SQLMap

Commands

sqlmap --flush-session

Detection

The --level flag affects which payload sqlmap tries and which injections points are tested, while the --risk flag adds more SQLi types.

Value
Level (1-5)
Risk (1-3)

1

GET and POST parameters are always tested (default value)

Innocuous for the majority of SQLi points (default value).

2

HTTP Cookie header values.

Adds heavy query time-based SQLis.

3

HTTP User-Agent/Referer headers values.

Adds OR-based SQLis.

sqlmap -u "http://www.example.com/vuln.php?id=1" --batch -v 0

Data Exfil

# List databases
sqlmap -r burp.req --batch --dbs
# Current database and user
sqlmap -r burp.req --banner --current-user --current-db --is-dba --batch
sqlmap -r burp.req -D testdb -T testtable --dump --where="col1 LIKE 'f%'" --batch -v 0

Advanced Data Exfil

sqlmap -r burp.req --search -T tableName --batch -v 0

OS Exploitation

Bypasses

Usage

Basic Usage

cURL

The lab used is from the Web Enumeration & Exploitation section of the Attacking Enterprise Networks module from HTB.

Copy as cURL from browser's Network tab (Figure 1).

Figure 1: Copying the cURL command via Mozilla's Network tab.

Change curl to sqlmap (Figure 2). If a specific parameter needs to be tested, we can use the * as follows: --data 'uid=1*&name=test'.

--batch chooses the defaults when prompted, -v 0 reduces the verbosity level.

Figure 2: Changing cURL to sqlmap and we are good to go!

HTTP Requests

Capture the Request Headers and POST data via the browser or Burp (Figure 3).

From Mozilla Copy Value -> Copy Request Headers and then add the parameters via Copy Value -> Copy POST Data.

Figure 3: Copying the POST request to a file with Burp Suite.

Supply the file to SQLMap (Figure 4).

Figure 4: Using SQLMap with a request file.

Resources

Last updated

Was this helpful?