GO KALI FREE

SQLMap

Web Application

Intermediatehigh risk

SQLMap is an open-source penetration testing tool that automates SQL injection detection and exploitation. It supports five SQL injection types (boolean-based blind, time-based blind, error-based, UNION query-based, and stacked queries) and over 30 database backends including MySQL, Oracle, PostgreSQL, Microsoft SQL Server, and many more.

Installation

sudo apt install sqlmap

Basic Syntax

sqlmap -u "<URL>" [options]

Quick Facts

Full Name
SQLMap
License
GNU GPL v2
Author
Bernardo Damele & Miroslav Stampar
Written In
Python
Platforms
Linux, Windows, macOS
Category
SQL Injection Framework
First Release
2006
Database Support
MySQL, PostgreSQL, Oracle, MSSQL, SQLite, + more

Tool Overview

SQLMap is a free, open-source penetration testing tool that automates the detection and exploitation of SQL injection vulnerabilities in web applications. It supports five distinct SQL injection types: boolean-based blind, time-based blind, error-based, UNION query-based, and stacked queries.

Created by Bernardo Damele Assuncao and Miroslav Stampar in 2006, SQLMap has become the industry-standard tool for SQL injection testing. It supports all major database backends including MySQL, Oracle, PostgreSQL, Microsoft SQL Server, SQLite, IBM DB2, Firebird, Sybase, SAP MaxDB, and Informix.

SQLMap goes beyond simple injection detection. It can enumerate databases, extract tables and columns, dump entire databases, escalate privileges to DBA, access the underlying operating system through database-specific features, and even upload files to the target server. Its intelligent detection engine automatically identifies injection points and selects the optimal exploitation technique.

Common Commands

sqlmap -u "http://example.com/?id=1"Basic SQL injection test on a single URL parameter
sqlmap -u "http://example.com/?id=1" --dbsEnumerate available databases after detection
sqlmap -u "http://example.com/?id=1" -D mydb --tablesList tables in a specific database
sqlmap -u "http://example.com/?id=1" -D mydb -T users --dumpDump all rows from a specific table
sqlmap -u "http://example.com/?id=1" --batchRun in non-interactive mode with default answers
sqlmap -u "http://example.com/?id=1" --level=5 --risk=3Maximum level and risk for thorough testing
sqlmap -u "http://example.com/?id=1" --technique=BEUUse only Boolean, Error, and UNION injection techniques
sqlmap -u "http://example.com/?id=1" --os-shellAttempt to get an operating system shell
sqlmap -u "http://example.com/?id=1" --file-read="/etc/passwd"Read a file from the database server filesystem
sqlmap -u "http://example.com/?id=1" --passwordsEnumerate database user password hashes
sqlmap -u "http://example.com/?id=1" --dump-allDump all accessible databases and tables
sqlmap -u "http://example.com/?id=1" --random-agentUse a random HTTP User-Agent header to avoid detection
sqlmap -r request.txtTest an HTTP request loaded from a saved file
sqlmap -u "http://example.com/?id=1" --proxy="http://127.0.0.1:8080"Route traffic through a proxy for monitoring
sqlmap -u "http://example.com/?id=1" --formsAuto-detect and test forms on a target page

Step-by-Step Guide

  1. 1Open a terminal in Kali Linux
  2. 2Identify the target URL with a vulnerable parameter
  3. 3Start with a basic test: sqlmap -u "http://target/?id=1"
  4. 4SQLMap will prompt to test the identified parameter
  5. 5After detection, enumerate databases with --dbs
  6. 6Select a database and enumerate tables with -D dbname --tables
  7. 7Dump table contents with -D dbname -T tablename --dump
  8. 8Use --batch for automated non-interactive scanning
  9. 9Save session data for later resumption with -s session.sqlite

Warnings

Use Cases

SQL Injection Testing

Automatically detect all five SQL injection types across GET, POST, and header parameters.

Database Enumeration

Extract database names, table names, column names, and full data contents from vulnerable applications.

Privilege Escalation

Identify database user privileges and attempt escalation to DBA for full server control.

OS Command Execution

Leverage database-specific features to execute operating system commands on the target server.

WAF Bypass

Use tamper scripts to bypass Web Application Firewalls and security filters.

Automated Web Auditing

Crawl websites, detect forms, and test all parameters for injection vulnerabilities.

Password Hash Extraction

