Practical Exploitation of Error Based Sql Injection
A search parameter was concatenated into SQL without filtering, and the site displayed full database error pages. By forcing a duplicate-key error that embedded query output in the message, an attacker could read table names and user credentials even though the query returned no rows to the page.
Published on eslam.io
Hi everybody I don’t post much write-ups online because most of the work done privately and under NDA.
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 search term was concatenated directly into SQL statements without parameterisation, and verbose database errors were shown to users in production.
Impact
An attacker could extract database schema information and user credentials from error messages, though this depended on database errors being displayed.
What the attacker needed
Search page reachable; database errors shown to users
The fix
Database errors should be turned off in production and the query should be parameterised rather than built from user input.
How it was found
- Open the search page and send a single quote in the term parameter.
- Observe the database error page revealing the generated query.
- Send a crafted term that makes a grouped subquery produce a duplicate key error containing concatenated data.
- Read the leaked value from the duplicate entry message.
- Repeat with subqueries against the schema tables to list table names.
- Repeat against the users table to read usernames and passwords.
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 built a database query by pasting in whatever the visitor typed, so a visitor could add their own database instructions. The site also showed detailed database error messages, and the attacker made the database complain in a way that included secret data in the complaint text, which then appeared on screen.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.