SQL injection with INSERT statement
A blog platform's tag creation feature was vulnerable to SQL injection because user input was inserted directly into an INSERT statement. An attacker could use time-based techniques to confirm the injection and then extract the entire database schema by inserting multiple rows with subqueries.
SQL injection vulnerabilities are often found in the INSERT statement when performing add operations, such as creating a new user or blog post. In this document, we examine a real-world case in which a user attempts to add a new tag to their blog post.
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 concatenated user-supplied tag names directly into an SQL INSERT statement without parameterisation or escaping.
Impact
An attacker could extract the entire database schema, and potentially other data, through the vulnerable tag creation feature.
What the attacker needed
A user account on the blog platform; ability to create tags
How it was found
- Insert a single quote in the tag name and observe a 500 error.
- Test a time-based payload and observe a 5-second delay.
- Determine the number of columns after the tag name by trying null values.
- Determine the number of columns before the tag name by trying multi-row inserts.
- Use the user ID to make inserted tags visible in the UI.
- Extract database schema information in 100-character chunks using subqueries.
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 command without proper handling, letting an attacker change the command's meaning. Here, the tag name field was placed directly into an INSERT statement, so a crafted tag name could make the database wait or return hidden data. The attacker used this to read the database structure, though they had to work around a 100-character limit by splitting the data into chunks.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.