Enumerate and extract database user password hashes for offline cracking with John the Ripper or Hashcat.

File System Access

Read and write files on the database server through INTO OUTFILE and UTL_FILE for data exfiltration or webshell upload.

Stored Procedure Abuse

Execute database stored procedures for advanced exploitation including linked server traversal and XPCmdShell execution.

Blind Injection Automation

Automate boolean-based and time-based blind SQL injection to extract data when no error messages are visible.

Key Features

Comparison

SQLMap vs Manual SQL Injection vs Burp Scanner

FeatureSQLMapManual InjectionBurp Scanner
SpeedFast (automated)Slow (hand-crafted)Fast (automated)
Learning ValueMedium (understand output)Very high (core skill)Low (black box)
WAF Evasion30+ tamper scriptsFull controlLimited
Data ExtractionAutomated dumpManual, tediousDetection only
Best ForConfirmed exploitation at scaleLearning + edge casesBroad app coverage

SQLMap Level & Risk — Coverage vs Noise

FeatureSettingRequestsWhen to Use
--level=1 --risk=1 (default)GET/POST values onlyFewestFirst pass, quiet recon
--level=3Adds Cookie & User-AgentModerateParams hidden in headers
--level=5All headers & entry pointsMostThorough authorized audit
--risk=2Adds heavy time-basedMoreBoolean blind fails
--risk=3Adds OR-based payloadsHighest (can modify data)Lab / explicit sign-off only

SQL Injection Technique Selection (--technique)

FeatureTechniqueFlagNotes
Boolean-based blindTrue/false page diffBReliable, moderate speed
Error-basedDB error in responseEFast when errors surface
UNION queryAppended UNION SELECTUFastest bulk extraction
Stacked queriesMultiple statementsSEnables OS/file actions where supported
Time-based blindResponse delayTWorks when no output — slowest

Best Practices

Common Errors

sqlmap: command not found
Install it with sudo apt install sqlmap, pip install sqlmap, or clone the repo and run python sqlmap.py from the source directory.
[CRITICAL] all tested parameters do not appear to be injectable
Raise coverage with --level=5 --risk=3, confirm you are testing the right parameter with -p, and provide a full request via -r request.txt so headers and cookies are included.
[CRITICAL] unable to connect to the target URL
Verify the URL in a browser or with curl -I, check connectivity, and if you route through Burp add --proxy=http://127.0.0.1:8080.
[CRITICAL] connection timed out to the target URL
Add --timeout=30, slow down with --delay=1, and reduce --threads. A WAF may be throttling you — see the WAF error below.
[WARNING] heuristic detected that the target is protected by a WAF/IPS
On authorized targets, try --tamper (e.g. space2comment,between), lower --threads, add --random-agent, and pace requests with --delay. Detect the WAF first with wafw00f.
[CRITICAL] you did not provide the list of targets / no parameter to test
Provide a parameter with -u "http://site/?id=1", pass POST data with --data, or capture the full request in Burp and feed it with -r request.txt.
[CRITICAL] connection reset / the target closed the connection
Reduce aggression: fewer --threads, add --delay, use --random-agent, and consider --safe-url/--safe-freq to interleave benign requests.
[CRITICAL] can't establish SSL connection / certificate verify failed
Add --force-ssl if the site needs HTTPS, and on authorized test targets you can bypass certificate validation. Confirm the correct scheme (http vs https).
[CRITICAL] unable to retrieve the number of databases / no output
Switch technique with --technique=BEUST, confirm privileges with --privileges, and for blind cases add --level and be patient — time-based extraction is slow.
CSRF token error / the session appears to be expired
Use --csrf-token and --csrf-url to let SQLMap fetch fresh tokens, and pass a valid session with --cookie or a full -r request file.
[ERROR] there was an error while unpacking / stale session in the output directory
Add --flush-session to clear cached data for the target, or --fresh-queries to ignore the query cache for this run.
PermissionError writing to the output directory
Run as a user that owns the output path, set --output-dir to a writable location, or mount a writable volume when using the Docker image.

People Also Ask

How do I test a login page with SQLMap?

Use -r request.txt to pass a saved Burp Suite request, or --data='user=admin&pass=*' to test POST parameters. The * marks the injection point. Add --level=5 --risk=3 for maximum injection testing depth. Always test on authorized targets only.

How long does SQLMap take to test a target?

