Ir al contenido

📕 FIELD MANUAL 5.2: SQL INJECTION POLYGLOTS (THE UNIVERSAL BULLET)

Objective: We will use a single complex payload capable of exploiting SQL injections in multiple syntactic contexts simultaneously.

0views

Classification: RED TEAM EYES ONLY

Objective: We will use a single complex payload capable of exploiting SQL injections in multiple syntactic contexts simultaneously.

Targets: Mass audits, initial scans (Fuzzing).

MITRE ATT&CK: T1190.

1. INTEL & RECON: THE THEORY OF CONTROLLED CHAOS

Sección titulada «1. INTEL & RECON: LA TEORÍA DEL CAOS CONTROLADO»

When we attack a parameter (id=...), we do not know what the backend query looks like:

  1. Integer: WHERE id = $id
  2. String (Single Quote): WHERE id = '$id'
  3. String (Double Quote): WHERE id = "$id"
  4. Parentheses: WHERE id = ('$id')

If we send 1' OR 1=1, we will fail if the backend uses double quotes or pure integers (sometimes). We need something that breaks all at once.

A Polyglot abuses the way SQL handles comments (/* ... */, --, #) to “consume” the syntax that bothers us and leave the payload active.

We are going to dissect the most famous polyglot from the Seclists repository.

SLEEP(5) /*' or SLEEP(5) or '" or SLEEP(5) or "*/

(Note: This is a simplified example for Time-Based. We will move on to a more generic authentication one).

admin'/*"*/ or 1=1 -- -

Behavioral Analysis:

Query: SELECT * FROM users WHERE user = '$input' Injection: SELECT * FROM users WHERE user = 'admin'/*"*/ or 1=1 -- -'

  • Explanation:
    1. 'admin' closes the string.
    2. /*"*/ is a block comment. The SQL engine ignores it completely.
    3. or 1=1 executes. SUCCESS!

Query: SELECT * FROM users WHERE user = "$input" Injection: SELECT * FROM users WHERE user = "admin'/*"*/ or 1=1 -- -"

  • Explanation:
    1. "admin'/*": Here the single quote is just text inside the double quotes. BUT, the double quote within the comment /*"*/ CLOSES the original string.
    2. / closes the comment (or generates ignored noise).
    3. or 1=1 is executed. SUCCESS! (Depending on the engine, it sometimes requires fine-tuning, but the idea is to saturate the delimiters).

Sometimes we want to test EVERYTHING at once.

javascript://%250Aalert(1)//"/*\'/*"/*--/*#*/OR 1=1 OR "a"="a

This monster attempts to execute JavaScript (if reflected), break SQL (single quotes, double quotes, hash comments, and dashes) all in one.

The Polyglot is ideal for a fast Discovery phase.

  1. Load: We will load Burp Intruder.
  2. Positions: We will mark all input parameters.
  3. Payloads: We will load a small list of Polyglots (3 or 4 strings).
    • ' OR 1=1 -- -
    • " OR 1=1 -- -
    • admin'/*"*/ or 1=1 -- -
  4. Attack: We will launch the attack. If ANY work, we will see a change in response length or a delay (if we use SLEEP).
  5. Advantage: Instead of sending 500 payloads per parameter, we will send 3. If we have 100 parameters, we will save thousands of requests.

4. ESCALATION: FROM POLYGLOT TO DEDICATED EXPLOIT

Sección titulada «4. ESCALADA: DE POLYGLOT A EXPLOIT DEDICADO»

The Polyglot is a "Mine detector".

  1. We will launch the Polyglot.
  2. If it exploits (error, delay, bypass), we WILL STOP using the Polyglot.
  3. We will switch to a specific payload (Module 1.1 or 3.1) for that specific context.
    • Why? Because Polyglots are messy and can corrupt data if we try to use them to extract information (UNION SELECT). We will only use them to enter or detect.

Polyglots are the easiest attacks for a WAF to detect due to their "ugliness".

  1. High Entropy: Strings with many special characters together ('/*"*/).
  2. WAF Signatures: Rules like Detect mixed quotes inside comments will trigger immediately.
  3. Length: They tend to be long and strange payloads.
  1. Input Sanitization: We will reject inputs containing SQL comment sequences (-, /*, #) if the field is a username or email.
  2. Prepared Statements: As always, parameterization causes the Polyglot to be treated as a simple garbage text string admin'/*"*/... that does not match any real user.

Status: Module 5.2 Completed. End of Phase 5. Next Step: Phase 6 - Specific Technologies (SQLite and CMS).