SQLI through User Agent
The application was vulnerable to boolean-based SQL injection through the User-Agent header. An attacker could use this to extract database version, table names, column names, and ultimately user passwords.
Hi everyone, in this simple tutorial I will describe how I was able to exploit a SQL injection, using the user-agent as vector. First of all, I will leave “blur” in the sensitive parts as it was requested from the customer of the private program.
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 User-Agent header directly into a SQL query without parameterisation or sanitisation.
Impact
An attacker could extract sensitive data from the database, including user passwords, as demonstrated by retrieving a password for a specific user id.
What the attacker needed
Authenticated user; ability to set User-Agent header
How it was found
- Authenticate to the application and observe a request.
- Insert a single quote in the User-Agent header and note the change from 200 OK to 401.
- Test boolean conditions: a true condition returns 200 OK, a false condition returns 401.
- Use substring on @@version to identify the database as MySQL/MariaDB and extract the version.
- Use a subselect with a wordlist to find the table name app_user.
- Use similar boolean tests to find column names and extract a password for a given user id.
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.
SQL injection is when user input is inserted into a database query without proper handling, letting an attacker change the query's meaning. Here, the User-Agent header (a string your browser sends to identify itself) was used to sneak in extra SQL. By sending true/false conditions, the attacker could ask the database yes/no questions and slowly extract 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.