[Burp Suite] SQL injection 2

Lab: SQL injection UNION attack, retrieving multiple values in a single column

This lab contains a SQL injection vulnerability in the product category filter. The results from the query are returned in the application’s response so you can use a UNION attack to retrieve data from other tables.

The database contains a different table called users, with columns called username and password.

To solve the lab, perform a SQL injection UNION attack that retrieves all usernames and passwords, and use the information to log in as the administrator user.


alt text Very similar to the previous Lab, this is what the landing page of the lab looks like.


alt text We know there’s a SQL injection vulnerability in the product category filter. Before we select a category, I clicked on intercept on button on Burp Suite, then selected the Pets category.


alt text Send this request we intercepted to Burp Suite Repeater because we would need to send requests and receive response multiple times to figure out the vulnerability and exploit it.


alt text ' UNION SELECT NULL, NULL, NULL, NULL from users--. Starting with 4 NULLs as the placeholders to test whether the original query has 4 columns from the users table. However, before we run it for a test, we need to apply URL encoding on this query.


alt text URL encoding applied


alt text 4 NULLs, and 3 NULLs returned 500 Internal Server Error status code.


alt text When the number of NULL placeholders got cut down to 2, it finally returned status code 200


alt text replaced the first NULL placeholder with a string value 'A', didn’t work out. This indicates that the first column expects a different data type value, not a String data type.


alt text replaced the second NULL with the same string data type value, and it worked. As you can see, we got the status code 200 as our response.


alt text Then, our SQL query became the following:

' UNION SELECT NULL, username||password from users--

We need both username and password values and we know the first column isn’t much useful because it doesn’t expect a string data type. Therefore, we concatenated the username column and password column, combining tow values into a single output column.

If you see what’s returned on the right, it’s hard to distinguish between the username and password because they’re concatenated without any separator.


alt text Therefore, I added --- as a separator between the username and password. The final query is as follows:

' UNION SELECT NULL, username||'---'||password from users--

Of course, you would need to apply URL encoding on the query if you need to pass this query in a URL as I did.


alt text Type in the credentials I just obtained from the query.


alt text BAM!


#Burp Suite