What is SQLMap?
SQLMap is an open-source penetration testing tool that automates the process of detecting and exploiting SQL injection vulnerabilities in web applications. It supports a wide range of database management systems including MySQL, PostgreSQL, Oracle, Microsoft SQL Server, SQLite, and many others.
Key Capabilities
- Automatic SQL Injection Detection: Identifies vulnerable parameters in URLs, forms, cookies, and HTTP headers
- Database Fingerprinting: Determines the exact DBMS type and version
- Data Extraction: Retrieves database names, tables, columns, and data
- Advanced Exploitation: File system access, OS command execution (in specific scenarios)
- Bypass Techniques: WAF/IPS evasion using tamper scripts and encoding
- Multiple Injection Techniques: Supports UNION, Boolean-based blind, time-based blind, error-based, and stacked queries
Why Learn SQLMap?
Understanding SQLMap is crucial for both offensive and defensive security:
- Security Testing: Identify SQL injection vulnerabilities in your applications before attackers do
- Vulnerability Assessment: Comprehensive testing of web application attack surfaces
- Defense Understanding: Learn how attackers exploit SQL injection to better defend against it
- Compliance: Meet security testing requirements for standards like PCI-DSS, OWASP Top 10
SQL Injection Types
1. UNION-Based SQL Injection
The most straightforward type. Uses the UNION SQL operator to combine the results of the original query with injected queries, allowing direct data extraction.
2. Boolean-Based Blind SQL Injection
Used when the application doesn't return error messages or data, but behaves differently based on TRUE or FALSE conditions. Data is extracted one bit at a time.
3. Time-Based Blind SQL Injection
When even boolean responses aren't visible, time delays are used. The application pauses execution based on injected conditions.
4. Error-Based SQL Injection
Leverages database error messages to extract information. Some DBMS functions return data within error messages.
5. Stacked Queries
Allows execution of multiple SQL statements separated by semicolons. Enables advanced exploitation like INSERT, UPDATE, or stored procedure calls.
SQLMap Detection Techniques
Parameter Discovery
SQLMap can test multiple parameter types:
- GET Parameters: URL query strings like
?id=1&cat=books - POST Data: Form submissions and request body data
- HTTP Headers: Cookie, User-Agent, Referer, X-Forwarded-For
- URI Path: RESTful parameters in the URL path
Fingerprinting Process
SQLMap identifies the database system through:
- Banner Grabbing: Extract version information using functions like
@@version,version() - Syntax Differences: Test DBMS-specific syntax (e.g., MySQL uses
#for comments, MSSQL uses--) - Function Behavior: Test database-specific functions like
SUBSTRINGvsSUBSTR - Error Messages: Analyze error message patterns unique to each DBMS
- Response Timing: Different databases have different execution speeds and behaviors
Injection Point Testing
Database Fingerprinting
Version Detection
Each DBMS has specific functions to reveal version information:
Database Enumeration
SQLMap uses system tables to enumerate database structure:
Data Extraction
Defense Against SQL Injection
Primary Defenses
-
Prepared Statements (Parameterized Queries)
# VULNERABLE CODE (Python example) cursor.execute("SELECT * FROM users WHERE id = '" + user_id + "'") # SECURE CODE cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,))
-
Input Validation and Sanitization
- Whitelist allowed characters
- Validate data types (ensure numbers are numeric)
- Limit input length
- Escape special characters
-
Least Privilege Principle
- Database user should only have necessary permissions
- Never use 'root' or 'sa' for web application database connections
- Disable dangerous functions (xp_cmdshell, LOAD_FILE, etc.)
-
Web Application Firewalls (WAF)
- Filter common SQL injection patterns
- Rate limiting to slow down automated attacks
- Not a replacement for secure coding, but adds defense in depth
Detection and Monitoring
- Log all database errors and unusual query patterns
- Monitor for suspicious characters in inputs (', --, /*, UNION, etc.)
- Alert on multiple failed queries from same source
- Implement intrusion detection systems (IDS)
Responsible Disclosure
If you discover SQL injection vulnerabilities during authorized testing:
- Document thoroughly: Steps to reproduce, affected parameters, potential impact
- Report responsibly: Contact the organization's security team, not social media
- Give time to patch: Typically 90 days before public disclosure
- Don't exfiltrate data: Proving the vulnerability exists is enough; don't steal data
- Follow bug bounty rules: If participating in a program, adhere to their guidelines
SQLMap Command Simulator
Challenge 1: Basic Detection
10 pointsUse SQLMap to detect if the target URL is vulnerable to SQL injection. What flag should you use to enumerate all available databases?
Challenge 2: Database Enumeration
15 pointsAfter discovering databases named 'shop_db', 'mysql', and 'information_schema', you need to enumerate tables in 'shop_db'. What flag specifies the target database?
Challenge 3: Table Discovery
15 pointsYou're targeting the 'shop_db' database. What flag will enumerate all tables in this database?
Challenge 4: Column Extraction
20 pointsYou've found a 'users' table in 'shop_db'. What flag combination will show you all columns in this table? (format: -D database -T table --flag)
Challenge 5: Data Dumping
20 pointsExtract all data from the 'users' table. What flag dumps the data? (Provide just the dump flag)
Challenge 6: DBMS Fingerprinting
15 pointsWhat flag forces SQLMap to perform extensive DBMS version fingerprinting?
Challenge 7: POST Request Testing
25 pointsThe login form uses POST method with parameters 'username' and 'password'. What flag specifies POST data for testing?
Challenge 8: Cookie Testing
25 pointsYou suspect the 'session_id' cookie might be vulnerable. What flag tests cookie parameters?
Challenge 9: Risk and Level
30 pointsYou want SQLMap to perform more thorough testing with higher risk payloads. What flags set both risk and level to maximum (3 and 5 respectively)?
Challenge 10: Batch Mode
20 pointsYou're running SQLMap in an automated script and need it to never prompt for user input, always using default options. What flag enables this?
Common SQLMap Options
Target Options
| Option | Description | Example |
|---|---|---|
| -u URL | Target URL | -u "http://site.com/page.php?id=1" |
| -g GOOGLEDORK | Use Google dork results as target | -g "inurl:.php?id=" |
| -r REQUESTFILE | Load HTTP request from file | -r request.txt |
| --data=DATA | POST data string | --data="user=admin&pass=test" |
| --cookie=COOKIE | HTTP Cookie header value | --cookie="PHPSESSID=abc123" |
| --headers=HEADERS | Extra HTTP headers (newline separated) | --headers="X-Forwarded-For: 127.0.0.1" |
Enumeration Options
| Option | Description | Example |
|---|---|---|
| --dbs | Enumerate databases | --dbs |
| -D DB | Specify database to enumerate | -D shop_db |
| --tables | Enumerate tables | -D shop_db --tables |
| -T TABLE | Specify table to enumerate | -T users |
| --columns | Enumerate columns | -D shop_db -T users --columns |
| --dump | Dump table data | -D shop_db -T users --dump |
| --dump-all | Dump all databases tables entries | --dump-all |
| -C COLUMNS | Specify columns to dump | -C username,password |
| --schema | Enumerate database schema | --schema |
| --count | Get number of entries in table | -D shop_db -T users --count |
Detection and Techniques
| Option | Description | Example |
|---|---|---|
| --level=LEVEL | Level of tests (1-5, default 1) | --level=5 |
| --risk=RISK | Risk of tests (1-3, default 1) | --risk=3 |
| --technique=TECH | SQL injection techniques (BEUSTQ) | --technique=BEU |
| --dbms=DBMS | Force DBMS type | --dbms=MySQL |
| --os=OS | Force OS type | --os=Linux |
| --fingerprint | Extensive DBMS fingerprinting | --fingerprint |
Optimization
| Option | Description | Example |
|---|---|---|
| --threads=THREADS | Max concurrent HTTP requests | --threads=5 |
| --batch | Never ask for user input (automatic) | --batch |
| --keep-alive | Use persistent HTTP connections | --keep-alive |
| --null-connection | Retrieve page length without content | --null-connection |
Evasion Techniques
| Option | Description | Example |
|---|---|---|
| --tamper=TAMPER | Use tamper scripts | --tamper=space2comment |
| --random-agent | Use random User-Agent | --random-agent |
| --delay=DELAY | Delay between requests (seconds) | --delay=2 |
| --timeout=TIMEOUT | Connection timeout (seconds) | --timeout=30 |
| --proxy=PROXY | Use proxy | --proxy="http://127.0.0.1:8080" |
| --tor | Use Tor anonymity network | --tor |
Injection Technique Codes
Use with --technique flag to specify which techniques to use:
| Code | Technique | Speed | Stealth |
|---|---|---|---|
| B | Boolean-based blind | Slow | Medium |
| E | Error-based | Fast | Low |
| U | UNION query-based | Very Fast | Low |
| S | Stacked queries | Fast | Very Low |
| T | Time-based blind | Very Slow | High |
| Q | Inline queries | Medium | Medium |
Popular Tamper Scripts
Tamper scripts modify payloads to bypass WAF/IPS filters:
| Tamper Script | Purpose | Example Transformation |
|---|---|---|
| space2comment | Replace spaces with comments | SELECT * FROM → SELECT/**/FROM |
| between | Replace > with BETWEEN | id > 1 → id BETWEEN 1 AND 9999 |
| charencode | URL-encode characters | SELECT → %53%45%4C%45%43%54 |
| randomcase | Random uppercase/lowercase | SELECT → SeLeCt |
| base64encode | Base64 encode payload | 1' OR '1'='1 → MScgT1IgJzEnPScx |
| apostrophenullencode | Replace apostrophe with %00%27 | ' → %00%27 |
| equaltolike | Replace = with LIKE | WHERE id = 1 → WHERE id LIKE 1 |
Common Command Patterns
Basic Vulnerability Testing
Full Database Enumeration
Advanced Testing
Progress Management
Export Progress
Download your challenge progress and statistics as JSON
Import Progress
Restore previously exported progress data
Reset Progress
Clear all challenge completions and reset points to zero
Appearance
Dark Mode
Toggle between dark and light theme
About
An educational platform for learning SQL injection detection and exploitation techniques using SQLMap. This simulator provides a safe, controlled environment to practice SQLMap commands without conducting actual attacks.
Educational Use Only: This tool is designed for cybersecurity education and authorized penetration testing training. Never use SQL injection techniques on systems you don't own or have explicit permission to test.
Unauthorized access to computer systems is illegal. This training module simulates SQLMap functionality for educational purposes only. Users are responsible for ensuring their activities comply with all applicable laws and regulations.