Before exploiting, you need to confirm an input actually reaches a SQL query. Three indicator families cover almost every real app:
Error-Based Detection
The fastest signal. If you can make the database throw an error by malforming the query, you have injection.
- Submit a single quote
'and watch for SQL error messages (e.g. “You have an error in your SQL syntax”, “Unclosed quotation mark”) - Try
",),'),")— different injection contexts need different terminators - Even a partial error (stack trace, 500 Internal Server Error with a DB-looking string) counts
The error itself often reveals the DBMS — “MySQL” in the error message saves you a fingerprinting round.
Boolean-Based Detection
When the app swallows errors but the page content changes based on query results:
' AND 1=1-- - → normal page
' AND 1=2-- - → different page / empty result
If the two differ, your input reaches a WHERE clause. The difference might be a results list disappearing, a specific element changing, or the page being completely blank.
Time-Based Detection
The last resort when there’s no visible difference between true and false responses. You force the DB to sleep:
' OR SLEEP(5)-- -
'; WAITFOR DELAY '0:0:5'-- - (MSSQL)
'; SELECT pg_sleep(5)-- - (PostgreSQL)If the response takes ~5 seconds longer than normal, you have blind time-based injection. Slow but works against everything.
Where to Test
Every input that could reach a query. Don’t stop at the obvious GET/POST parameters:
- URL query strings
- Form fields (search boxes, login forms, feedback)
- Cookies (session IDs, preferences)
- HTTP headers (
User-Agent,Referer,X-Forwarded-For) - JSON/XML bodies in API calls
- File uploads (filenames end up in DB queries sometimes)
Order of Attacks
Try payloads in this order — cheapest first:
- Single quote — fastest, errors are loudest
- Numeric OR true —
1 OR 1=1(no quotes needed for numeric contexts) - Boolean comparison —
' AND 1=1-- -vs' AND 1=2-- - - Time delay —
' OR SLEEP(3)-- -as a last resort
Injection Context
Once you confirm injection, identify the exact context — this tells you what to escape:
| Original Query | Payload |
|---|---|
WHERE id = $input | 1 OR 1=1-- - |
WHERE name = '$input' | admin' OR '1'='1 |
WHERE name = "$input" | admin" OR "1"="1 |
WHERE id IN ($input) | 1) OR (1=1-- - |
WHERE name LIKE '%$input%' | %' OR '1'='1 |
Mismatching contexts is the most common reason “it should work but doesn’t” happens. When a payload fails, try it with and without the quote.
