Skip to content
SQL injection Write-up Beginner

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.

_Y000_ Follow

Published on infosecwriteups.com

On this occasion I would like to relate step by step another of the injections that I liked the most.

_Y000_, on infosecwriteups.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

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

  1. Add a single quote to the parameter to trigger an SQL error and confirm injection.
  2. Use ORDER BY with increasing numbers to determine the number of columns (47).
  3. Use UNION SELECT with 47 columns to find which columns are reflected (column 25).
  4. Inject @@version to retrieve the database version.
  5. Inject a subquery to retrieve the database name.
  6. 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.

More by _Y000_

View all

3 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.