Skip to content
SQL injection Write-up Advanced

Exploiting tricky blind SQLI

A blind SQL injection in the LIMIT clause of a PostgreSQL query allowed an attacker to extract data by counting the number of albums returned on a page, where the count corresponded to the ASCII value of a character from a subquery.

Rahul Maini Follow

Published on noob.ninja

July 21, 2019

Rahul Maini, on noob.ninja

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

The application inserted user input directly into the LIMIT clause of a SQL query without proper validation, and although quotes were escaped, the numeric context allowed injection through other means.

Impact

An attacker could extract arbitrary data from the database, such as the version, one character at a time, by observing the number of albums returned.

What the attacker needed

Access to the album pagination feature; ability to create albums; ability to run JavaScript in the browser

How it was found

  1. Create around 200 albums to ensure enough rows for the ASCII values.
  2. Inject a subquery using substr and ascii functions into the LIMIT clause to return a number of albums equal to the ASCII value of a character from the database version.
  3. Count the number of albums displayed on the page using JavaScript.
  4. Convert the count back to a character using String.fromCharCode to extract the database version character by character.

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 had a hidden database query that could be tricked into returning a number of albums equal to the ASCII code of a character from the database. By counting the albums shown, an attacker could read information from the database one character at a time.

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 Rahul Maini

View all

1 more disclosed report, 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.