Fun SQL Injection 2 — MSSQL
A parameter used to display a PDF was vulnerable to SQL injection, allowing an attacker to execute arbitrary SQL queries. The attacker could extract database version, database name, server name, table names, and column names.
On this occasion I would like to relate step by step another of the injections that I liked the most.
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
Impact
An attacker could extract sensitive information from the database, including version, database name, server name, table names, and column names.
What the attacker needed
Access to the vulnerable parameter
How it was found
- Add a single quote to the parameter to trigger an SQL error and confirm injection.
- Use ORDER BY with increasing numbers to determine the number of columns (47).
- Use UNION SELECT with 47 columns to find which columns are reflected (column 25).
- Inject @@version to retrieve the database version.
- Inject a subquery to retrieve the database name.
- Inject subqueries to list table names and column names.
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 parameter that selects a PDF was not sanitised, so adding a quote caused an error and revealed the database type. The attacker then used UNION SELECT to pull data from the database.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.