← Back to Challenges

📚


Product Search

Stacked Queries SQL Injection Challenge 📚

Stacked queries (also called batched queries) allow an attacker to execute multiple SQL statements in a single request by separating them with semicolons. This is one of the most dangerous types of SQL injection because it allows attackers to perform multiple operations, including:

Important: Not all database systems and APIs support stacked queries. SQLite with sql.js supports them, and when vulnerable code uses string concatenation and allows semicolons, stacked queries become possible.

WARNING: In many countries (including UK) it is illegal to use this attack.

Up to 6 months in jail for unauthorised access

I've set up a vulnerable test system here so that you can have a go.

I promise not to prosecute.

The challenge on this page is to understand how stacked queries work. Try the examples below in the search box to see how multiple queries can be executed in a single request.

Try These Stacked Query Attacks:

How Stacked Queries Work

Stacked queries work by separating multiple SQL statements with semicolons:

Example: If the original query is:

SELECT * FROM products WHERE name = '$input'

And you inject: mouse'; SELECT * FROM users --

The database executes:

SELECT * FROM products WHERE name = 'mouse';
SELECT * FROM users -- '

Both queries are executed, and you can see results from both.

Security Implications

Stacked queries are extremely dangerous because they allow:

Prevention: Always use parameterized queries (prepared statements) and never allow user input to be directly concatenated into SQL queries. Most prepared statement implementations prevent stacked queries by design.