SQLMap Spellbook: Basic Usage of SQLMap

Prologue

This article is mainly intended to serve as my own cheat sheet and notes, but if it can also help you, that would be great. The content is summarized from the original document, so you can regard this article as an TL;DR version of the document per se.

I will consistently update the content if I find something missing or something worth to be noted. You can also contact me to update the content.

SQL Injection Types

There’re 5 types of SQLi vulnerability or 5 ways that SQLMap can test a website.

  1. Boolean-Based (Content-Based) Blind SQLi

    • Attackers send some boolean expression that forces the application to return different result depending on the TRUE or FALSE condition.

    • By trying the payload multiple times, attackers can infer the secret data.

  2. Time-Based Blind SQLi

    • This attack method relied on sending a function or an SQL query to the database to force it to wait or delay for an amount of time before responding. The responding time can tell the attackers if the query is TRUE or FALSE.
  3. Error-Based SQLi

    • By triggering the SQL error message from the database to obtain the data.
  4. Union-Based SQLi

    • Use the UNION operator to merge the result of original query and the one from the malicious query.
    • The secret data will then be rendered by the browser directly.
  5. Stacked Queries (Piggybacking)

    • Stacked queries injection allows multiple query in one SQL request.
    • It often uses the “;” sign as the seperator to concatenate several queries.

Magic Spells

The following are some parameters commonly used in SQLMap.

Options

FlagDescription
-h, --helpShow basic help message and exit
-hhShow advanced help message and exit
-v VERBOSEVerbosity level: 0-6 (default 1)

Target

At least one of these options has to be provided to define the target(s).

FlagDescription
-u URL, --url=URLTarget URL (e.g. “http://www.site.com/vuln.php?id=1”)

Request

These options can be used to specify how to connect to the target URL.

FlagDescription
--data=DATAData string to be sent through POST (e.g. “id=1”)
--cookie=COOKIEHTTP Cookie header value (e.g. “PHPSESSID=a8d127e…”)
--random-agentUse randomly selected HTTP User-Agent header value
--proxy=PROXYUse a proxy to connect to the target URL
--torUse Tor anonymity network
--check-torCheck to see if Tor is used properly

Injection

These options can be used to specify which parameters to test for, provide custom injection payloads and optional tampering scripts.

FlagDescription
-p TESTPARAMETERTestable parameter(s) (eg. -p username)
--dbms=DBMSForce back-end DBMS to provided value (eg. --dbms=mysql)
--tamper=TAMPERUse given script(s) for tampering injection data

Detection

These options can be used to customize the detection phase.

FlagDescription
--level=LEVELLevel of tests to perform (1-5, default 1)
--risk=RISKRisk of tests to perform (1-3, default 1)

Enumeration

These options can be used to enumerate the back-end database management system information, structure and data contained in the tables.

FlagDescription
-a, --allRetrieve everything
-b, --bannerRetrieve DBMS banner
--current-userRetrieve DBMS current user
--current-dbRetrieve DBMS current database
--passwordsEnumerate DBMS users password hashes
--dbsEnumerate DBMS databases
--tablesEnumerate DBMS database tables
--columnsEnumerate DBMS database table columns
--schemaEnumerate DBMS schema
--sql-shellPrompt for an interactive SQL shell
--dumpDump DBMS database table entries
--dump-allDump all DBMS databases tables entries
-D DBDBMS database to enumerate
-T TBLDBMS database table(s) to enumerate
-C COLDBMS database table column(s) to enumerate

Operating system access

These options can be used to access the back-end database management system underlying operating system.

FlagDescription
--os-shellPrompt for an interactive operating system shell
--os-pwnPrompt for an OOB shell, Meterpreter or VNC
--priv-escDatabase process user privilege escalation

General

These options can be used to set some general working parameters.

FlagDescription
--batchNever ask for user input, use the default behavior
--crawl=CRAWLDEPTHCrawl the website starting from the target URL (usually use 2)
--formsParse and test forms on target URL
--flush-sessionFlush session files for current target

Miscellaneous

FlagDescription
--wizardSimple wizard interface for beginner users

More About The Spells

If you want to know more about the magic spells of SQLMap, you can check out the official document. I will put some resources below JFYI.

  1. Chinese version of SQLMap docs.
  2. Official SQLMap docs

You can also use the -hh flag to see the manual page of sqlmap in your CLI.