Skip to content
SQL injection Write-up Intermediate

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.

fr0stNuLL Follow

Published on medium.com

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.

fr0stNuLL, on medium.com

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

  1. Authenticate to the application and observe a request.
  2. Insert a single quote in the User-Agent header and note the change from 200 OK to 401.
  3. Test boolean conditions: a true condition returns 200 OK, a false condition returns 401.
  4. Use substring on @@version to identify the database as MySQL/MariaDB and extract the version.
  5. Use a subselect with a wordlist to find the table name app_user.
  6. 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.

More by fr0stNuLL

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.