Skip to content

Commit 81b3f85

Browse files
authored
Merge pull request #776 from m14r41/patch-1
enhancement: clarified and expanded details on Second-Order SQL Injec…
2 parents 5e0b097 + 6cb0048 commit 81b3f85

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

SQL Injection/README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,28 @@ In short, the result of the first SQL query is used to build the second SQL quer
358358
## Second Order SQL Injection
359359

360360
Second Order SQL Injection is a subtype of SQL injection where the malicious SQL payload is primarily stored in the application's database and later executed by a different functionality of the same application.
361-
362-
```py
363-
username="anything' UNION SELECT Username, Password FROM Users;--"
364-
password="P@ssw0rd"
365-
```
366-
367-
Since you are inserting your payload in the database for a later use, any other type of injections can be used UNION, ERROR, BLIND, STACKED, etc.
361+
Unlike first-order SQLi, the injection doesn’t happen right away. It is **triggered in a separate step**, often in a different part of the application.
362+
363+
1. User submits input that is stored (e.g., during registration or profile update).
364+
365+
```text
366+
Username: attacker'--
367+
Email: attacker@example.com
368+
```
369+
370+
2. That input is saved **without validation** but doesn't trigger a SQL injection.
371+
372+
```sql
373+
INSERT INTO users (username, email) VALUES ('attacker\'--', '[email protected]');
374+
```
375+
376+
3. Later, the application retrieves and uses the stored data in a SQL query.
377+
378+
```python
379+
query = "SELECT * FROM logs WHERE username = '" + user_from_db + "'"
380+
```
381+
382+
4. If this query is built unsafely, the injection is triggered.
368383

369384
## PDO Prepared Statements
370385

@@ -438,6 +453,7 @@ PDO allows for binding of input parameters, which ensures that user data is prop
438453
```
439454

440455
## Generic WAF Bypass
456+
---
441457

442458
### No Space Allowed
443459

0 commit comments

Comments
 (0)