Simple GET parameter tests complete in seconds. Full database dumps can take hours depending on database size and injection complexity. Use --threads for parallel requests, --batch for non-interactive mode, and --smart to reduce unnecessary requests on large targets.

Can SQLMap bypass WAFs and firewalls?

SQLMap has built-in WAF bypass techniques including --tamper scripts (space2comment, between, randomcase), --random-agent, and --delay for rate limiting. Use --level=5 --risk=3 with tamper scripts for best WAF bypass results.

What SQL injection types does SQLMap support?

SQLMap supports five injection types: boolean-based blind (--technique=B), time-based blind (--technique=T), error-based (--technique=E), UNION query-based (--technique=U), and stacked queries (--technique=S). It automatically detects and selects the best technique.

How do I use SQLMap with Burp Suite?

Save a vulnerable request from Burp Suite to a file (right-click > Save item), then run sqlmap -r request.txt. SQLMap automatically parses cookies, headers, and POST data from the Burp request. Add -p parameter_name to target a specific parameter.

Can SQLMap dump an entire database?

Yes. Use --dump-all to extract all data from all databases, or --dump -D dbname -T tablename for specific tables. Add --threads=10 for faster extraction. Use --where to filter rows. Always ensure you have authorization for the scope of data you extract.

Learning Path

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

Related Tools

Nikto

Web Application

Web server scanner that complements SQLMap by identifying misconfigurations and outdated software on the same targets.

Gobuster

Web Application

Directory and subdomain brute-forcer for discovering hidden endpoints that SQLMap can then test for injection.

Nmap

Information Gathering

Network scanner that identifies web services and open ports for SQLMap to target with injection testing.

Hydra

Password Attacks

Online password brute-forcer for services discovered alongside vulnerable web applications.

Metasploit

Exploitation

Exploitation framework for post-SQLMap exploitation using extracted credentials and OS shell access.

Burp Suite

Web Application

Web security testing proxy for intercepting and modifying HTTP requests before feeding them to SQLMap.

XSStrike

Web Application

Advanced XSS detection and exploitation tool for testing cross-site scripting vulnerabilities alongside SQL injection.

FFUF

Web Application

Fast web fuzzer for discovering hidden directories, parameters, and virtual hosts on target web applications.

Frequently Asked Questions

What is SQLMap?

SQLMap is an open-source penetration testing tool that automates SQL injection detection and exploitation. It supports five SQL injection types (boolean-based blind, time-based blind, error-based, UNION query-based, and stacked queries) and over 30 database backends. SQLMap can enumerate databases, extract data, escalate privileges, and execute OS commands through vulnerable web applications.

What is SQLMap used for?

SQLMap is used for five primary tasks: detecting SQL injection vulnerabilities in web applications, enumerating database structures (databases, tables, columns), extracting sensitive data from vulnerable databases, escalating privileges to database administrator, and executing operating system commands through database-specific features like xp_cmdshell.

How does SQLMap work?

SQLMap sends specially crafted payloads to web application parameters and analyzes the server's responses. It tests for boolean-based blind (true/false logic), time-based blind (response delays), error-based (database errors), UNION query-based (appended SELECT), and stacked queries (semicolon-separated statements) injection types. Once injection is confirmed, it uses the identified technique to extract data or execute commands.

Is SQLMap free?

Yes, SQLMap is completely free and open source under the GNU General Public License (GPL). You can download it from GitHub, install it via apt-get install sqlmap on Kali Linux, or clone the repository directly. All features including tamper scripts, OS shell access, and database enumeration are included at no cost.

Is SQLMap legal?

SQLMap itself is legal software. However, using it to test web applications without explicit written permission from the owner is illegal in most jurisdictions. SQL injection exploitation can modify data, extract credentials, and execute system commands. Unauthorized use violates laws like the CFAA (US) and Computer Misuse Act (UK). Always obtain proper authorization before testing.

What databases does SQLMap support?

SQLMap supports over 30 database backends including MySQL, PostgreSQL, Microsoft SQL Server, Oracle, SQLite, IBM DB2, Firebird, SAP MaxDB, Sybase, Informix, Altibase, MonetDB, MariaDB, and others. It automatically detects the database backend and adjusts exploitation techniques accordingly.

Can SQLMap bypass WAFs?

Yes, SQLMap includes over 30 tamper scripts for WAF bypass. Common scripts include space2comment (replaces spaces with /**/), charencode (URL-encodes characters), between (replaces > with NOT BETWEEN), and randomcase (randomizes letter casing). Chain multiple tamper scripts with --tamper=script1,script2 for maximum evasion.

