From Errors to Exploits: A Manual Dive into SQL Injection (Part 2
The TrackingId cookie parameter was vulnerable to error-based SQL injection, allowing an attacker to extract database version and user credentials via error messages. The attacker could then log in as the administrator using the leaked password.
Published on medium.com
After accessing the lab, we inspect the request sent to the server. We observe that the TrackingId parameter in the cookie is reflected in the response.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the application concatenated the TrackingId cookie value directly into an SQL query without parameterisation or sanitisation.
Impact
An attacker could extract sensitive data such as database version and user credentials, and then log in as the administrator.
What the attacker needed
Access to the lab environment; ability to set a cookie value
How it was found
- Send a single quote in the TrackingId cookie and observe a database error.
- Use the || operator to test string concatenation and identify PostgreSQL.
- Inject a CAST expression to trigger a type conversion error.
- Replace the test string with version() to leak the database version.
- Use string_agg and LIMIT to extract usernames and passwords via error messages.
- Log in with the extracted administrator credentials.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The website put a cookie value directly into a database query without cleaning it. By sending special characters, the attacker made the database show its error messages, which included secret information like the admin password. This is called SQL injection, and the error-based variant uses those error messages to steal data.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.