0xnhl

SQLmap

/ Update
5 min read

SQLmap is an automated web vulnerability and SQL Injection detection and exploitation tool. It helps automate the enumeration of vulnerable applications, as well as the exploitation of SQL injection.

Usage#

sqlmap [options]
OR
python sqlmap.py [options]
plaintext

Run sqlmap against a single target URL:

sqlmap [-u|--url] "http://www.example.com/vuln.php?id=1"
plaintext

Send data in a POST request (--data implies POST request):

python sqlmap.py [-u|--url] "http://www.example.com/vuln.php" --data="id=1"
plaintext

Essential & Targeting Flags#

  • -u <url>: Specify the target URL (e.g., sqlmap -u "http://example.com").
  • -r <file>: Load an HTTP request from a text file (useful for POST requests or authenticated endpoints).
  • -p <parameter>: Manually define the parameter(s) to test for SQL injection.
  • --data=<string>: Send data string through a POST request.

Scope & Testing Depth#

  • --level=<1-5>: Set the level of tests to perform (default 1). Increasing the level adds more payloads and checks.
  • --risk=<1-3>: Set the risk level of tests (default 1). Higher risk tests can include dangerous, time-consuming queries that modify/damage data.
  • --technique=<B|E|U|S|T|Q>: Specify the SQL injection techniques to use: Boolean, Error, UNION, Stacked, Time-based, or Query.

Enumeration Flags#

  • --dbs: Enumerate all databases accessible by the database user.
  • --tables: Enumerate all tables within a specified or current database.
  • --columns: Enumerate all columns within a specific table.
  • --schema: Enumerate the entire database schema.

Data Extraction & Dumping#

  • --dump: Extract all entries/rows from a specific database, table, or column.
  • --dump-all: Dump all available database table entries.
  • -D <db>: Specify the database name.
  • -T <table>: Specify the table name.
  • -C <column>: Specify the column name.

WAF & Bypass#

  • --tamper=<script>: Use built-in or custom scripts to obfuscate payloads and bypass Web Application Firewalls (e.g., --tamper=space2comment).

Operational Flags#

  • --batch: Automatically select the default answer for all prompts (skips manual user interaction).
  • --threads=<number>: Max number of concurrent requests (speeds up data dumping).
  • --os-shell: Prompt for an interactive operating system shell (allows arbitrary OS command execution).

If you don’t want to manually add the flags to each command, use the--wizard flag with SQLMap. When you use this flag, the tool will guide you through each step and ask questions to complete the scan.

The --dbs flag helps you to extract all the database names. Once you get to know the database names, you can extract information about the tables of that database by using-D database_name --tables. After obtaining the tables, if you want to enumerate the records in those tables, you can use-D database_name -T table_name --dump.

 If you see any web application using GET parameters in the URLs to retrieve data, you can test that URL with the -u flag in the SQLMap tool. This is considered to be HTTP GET-based testing. This approach is followed when the application uses GET parameters in the URL to retrieve data from the searches.

You can also use POST-based testing, where the application sends data in the request’s body instead of the URL. Examples of this could be login forms, registration forms, etc. To follow this approach, you must intercept a POST request on the login or registration page and save it as a text file. Then we can use the -r flag to input that request saved in the text file to the SQLMap tool. eg: sqlmap -r intercepted_request.txt

In real-world scenarios, many web applications rely on cookies to maintain user sessions, enforce authentication, or apply access controls. When testing such applications, simply providing a URL with SQLMap may not be sufficient, as unauthenticated requests could be redirected, denied, or return different content. SQLMap supports cookie-based testing via the —cookie flag, which lets you include session cookies (such as PHPSESSIDJSESSIONID, or authentication tokens) directly in your request. This ensures that SQLMap interacts with the application in the same authenticated or authorised context as a normal user. For example, after logging into an application via a browser and capturing the session cookie, you can pass it to SQLMap using --cookie="SESSIONID=abcdef123456" to accurately test injection points that are only reachable after authentication.

Example#

Let’s take a look at a quick example of how to use SQLmap to exploit an SQL injection vulnerability. Say that a host with IP address 10.1.1.14 is vulnerable to SQL injection. In order to automate the enumeration and exploitation of this vulnerability, you first connect to the vulnerable application and capture the HTTP GET request by using a proxy. The example below shows the captured HTTP GET request. You can use this information to launch the SQLmap tool, to the vulnerable server (10.1.1.14).

 HTTP GET Request to a Vulnerable Web Application

GET /dvwa/vulnerabilities/sqli/?id=omar&Submit=Submit HTTP/1.1
Host: 10.1.1.14
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101Firefox/52.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://10.1.1.14/dvwa/vulnerabilities/sqli/
Cookie: security=low; PHPSESSID=1558e11b491da91be3b68e5cce953ca4
Connection: closeUpgrade-Insecure-Requests: 1
plaintext

The first highlighted line in Example 10-15 shows the GET request’s URI. The second highlighted line shows the cookie and the session ID (PHPSESSID=1558e11b491da91be3b68e5cce953ca4).

Using the SQLmap Tool to Exploit an SQL Injection Vulnerability

The first four highlighted lines in Example show how SQLmap automates the various tests and payloads sent to the vulnerable application. The last few highlighted lines show how SQLmap was able to enumerate all the databases in the SQL server.

When you have a list of all available databases, you can try to retrieve the tables and records of the dvwa database by using the command shown in Example below.

Retrieving Sensitive Information from a Database

The first four highlighted lines show how SQLmap was able to automatically enumerate users from the compromised database and crack their passwords.

SQLmap
https://nahil.xyz/vault/tools/sqlmap/
Author Nahil Rasheed
Published at July 7, 2025
Disclaimer This content is provided strictly for educational purposes only.