Skip to content
SQL injection Write-up Intermediate

Visible Error-Based SQL Injection: Leaking Data Through PostgreSQ

The TrackingId cookie was embedded directly into a backend SQL query, and database error messages were reflected in the HTTP response. An attacker could use type-conversion errors to leak data such as the administrator username and password from the users table.

Mohamed Ahmed Follow

Published on medium.com

This lab demonstrates an in-band SQL injection vulnerability where the application reflects database error messages directly in the HTTP response. Unlike typical URL-based injection points, the vulnerable input here is located inside the TrackingId cookie, which is processed by the backend for analytics purposes.

Mohamed Ahmed, 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 TrackingId cookie value was concatenated into a SQL query without parameterisation, and raw database errors were returned to the client.

Impact

An attacker could extract the administrator username and password and log in as administrator, fully compromising the application.

What the attacker needed

Access to the login page; ability to modify the TrackingId cookie

The fix

The cookie value should be passed to the database through parameterised queries, and raw database error messages should not be returned to users.

How it was found

  1. Capture a request to the login page in Burp and send it to Repeater.
  2. Append a single quote to the TrackingId cookie value and observe a database error in the response.
  3. Add SQL comment syntax after the quote and see the error disappear, confirming injection.
  4. Inject a subquery wrapped in a cast to integer and observe a boolean type error.
  5. Adjust the condition so it evaluates as a boolean and the query runs cleanly.
  6. Replace the constant with a subquery selecting the username from the users table to leak it via the error.

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.

A cookie the site uses for analytics was pasted straight into a database query without being cleaned. By adding extra SQL and deliberately causing a type error, the attacker made the database print its own data inside the error message shown on the page. That let them read the administrator's password and log in.

What is SQL injection?

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

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.