What is the difference between --level and --risk in SQLMap?

--level controls the number of injection tests performed (1-5). Level 1 tests GET/POST parameters; level 5 tests cookies, HTTP headers, and User-Agent. --risk controls the risk of tests (1-3). Risk 1 uses safe tests; risk 3 adds heavy time-based tests that may cause DoS. Use --level=5 --risk=3 only in authorized penetration tests on resilient applications.

Can SQLMap get a reverse shell?

Yes, when the database user has sufficient privileges (DBA) and the database backend supports it. Use --os-shell to get an interactive command shell through MySQL's LOAD DATA INFILE or MSSQL's xp_cmdshell. You can also use --os-pwn for a Meterpreter shell through Metasploit integration.

How long does a SQLMap scan take?

Scan time depends on the target, techniques used, and --level/--risk settings. A basic boolean detection scan takes 30-60 seconds. Full enumeration with --level=5 --risk=3 can take 10-30 minutes. Time-based blind extraction is slowest, potentially hours for large datasets. Use --threads=10 to parallelize data extraction.

What is the --batch flag in SQLMap?

The --batch flag runs SQLMap in non-interactive mode, automatically answering 'yes' to all prompts and choosing default options. Essential for automated scanning, CI/CD pipelines, and scripted testing. Without --batch, SQLMap pauses for user input at every decision point.

Can SQLMap test POST parameters?

Yes. Use sqlmap -u "http://target.com/" --data="username=admin&password=test" to test POST parameters. You can also save a full HTTP request with Burp Suite and load it with sqlmap -r request.txt, which automatically tests all parameters including POST data, cookies, and headers.

How do I practice SQLMap safely?

Practice on intentionally vulnerable applications like DVWA (Damn Vulnerable Web Application), bWAPP, SQLi-labs, or HackTheBox/TryHackMe machines. These environments are designed for learning and provide legal, safe targets. Never practice on systems you do not own or have permission to test.

What is the difference between SQLMap and manual SQL injection?

SQLMap automates detection and exploitation, testing thousands of payloads automatically. Manual injection gives you full control and understanding of the vulnerability. SQLMap is faster and more thorough; manual testing is better for learning and complex injection scenarios that automation cannot handle. Professional penetration testers use both approaches.

Can SQLMap exploit stored SQL injection?

Yes. Save the HTTP request containing the injection point with Burp Suite, then use sqlmap -r request.txt. For stored injection in form fields, SQLMap can test and exploit injection that is stored in the database and triggered when other users view the affected page.

How do I update SQLMap to the latest version?

Update SQLMap by running sqlmap --update if installed from the Git repository. On Kali Linux, use sudo apt update && sudo apt install --only-upgrade sqlmap. The --update flag pulls the latest code from the GitHub repository and ensures you have the newest tamper scripts and detection techniques.

How do I test for time-based blind injection?

Use --technique=T to test specifically for time-based blind injection. You can adjust the delay threshold with --time-sec=5 (default is 5 seconds). Time-based injection is the slowest technique but works when no error messages or UNION output are available. It measures response time differences to infer data.

Can SQLMap test REST API endpoints?

Yes. Save the API request with Burp Suite and load it with sqlmap -r request.txt. SQLMap will automatically test all parameters in the request body, headers, and URL. For JSON APIs, use --data with the JSON payload and --headers to include authentication tokens.

Can sqlmap bypass login authentication?

Yes, use sqlmap with the --forms flag to automatically test login form parameters: sqlmap -u 'http://target.com/login' --forms. You can also manually specify the login POST data with --data='username=admin&password=test' and target specific parameters with -p. Sqlmap tests for authentication bypass through SQL injection in the login fields.

How do I use sqlmap with Tor for anonymity?

First start the Tor service (sudo service tor start), then configure sqlmap to use the Tor SOCKS5 proxy: sqlmap -u 'http://target.com' --proxy=socks5://127.0.0.1:9050. This routes all sqlmap traffic through the Tor network for anonymity. Note that Tor adds latency and may cause timeouts — increase --timeout to 30 seconds.

Can sqlmap test for second-order SQL injection?

SQLMap has limited support for second-order injection. Use the --second-order flag to specify a URL that is triggered after the initial injection. First inject a payload into a registration or profile form, then point --second-order to the page where the stored payload is executed. Second-order injection requires manual identification of the injection and response pages.

