SQL Injection Testing
This skill should be used when the user asks to "test for SQL injection vulnerabilities", "perform SQLi attacks", "bypass authentication using SQL injection", "extract database inform.
Content
Purpose
Execute comprehensive SQL injection vulnerability assessments on web applications to identify database security flaws, demonstrate exploitation techniques, and validate input sanitization mechanisms. This skill enables systematic detection and exploitation of SQL injection vulnerabilities across in-band, blind, and out-of-band attack vectors to assess application security posture.
Inputs / Prerequisites
Required Access
- -Target web application URL with injectable parameters
- -Burp Suite or equivalent proxy tool for request manipulation
- -SQLMap installation for automated exploitation
- -Browser with developer tools enabled
Technical Requirements
- -Understanding of SQL query syntax (MySQL, MSSQL, PostgreSQL, Oracle)
- -Knowledge of HTTP request/response cycle
- -Familiarity with database schemas and structures
- -Write permissions for testing reports
Legal Prerequisites
- -Written authorization for penetration testing
- -Defined scope including target URLs and parameters
- -Emergency contact procedures established
- -Data handling agreements in place
Outputs / Deliverables
Primary Outputs
- -SQL injection vulnerability report with severity ratings
- -Extracted database schemas and table structures
- -Authentication bypass proof-of-concept demonstrations
- -Remediation recommendations with code examples
Evidence Artifacts
- -Screenshots of successful injections
- -HTTP request/response logs
- -Database dumps (sanitized)
- -Payload documentation
Core Workflow
Phase 1: Detection and Reconnaissance
#### Identify Injectable Parameters
Locate user-controlled input fields that interact with database queries:
#### Test for Basic Vulnerability Indicators
Insert special characters to trigger error responses:
Monitor application responses for:
- -Database error messages revealing query structure
- -Unexpected application behavior changes
- -HTTP 500 Internal Server errors
- -Modified response content or length
#### Logic Testing Payloads
Verify boolean-based vulnerability presence:
Compare responses between true and false conditions to confirm injection capability.
Phase 2: Exploitation Techniques
#### UNION-Based Extraction
Combine attacker-controlled SELECT statements with original query:
#### Error-Based Extraction
Force database errors that leak information:
#### Blind Boolean-Based Extraction
Infer data through application behavior changes:
#### Time-Based Blind Extraction
Use database sleep functions for confirmation:
#### Out-of-Band (OOB) Extraction
Exfiltrate data through external channels:
Phase 3: Authentication Bypass
#### Login Form Exploitation
Craft payloads to bypass credential verification:
Query transformation example:
Phase 4: Filter Bypass Techniques
#### Character Encoding Bypass
When special characters are blocked:
#### Whitespace Bypass
Substitute blocked spaces:
#### Keyword Bypass
Evade blacklisted SQL keywords:
Quick Reference
Detection Test Sequence
Database Fingerprinting
Information Schema Queries
Common Payloads Quick List
| Purpose | Payload |
|---|---|
| Basic test | `'` or `"` |
| Boolean true | `OR 1=1--` |
| Boolean false | `AND 1=2--` |
| Comment (MySQL) | `#` or `-- ` |
| Comment (MSSQL) | `--` |
| UNION probe | `UNION SELECT NULL--` |
| Time delay | `AND SLEEP(5)--` |
| Auth bypass | `' OR '1'='1` |
Constraints and Guardrails
Operational Boundaries
- -Never execute destructive queries (DROP, DELETE, TRUNCATE) without explicit authorization
- -Limit data extraction to proof-of-concept quantities
- -Avoid denial-of-service through resource-intensive queries
- -Stop immediately upon detecting production database with real user data
Technical Limitations
- -WAF/IPS may block common payloads requiring evasion techniques
- -Parameterized queries prevent standard injection
- -Some blind injection requires extensive requests (rate limiting concerns)
- -Second-order injection requires understanding of data flow
Legal and Ethical Requirements
- -Written scope agreement must exist before testing
- -Document all extracted data and handle per data protection requirements
- -Report critical vulnerabilities immediately through agreed channels
- -Never access data beyond scope requirements
Examples
Example 1: E-commerce Product Page SQLi
Scenario: Testing product display page with ID parameter
Initial Request:
Detection Test:
Column Enumeration:
Data Extraction:
Example 2: Blind Time-Based Extraction
Scenario: No visible output, testing for blind injection
Confirm Vulnerability:
Extract Database Name Length:
Extract Characters:
Example 3: Login Bypass
Target: Admin login form
Standard Login Query:
Injection Payload:
Resulting Query:
Result: Password check bypassed, authenticated as administrator.
Troubleshooting
No Error Messages Displayed
- -Application uses generic error handling
- -Switch to blind injection techniques (boolean or time-based)
- -Monitor response length differences instead of content
UNION Injection Fails
- -Column count may be incorrect → Test with ORDER BY
- -Data types may mismatch → Use NULL for all columns first
- -Results may not display → Find injectable column positions
WAF Blocking Requests
- -Use encoding techniques (URL, hex, unicode)
- -Insert inline comments within keywords
- -Try alternative syntax for same operations
- -Fragment payload across multiple parameters
Payload Not Executing
- -Verify correct comment syntax for database type
- -Check if application uses parameterized queries
- -Confirm input reaches SQL query (not filtered client-side)
- -Test different injection points (headers, cookies)
Time-Based Injection Inconsistent
- -Network latency may cause false positives
- -Use longer delays (10+ seconds) for clarity
- -Run multiple tests to confirm pattern
- -Consider server-side caching effects
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
FAQ
Discussion
Loading comments...