📕 FIELD MANUAL 12.1: SECOND-ORDER SQL INJECTION (THE DELAYED INJECTION)
Objective: We will exploit logical vulnerabilities where the payload is injected in one phase (Seeding), but detonates in a completely different function...
Classification: RED TEAM EYES ONLY
Objective: We will exploit logical vulnerabilities where the payload is injected in one phase (Sowing), but detonated in a completely different function (Detonation).
MITRE ATT&CK: T1190 (Exploit Public-Facing Applications).
1. INTEL & RECON: THE PATIENT SNIPER
Sección titulada «1. INTEL & RECON: EL FRANCOTIRADOR PACIENTE»Most pentesters fail here because they expect an immediate error. In Second-Order, the attack is asynchronous.
Critical Tactical Difference:
Sección titulada «Diferencia Táctica Crítica:»- Classic/Reflected:
Input->Query->Boom(Immediate). - Stored:
Input->DB->Vista de Admin->Boom(XSS - Client). - Second-Order:
Input (Seguro)->DB->Proceso de Backend->Boom(SQLi - Server).
Combat Scenario (The Password Change):
Sección titulada «Escenario de Combate (El Cambio de Contraseña):»- Registration (Seeding): We register as a user.
- Input:
admin' -- - Backend: The app escapes the quotes (
\') when inserting. - DB: The user is literally saved as the string
admin' --.
- Input:
- Operation (Detonation): We will go to “Change Password”.
- Vulnerable Logic: The app retrieves our user from the session or DB to build the update query.
- Constructed Query:
UPDATE users SET password='123' WHERE username='admin' --' - Result: The query closes the quote after
adminand comments out the rest (-). We have just changed the password of the real useradmin, not ours.
2. ARMAMENT: THE LOGICAL TRAP
Sección titulada «2. ARMAMENTO: LA TRAMPA LÓGICA»STEP 1: The Seeding
Sección titulada «PASO 1: La Siembra (Seeding)»We must find a field that is saved in the DB and that we know will be used in another query later without being re-sanitized.
- Common Vectors: Username, Shipping address, Email, Profile comments.
- Seeding Payload (MySQL):
admin' # - Seeding Payload (Generic):
admin' --
STEP 2: The Detonation (Triggering)
Sección titulada «PASO 2: La Detonación (Triggering)»We will execute the secondary function that uses the seeded data.
- Action: We will go to “Change Password”, “Update Profile”, or “View Order History”.
- Mechanism: If the application blindly trusts the data because it “comes from the database” (trusted zone) and concatenates it, the injection occurs at that moment.
3. AUTOMATION & TOOLS
Sección titulada «3. AUTOMATIZACIÓN & HERRAMIENTAS»Detecting this automatically is difficult because the scanner needs to understand the business logic (Register -> Then go to Profile).
- Burp Suite (Manual):
- We will intercept the Registration.
- We will modify the
usernametotest'. - We will navigate through the app while logged in. If we see a SQL error on any other page, it is Second-Order.
4. PURPLE TEAM PERSPECTIVE (DEFENSE)
Sección titulada «4. PERSPECTIVA DEL EQUIPO PURPLE (DEFENSA)»- Defense: The golden rule is “Trust No One”.
- Validation: We will never trust data, even if it comes from our own database.
- Mitigation: We will always use Prepared Statements, both when inserting data (Input) and when retrieving and using it in a new query (Processing).

