0xBOverchunked: SQL Injection
Platform: Hack The Box
Category/Tags: Web, SQL Injection
Difficulty: Easy
Introduction
Are you able to retrieve the 6th character from the database?
Information Gathering
A simple web application that search a certain id that returns some information of a character.

I download the zip file containing the source code of this web application.
I inspect the SearchHandler.php, this is the entrypoint of the request. If the request is being sent by chunks it will respond to “No post id found.” or Internal Server Error (500). Otherwise, if the id is found, it will return the character’s information. If the server detected a malicious characters that relates to SQL, it may respond it that there’s an attempt of SQL Injection.
This is the waf.php, a.k.a. Web Application Firewall wherein there is a list of blacklisted characters and syntax that is related when we run an SQL query.
If the value of search parameter is not an attempt of an SQL Injection, it will now query the database base on the id. If id is equal to 6, then it will return that we cannot view this information. So, we assume that the flag is in the id of 6.
So, we saw that the flag is in the id of 6. We will need to see the information of that id to gain the flag that is in the gamedesc column,
Vulnerability
This query if they do not use some libraries, frameworks or ORMs it may be vulnerable to SQL Injection.
Exploitation
So after trying some bypass in the search parameter, I already decide to use sqlmap; to dump the posts table to get the value of gamedesc column. I intercept the request using burpsuite, and paste it in as text file.

I tried all the flags in sqlmap, and changing options can change the response (sometimes I got “unable to connect to the target URL”). After trying some options, I get the gamedesc value using this command,
I use the most aggressive level to perform extent techniques, highest risk to reduce the false positives, I specify that the database is sqlite, I also need to dump the posts table, I want the data stream divided into chunks, I also use the random-agent flag to always change the user-agent, I also want to create a new session and I want to use the BEUS (Boolean-based blind SQL injection, Error-based SQL injection, Union-based SQL injection, Stacked queries SQL injection) technique. This will take some time because it guesses the letter 1 by 1 and gets the whole value of column by each rows, So I wait until the posts table dumped perfectly.
Gotcha! we got the dumped table and the flag is in the gamedesc column of id 6. You can also visit the dumped logs and csv through ~/.local/share/sqlmap/output/<MACHINE_IP>.

Last updated