How do I use sqlmap tamper scripts to bypass WAF?

Chain multiple tamper scripts with --tamper: sqlmap -u 'http://target.com/?id=1' --tamper=space2comment,between,randomcase. Common bypass chains include between+space2comment for ModSecurity, randomcase+charencode for Akamai, and apostrophemask+space2comment for Cloudflare. Write custom tamper scripts in /usr/share/sqlmap/tamper/ for specific WAF signatures.

Is it legal to use SQLMap?

SQLMap is legal to install and run, but using it against a website you do not own or lack written permission to test is illegal under computer-misuse laws such as the US CFAA and the UK Computer Misuse Act. Only run SQLMap against systems you own, deliberately vulnerable labs (DVWA, bWAPP, the SQLi-labs project), or targets covered by a signed engagement or an in-scope bug bounty program.

How do I practice SQLMap legally?

Use intentionally vulnerable practice environments: DVWA, bWAPP, OWASP Juice Shop, and the SQLi-labs series all run locally in a VM or Docker and are designed for training. These let you learn --dbs, --tables, and --dump safely without touching real infrastructure. Never practice on live sites, even 'just to test'.

Why does SQLMap say the parameter is not injectable?

A 'not injectable' result usually means the parameter is properly parameterized, a WAF is filtering payloads, or you have not probed deeply enough. Raise coverage with --level=5 --risk=3, provide a full request with -r request.txt (capturing cookies and headers), and try --tamper scripts if a WAF is present. If it is genuinely parameterized, that is the site being secure — not a SQLMap failure.

How do I test a POST request or login form with SQLMap?

Capture the request in Burp Suite, save it to a file, and run sqlmap -r request.txt. SQLMap parses the method, body, cookies, and headers automatically. For a specific field use --data="user=admin&pass=test" -p user. This is the reliable way to test authenticated areas and complex forms.

What is the safest way to run SQLMap in a real engagement?

Start with detection only (no --dump), use --batch to avoid accidental destructive prompts, and avoid --os-shell, --sql-shell, and stacked-query writes unless the scope explicitly authorizes them. Add --threads conservatively, log everything for the report, and prefer read-only enumeration (--current-db, --tables) before any data extraction. Coordinate with the client before touching production databases.

How does SQLMap compare to manual SQL injection testing?

SQLMap automates payload generation, database fingerprinting, and extraction, which saves hours on confirmed injection points. Manual testing gives you deeper understanding and finds logic-specific or second-order flaws that automation misses. Best practice is to learn manual injection first, then use SQLMap to scale exploitation once you understand what it is doing.

Can SQLMap damage the target database?

Yes, if used carelessly. Stacked-query and --os-shell operations can write data or execute commands, and aggressive extraction on huge tables can load the server. Use read-only enumeration by default, avoid destructive flags unless authorized, test against a staging copy when possible, and never run high --risk levels on production without explicit sign-off.

How do I save and resume a SQLMap session?

SQLMap automatically stores session data in ~/.local/share/sqlmap/output/<target>/ (or the output directory), so re-running the same command resumes where it left off instead of re-testing. Use --flush-session to start fresh, and -o with --output-dir to control where results are written for your report.

Which SQLMap flags should beginners avoid?

Beginners should avoid --os-shell, --os-pwn, --sql-shell, and high --risk=3 settings until they understand the consequences — these can write to the database or execute commands. Start with -u, --dbs, --tables, --columns, and --dump on a lab target. Learn what each flag does before scaling up.

How do I report SQL injection findings professionally?

Document the vulnerable parameter, the injection type SQLMap identified, a redacted proof-of-concept, the database version/DBMS, and the potential impact (data exposure, auth bypass). Include remediation guidance — parameterized queries/prepared statements, least-privilege DB accounts, and input validation — and reference OWASP. Never include full dumped data in a report; prove impact with minimal evidence.

Tags

#sql-injection#web-security#database-security#penetration-testing

Output Explanation

SQLMap output shows: injection type (boolean/time/error/union), parameter position, database backend, and retrieved data. Vulnerable parameters are marked with 'injectable' status. Retrieved databases, tables, and columns are displayed in tabular format during enumeration.

Ethical Usage Notice

This tool is designed for authorized security testing, educational purposes, and legitimate network administration only. Unauthorized access to computer systems is illegal.