SQL injection in an UPDATE query - a bug bounty story!
The full name field in a user profile update was vulnerable to SQL injection because single quotes were not escaped. An attacker could inject SQL commands to extract the database version and then use a script to dump user emails and passwords.
Published on mahmoudsec.blogspot.com
February 17, 2017
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 application failed to escape single quotes in the full name field before inserting it into an SQL UPDATE query.
Impact
An attacker could extract the database version and then dump user emails and passwords, potentially leading to account takeover.
What the attacker needed
A user account; ability to edit full name
The fix
The vulnerability was fixed according to the timeline.
How it was found
- Submit a single quote in the full name field and observe a 500 error with a SQL error message.
- Submit two single quotes and see the error disappear and the name change to a single quote, confirming the injection point.
- Inject a payload to retrieve the database version, which returns a number.
- Use ASCII and substring functions to extract data character by character.
- Write a Python script to automate the extraction of database schema and user credentials.
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.
When you type your name into a website, the site often saves it in a database. If the site doesn't clean up special characters like a single quote, an attacker can sneak in extra database commands. Here, the attacker could make the database reveal its version and then steal user emails and passwords.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.