SQLMap is the tool every web pentester, bug-bounty hunter, and red-teamer reaches for the moment a parameter looks injectable. It is a Python-based, open-source engine that automates the whole SQL injection kill chain: detecting the vulnerability, fingerprinting the database, extracting data, and — where the target allows it — pivoting to file access and command execution. It speaks the dialects of MySQL, PostgreSQL, Microsoft SQL Server, Oracle, SQLite and dozens more.
This guide takes you from a clean machine to a working OS shell through a legal practice target. You will install SQLMap four ways (Kali package, source, pip/pipx, Docker), run and read your first scan, enumerate databases end to end, tune the --level/--risk/--technique triad, defeat a WAF with tamper scripts, and finish on the other side of the table with KQL and SPL to detect SQLMap in your own logs.
Authorization is not optional. Run SQLMap only against systems you own or have explicit written permission to test. Everything below assumes a lab you control or a scoped engagement.
◈ Table of Contents
01 — What SQLMap Does
TOOL CONTEXTA SQL injection happens when user-controlled input is concatenated into a database query instead of being passed as a bound parameter. SQLMap probes a target parameter with crafted payloads, watches how the response changes, and from those differences infers whether — and how — it can talk to the backend database. Once it confirms an injection point, it can read the database structure and contents character by character, entirely through the vulnerable web request. It supports five core injection classes and will pick whichever the target permits.
| Technique | Flag letter | How it works | When SQLMap uses it |
|---|---|---|---|
| Boolean-based blind | B | Injects TRUE/FALSE conditions and reads content differences in the page | No error or data echoed, but page changes on true vs false |
| Error-based | E | Forces the DBMS to leak data inside an error message | Verbose database errors are returned to the client |
| UNION query | U | Appends a UNION SELECT to pull data into the visible response | Query results are rendered on the page |
| Stacked queries | S | Chains a second statement with ; — enables writes, os-shell | Driver allows multiple statements (e.g. MSSQL, PostgreSQL) |
| Time-based blind | T | Uses SLEEP/WAITFOR delays; reads data from response timing | Fully blind — no visible content or error difference |
Why a defender should care about a "red team" tool: SQLMap is exactly what is hitting your applications right now. Understanding its request patterns, its default User-Agent, and the payload shapes it generates is the fastest way to write detections that actually fire. That is why this tutorial closes with hunt queries, not just attack commands.
Pentest & Bug Bounty
Confirm and exploit an injection point in seconds, then prove impact by extracting a benign proof row for the report — without hand-writing payloads for each DBMS.
Regression Testing
Re-run a saved SQLMap session against a fixed endpoint in CI to verify a patched parameter is no longer injectable before release.
Detection Tuning
Generate real attack traffic in a lab to validate that your WAF rules, SIEM analytics, and app logs actually catch injection attempts.
Training
Teach analysts what a live SQLi looks like on the wire — payloads, timing, and the tell-tale error strings the DBMS returns.
SQLMap is loud and destructive by default temperament. The --dump, --os-shell and --file-write features can alter data and drop files on a target. Never point it at production or third-party systems without written authorization and an agreed scope.
02 — Prerequisites & Lab Setup
BEFORE YOU STARTSQLMap itself is light — it is a set of Python scripts with no compiled dependencies. The only hard requirement is a working Python 3 interpreter. What you also need is a legal target. Do not learn on the open internet. Stand up a deliberately vulnerable app instead — this guide uses DVWA (Damn Vulnerable Web Application), which ships a textbook SQLi parameter.
| Requirement | Minimum | Recommended | Notes |
|---|---|---|---|
| Python | 3.8 min | 3.11+ rec | Modern SQLMap runs on Python 3; legacy 2.6/2.7 support is deprecated |
| OS | Any Linux / macOS / Windows | Kali Linux 2026 | Kali ships SQLMap pre-installed and patched |
| RAM | 1 GB | 2 GB+ | Threaded dumps of large tables use more memory |
| Network | Reachability to target | Isolated lab VLAN | Keep attacker and target on a NAT/host-only lab network |
| Practice target | DVWA / bWAPP / SQLi-labs | DVWA via Docker | OWASP Juice Shop and PortSwigger labs also work |
| Optional | Burp Suite / OWASP ZAP | Burp Community | Capture authenticated requests to feed SQLMap with -r |
The fastest safe target is DVWA in a container. It exposes a classic ?id= injection on the SQL Injection page. Run it on an isolated host and never expose port 8080 to the internet.
Log in, click Create / Reset Database, then open DVWA Security and set the level to Low for your first run. You will raise it to Medium and High later to practise tamper scripts.
DVWA is intentionally broken. Bind it to localhost or a host-only network. An exposed DVWA instance is a real, exploitable foothold into your machine.
DVWA requires a session cookie plus a security cookie. SQLMap needs both to reach the vulnerable page. Copy them from your browser's developer tools (Application → Cookies) or from a Burp-captured request.
Instead of copying cookies by hand, capture the whole request in Burp (right-click → Copy to file) and hand the file to SQLMap with -r request.txt. It carries every header, cookie and POST body automatically.
03 — Method 1: Kali / Debian Package
STEP-BY-STEPKali Linux ships SQLMap in the default kali-linux-default metapackage. Before installing anything, check whether it is already present and what version you have.
On Debian, Ubuntu, Parrot or a minimal Kali build, install from the distribution repositories. Update the package index first so you get the current packaged release.
Distro packages can lag months behind upstream. Newer DBMS fingerprints, tamper scripts and bug fixes land in the Git repo first. For active engagements, prefer Method 2 (source) so you are never testing with a stale engine.
Confirm the binary runs, Python resolves, and the help text renders. The --dependencies flag reports optional libraries for advanced features (e.g. connecting directly to a DBMS, or Metasploit integration).
sqlmap --versionprints a version and exits cleanlysqlmap -hhlists Target, Request, Injection, Techniques sections- No "python: command not found" or import errors appear
04 — Method 2: Git From Source (All OS)
STEP-BY-STEPThis is the maintainers' recommended method and always gives you the newest engine. A shallow clone keeps the download small. Works identically on Linux, macOS and Windows (WSL or native).
The Git version is the same code the developers run. Keep it updated in one step: cd sqlmap-dev && git pull. No reinstall, no package manager.
From a source clone you invoke python3 sqlmap.py rather than a global sqlmap command. Add a shell alias so the rest of this guide's commands work verbatim.
SQLMap has a built-in updater that pulls the latest commit when run from a Git checkout. Either flag works; both fast-forward your clone.
--update only works on a Git clone. If you installed via apt or pip, the flag will refuse to run. Update through the same channel you installed with.
05 — Method 3: pip / pipx & Docker
STEP-BY-STEPOn modern Linux, PEP 668 blocks a system-wide pip install. pipx installs SQLMap into its own virtual environment and drops a global sqlmap command onto your PATH — clean and reversible.
A container keeps the tool and its Python runtime off your host entirely — handy for CI runners or a shared jump box. There is no official image, so build a tiny one from the source repo.
This compose file stands up the whole range in one command: a DVWA target and the SQLMap image on a shared, isolated network. From the SQLMap container, the target is reachable as http://dvwa.
Binding the DVWA port to 127.0.0.1:8080 (not 0.0.0.0) means only your own machine can reach the deliberately vulnerable app. This one prefix is the difference between a lab and an incident.
06 — Your First Scan
HANDS-ON
Every SQLMap command is built the same way: point it at a target with -u, supply whatever the request needs (cookies, POST data, headers), then tell it what to do. The anatomy below is worth memorising — every other command in this guide is a variation on it.
TARGET → REQUEST CONTEXT → BEHAVIOUR FLAGS → ACTION
Start minimal: give SQLMap the URL and the cookies, and add --batch so it answers its own prompts with sensible defaults. It will test the id parameter and report which techniques land.
Once a parameter is confirmed, SQLMap caches the result in a session file so subsequent commands skip re-detection and jump straight to the data.
For POST forms, pass the body with --data and SQLMap flips to POST automatically. Use -p to test only one parameter when a request has many, which is faster and quieter.
The cleanest way to handle authenticated, header-heavy, or JSON endpoints is to save the raw HTTP request to a file and hand it over with -r. SQLMap parses every header, cookie and body field, and tests them all.
Add -v 3 to any command to print the exact payloads SQLMap sends. It is the best way to learn what a boolean, error, union or time payload actually looks like on the wire.
07 — Database Enumeration
EXTRACTIONWith an injection confirmed, enumeration walks down the hierarchy: server banner → databases → tables → columns → rows. Run these in order; each command reuses the cached session so nothing is re-detected. Every flag below is additive — combine them freely.
| Goal | Flag | What it returns |
|---|---|---|
| Fingerprint | --banner | DBMS name and exact version string |
| Current context | --current-user --current-db | DB user and active database |
| Privilege check | --is-dba | Whether the DB user is an administrator |
| List databases | --dbs | All databases the user can see |
| List tables | --tables -D dvwa | Tables inside a chosen database |
| List columns | --columns -T users -D dvwa | Column names + types of a table |
| Dump rows | --dump -T users -D dvwa | The actual data |
| Dump creds | --passwords | DB user password hashes (if privileged) |
Chain the low-noise identity checks first. Knowing the DBMS, the current user, and whether that user is a DBA shapes every decision that follows — a DBA opens up file and OS access; a low-priv user does not.
- banner:
5.7.x-log MySQL Community Server - current user:
dvwa@localhost - current database:
dvwa - current user is DBA:
False
Descend the hierarchy. Narrow with -D (database) and -T (table) so you only extract what matters instead of dumping the whole server.
Extract specific columns rather than whole tables. In a real engagement you dump the minimum needed to prove impact — a single row, or just the username and hash columns — not the entire customer table.
SQLMap recognises common hash formats during a dump and will offer to crack them against a built-in dictionary. Extracted data is written to CSV under the output directory, keyed by target host.
--dump-all pulls every database on the server, including system schemas, and can run for hours against a large target. Scope your dumps. Mass extraction of real data may exceed your engagement's rules of engagement.
For ad-hoc queries, drop into an interactive SQL shell that runs each statement through the injection point. And because SQLMap caches everything, you can pause and resume long jobs at will.
Long dump interrupted by a dropped connection? Just re-run the same command. SQLMap picks up exactly where it stopped thanks to the per-target session and results cache.
08 — Level, Risk & Technique Tuning
CONTROL
Defaults are deliberately conservative to stay fast and safe. When a parameter looks injectable but the default run finds nothing, you widen the search with --level and --risk, or force a specific --technique. Understanding this triad is what separates a novice from someone who finds the injection everyone else missed.
| Flag | Range (default) | Effect | Trade-off |
|---|---|---|---|
| --level | 1–5 (1) | How many injection points to test (adds cookies at 2, headers/User-Agent at 3+) | Higher = far more requests, slower, louder |
| --risk | 1–3 (1) | Which payloads are allowed (risk 3 adds OR-based and heavy time-based tests) | Risk 3 OR-payloads can update rows — dangerous on writes |
| --technique | BEUSTQ (all) | Restrict to specific injection classes | Narrowing speeds runs and avoids noisy tests |
| --threads | 1–10 (1) | Parallel requests during data retrieval | Faster dumps, but more load and easier to detect |
| --time-sec | seconds (5) | Delay threshold for time-based blind | Raise on laggy networks to cut false positives |
If a quick scan comes up empty, raise the level to test cookies and headers, and the risk to allow heavier payloads. This is the standard "second pass" when you suspect an injection the defaults skipped.
--risk 3 enables OR-based payloads such as OR 1=1. On an UPDATE or DELETE endpoint that can rewrite every row in a table. Never use risk 3 blindly against write-capable parameters.
When you already know the backend, tell SQLMap. Restricting the technique and naming the DBMS cuts the request count dramatically and avoids wasting time on tests that cannot succeed.
Threads accelerate data retrieval; delays and randomised agents slow you down to stay under rate-based detection. Pick a lane based on whether you are racing a lab clock or evading a SOC.
--random-agent swaps the default "sqlmap/1.x" User-Agent for a real browser string. Leaving the default UA in place is the single most common way blue teams catch a scan instantly — see phase 10.
09 — WAF Bypass, Shells & File Access
ADVANCEDThis is where a confirmed injection becomes real impact — and where a WAF sits between you and the database. SQLMap's tamper scripts mutate payloads to slip past filters, while its OS and file features (available only when privileges and the DBMS allow) turn data access into system access. Raise DVWA's security level to Medium or High to practise the tamper workflow.
SQLMap can detect a WAF/IPS with --identify-waf, then reshape payloads with one or more tamper scripts. List every script with --list-tampers; chain them left-to-right with commas.
| Tamper script | What it does |
|---|---|
| space2comment | Replaces spaces with /**/ C-style comments |
| between | Rewrites >/= using BETWEEN ... AND |
| randomcase | Randomises keyword casing (SeLeCt) to defeat static signatures |
| charencode | URL-encodes characters to slip weak input filters |
| modsecurityversioned | Wraps the query in MySQL versioned comments to bypass ModSecurity |
There is no universal tamper combo. Start with --identify-waf, then test small chains. space2comment plus randomcase defeats a surprising number of default signature sets; add DBMS-specific scripts only once you know the backend.
If the DB user has file privileges (e.g. MySQL FILE, or MSSQL/PostgreSQL equivalents), SQLMap can read arbitrary files and, where secure_file_priv allows, write to the web root — a classic path to a web shell.
File-write to a web-accessible directory is functionally remote code execution once the file is a script. Treat this capability as high-impact: get explicit written sign-off, use a harmless marker file to prove access, and clean up afterwards.
When stacked queries and privileges align, --os-shell deploys a stager through the injection and hands you an interactive command prompt on the database server. --os-cmd runs a single command non-interactively.
--os-shell writes helper stagers (and on some stacks a UDF) to disk to achieve execution. These artifacts persist unless removed. Document what was dropped and remove it as part of engagement cleanup.
Send SQLMap traffic through Burp to inspect and log every request, or through Tor to rotate source addresses. Proxying through Burp is invaluable for understanding exactly what the tool sends.
SQLMap can discover its own targets: crawl a site to a given depth, auto-submit forms, or (in a lab) seed from a search dork. Use these to broaden coverage across an in-scope application.
Save every finding as a repeatable job: append --output-dir=./engagement and archive that folder. The session, logs and dumped CSVs together are your evidence trail for the report.
10 — Detection, Troubleshooting & Maintenance
BLUE + OPS
A CyberHawk tutorial does not stop at the attack. Here is how to catch SQLMap in your own telemetry, and how to fix the errors that trip people up most. SQLMap is noisy: it sends hundreds to thousands of requests to one parameter, its default User-Agent literally contains the string sqlmap, and its payloads carry recognisable syntax. All three are detectable.
This query flags the default SQLMap User-Agent and classic injection markers in web request logs, plus a volumetric burst from a single client to a single URI. Adjust the table name to your web-log source.
The Splunk equivalents: one search on the User-Agent and payload signatures, one on request volume per source. Point them at your web-access sourcetype.
Time-based blind injection is stealthy on volume but obvious on latency: hundreds of requests to one URI that each take ~5s or ~10s (your --time-sec value) is a near-perfect signature. Alert on response-time clustering, not just request count.
Most "SQLMap isn't working" problems are request-context issues, not the tool. This table covers the ones that account for the majority of failed first scans.
| Symptom | Likely cause | Fix |
|---|---|---|
| "all tested parameters do not appear to be injectable" | Defaults too shallow, or wrong parameter | Add --level=5 --risk=3; confirm the right -p |
| 302 redirect to login | Session cookie expired or missing | Re-capture cookie; add --cookie or use -r request.txt |
| 403 / 406 on every payload | WAF blocking | --identify-waf then --tamper + --random-agent |
| "unable to connect to the target URL" | Host unreachable / wrong scheme | Check reachability; add --force-ssl or fix the URL |
| Time-based false positives | Laggy or jittery network | Raise --time-sec=10; reduce --threads |
| CSRF token rejects requests | Anti-CSRF token per request | --csrf-token=NAME --csrf-url=URL |
| Stale results after a fix | Cached session | --flush-session or --fresh-queries |
Keep the engine current, know where your loot lands, and wipe engagement data when the report is delivered. Output (sessions, logs, CSV dumps) is stored per target under the SQLMap output directory.
- Update the engine before every engagement (
--update/git pull) - Scope dumps — extract proof rows, not whole databases
- Record any files/stagers written by
--file-writeor--os-shelland remove them - Archive the output dir as evidence, then
--purgesensitive data at close-out
11 — Sources & References
DOCUMENTATIONPrimary documentation and reference material used in this guide. The official wiki and usage pages are the authoritative source for every flag and are updated with each release.
Test like an attacker, detect like a defender.
SQLMap will find the injection — but the parameter should never have been vulnerable in the first place. Run your applications through CyberHawk's IOC Scanner and Live Tools, and pair this guide with our SQL Injection: Advanced Techniques deep dive for the manual side of the craft. For structured response playbooks, see our SOP library.
◈ Stay Connected
Follow CyberHawk Threat Intel for threat intelligence, deployment guides and hands-on SOC tooling content.
"They can't exploit you if you are the Exploit."