Sql Injection Pentesting Workflow
Purpose: Structured methodology for SQL injection identification, exploitation, and post-exploitation during penetration testing engagements.
Quick Reference
Detection
Confirm SQLi vulnerability
', ", ), -- -
Column Enum
Determine column count
ORDER BY n / UNION SELECT 1,2,3...
Data Extraction
Retrieve database contents
UNION + INFORMATION_SCHEMA
Privilege Check
Assess exploitation depth
super_priv, user_privileges
File Operations
Read/write system files
LOAD_FILE(), INTO OUTFILE
Code Execution
Establish persistence
Web shell upload
Phase 1: SQLi Detection & Confirmation
1.1 Injection Point Identification
Test input fields systematically with these payloads. Observe for errors, behavioural changes, or time delays.
Detection Payloads
'
%27
String terminator
"
%22
Double-quote terminator
)
%29
Close parenthesis
#
%23
MySQL comment
;
%3B
Statement terminator
'-- -
%27-- -
String + comment
' OR '1'='1
-
Boolean true injection
' AND '1'='2
-
Boolean false injection
' AND SLEEP(5)-- -
-
Time-based blind detection
Detection Strategy: Compare responses between ' AND '1'='1 (true) and ' AND '1'='2 (false). Different responses confirm boolean-based SQLi.
1.2 Database Fingerprinting
Once SQLi is confirmed, identify the backend DBMS.
Phase 2: Authentication Bypass
2.1 Standard Bypass Payloads
Use when targeting login forms or authentication mechanisms.
Context Matters: Analyse error messages to determine quote style (' vs "), parenthesis usage, and comment syntax required.
2.2 Bypass Decision Tree
Phase 3: Union-Based Injection
3.1 Column Count Enumeration
Critical: Union injection requires matching the exact column count of the original query.
Method 1: ORDER BY (Recommended)
Method 2: UNION SELECT
Column Discovery ORDER BY is stealthier (fewer requests). UNION SELECT provides immediate confirmation and identifies displayable columns.
3.2 Identifying Output Columns
Once column count is known, identify which columns render in the response.
Numbers appearing in the response indicate injectable output positions.
3.3 Data Extraction Templates
Replace the displayable column position with your extraction query.
Phase 4: Database Enumeration
4.1 Enumeration Workflow
4.2 Enumeration Payloads
Step 1: List All Databases
Step 2: List Tables in Target Database
Step 3: List Columns in Target Table
Step 4: Extract Data
4.3 Concatenation for Single-Column Output
When only one column displays output, concatenate multiple values.
Phase 5: Privilege Enumeration
5.1 User Context Assessment
5.2 Administrative Privilege Check
5.3 File Operation Permissions
secure_file_priv Values
Empty string: File operations allowed anywhere
Directory path: File operations restricted to that directory
NULL: File operations completely disabled
Phase 6: File Operations
6.1 Reading Files (LOAD_FILE)
Requirements: FILE privilege, file within secure_file_priv path, readable by MySQL user.
High-Value File Targets
/etc/passwd
User enumeration
/etc/shadow
Password hashes (requires root)
/var/www/html/config.php
Database credentials
/var/www/html/wp-config.php
WordPress credentials
/var/www/html/.htaccess
Apache configuration
/etc/apache2/sites-available/000-default.conf
Virtual host config
/etc/mysql/my.cnf
MySQL configuration
6.2 Writing Files (INTO OUTFILE)
Requirements: FILE privilege, writable secure_file_priv path, destination writable by MySQL.
Phase 7: Web Shell Deployment
7.1 PHP Web Shell Upload
7.2 Web Shell Usage
7.3 Common Web Root Paths
Debian/Ubuntu Apache
/var/www/html/
CentOS/RHEL Apache
/var/www/html/
Nginx (default)
/usr/share/nginx/html/
XAMPP
/opt/lampp/htdocs/
Windows XAMPP
C:/xampp/htdocs/
Windows IIS
C:/inetpub/wwwroot/
MySQL Operator Precedence
Understanding precedence is critical for crafting working payloads.
1 (Highest)
Division /, Multiplication *, Modulus %
2
Addition +, Subtraction -
3
Comparison =, >, <, <=, >=, !=, LIKE
4
NOT !
5
AND &&
6 (Lowest)
OR ||
Why ' OR '1'='1 Works The query SELECT * FROM users WHERE user='' OR '1'='1' evaluates user='' first (false), then '1'='1' (true). Since false OR true = true, all rows return.
MySQL CLI Reference
Connection
Database Operations
Table Operations
Column Operations
Query Modifiers
Payload Quick Reference
Authentication Bypass
Union Injection Template
INFORMATION_SCHEMA Queries
File Operations
Troubleshooting
No output from UNION
Wrong column count
Increment columns in ORDER BY
Syntax error
Quote mismatch
Try " instead of '
Comment not working
Wrong syntax
Try # or -- - (space after --)
LOAD_FILE returns NULL
Insufficient privileges
Check FILE privilege
OUTFILE fails
secure_file_priv restriction
Check allowed directories
Numbers not displaying
Columns are non-displayable
Try different column positions
Resources
Last updated