Ir al contenido

STUDY GUIDE: TOTAL MASTERY OF SQL INJECTION (MASTER CLASS)

Instructor: Red Team Advisor & Threat Emulation Objective: We will internalize the logic, execution, and methodology of the 24 Injection Phases.

0views

Instructor: Red Team & Threat Emulation Advisor Objective: We will internalize the logic, execution, and methodology of the 24 Injection Phases.

🧠 INTRODUCTION: THE PHILOSOPHY OF THE ATTACK

Sección titulada «🧠 INTRODUCCIÓN: LA FILOSOFÍA DEL ATAQUE»

Forget about the code for a second.

SQL Injection is not “hacking a database”. It is hijacking a conversation. The web application is “talking” to the database. Our job is to get in the middle of that conversation and whisper instructions that the database believes come from the legitimate administrator.

Our training is divided into 3 Maturity Blocks. We won't try to run before we walk.

🏗️ BLOCK 1: FUNDAMENTALS AND DESTRUCTION (PHASES 1 - 7)

Sección titulada «🏗️ BLOQUE 1: FUNDAMENTOS Y DESTRUCCIÓN (FASES 1 - 7)»

The "Brute Force" level and direct impact.

In these phases, the door is open or semi-open. Our goal is to enter, steal everything, and gain control of the server.

  1. The Entrance (Phase 1):
    • Concept: The server concatenates our input. SELECT * FROM news WHERE id = + NUESTRO_INPUT.
    • Practice: We won't use tools yet. We'll do it manually. We'll write ' and see if the website “bleeds” (shows an error). If it bleeds, we can kill it.
    • Visualization: We'll imagine the query in our heads. If we insert UNION SELECT, we'll be attaching a second sheet of results below the original one.
  2. The Inference (Phase 3 - Blind):
    • Concept: The website no longer bleeds errors. It is blind.
    • Mental Game: Let's play “20 Questions”. “Is the first letter of the password A?”. The database responds “Yes” (loading the website) or “No” (404 error or empty content).
    • Time-Based: If it doesn't even respond “No”, we will force it to sleep (SLEEP). If it takes time to respond, it is a “Yes”.”
  3. The God (Phase 7 - RCE):
    • Concept: SQL is a powerful language. It can read and write files.
    • Execution: If we can write a file (INTO OUTFILE) in the folder where the website is located (/var/www/html), and that file contains PHP code (system(...)), we will have just turned a database into a command terminal. Game Over.
  • Installation: We will deploy bWAPP or DVWA in a local Docker container.
  • Exercise:
    1. We will extract the database version using UNION.
    2. We will extract the admin password using Boolean Blind (custom Python script, not SQLMap).
    3. We will obtain a reverse shell by writing a PHP file.

🛡️ BLOCK 2: EVASION AND CUNNING (PHASES 8 - 16)

Sección titulada «🛡️ BLOQUE 2: EVASIÓN Y ASTUCIA (FASES 8 - 16)»

The “Sniper” level. The enemy defends itself.

We are no longer alone. There is a security guard (WAF) and business rules.

  1. The Guardian (Phase 8 - WAF):
    • Concept: The WAF looks for forbidden words (UNION, SELECT).
    • Strategy: We will use synonyms or “noise”. If UNION is forbidden, perhaps /*!UNION*/ (executable comment in MySQL) is not. Or perhaps we will fragment the word into several parameters (HPP).
  2. The Logic (Phase 12 - Second Order):
    • Concept: It is a time bomb. We inject now, it explodes tomorrow.
    • Execution: We will register ourselves as admin' --. The database will store it. When we change our password, the database will search for our user, find the quote, and break the query, affecting the real admin.
  3. The Cloud (Phase 10):
    • Concept: The database is a dumb web browser.
    • Execution: We will tell it “Read this file”. But instead of a local file, we will give it a cloud URL (http://169.254.169.254). The database will obey, fetch the AWS keys, and we will steal the entire cloud.
  • Installation: We will look for “WAF Bypass” CTF challenges or we will configure ModSecurity in front of our DVWA and try to bypass it.
  • Exercise:
    1. We will use Tamper Scripts from SQLMap to evade a basic filter.
    2. We will practice NoSQL injection in a vulnerable NodeJS app (there are many on GitHub like NoSQLi-Lab).

👽 BLOCK 3: ELITE AND EXOTIC (PHASES 17 - 24)

Sección titulada «👽 BLOQUE 3: ELITE Y EXÓTICO (FASES 17 - 24)»

The “Movie Hacker” level. Nothing is what it seems.

Sometimes there is no SQL. There are other languages (LDAP, XPath, CQL) or physics problems (Time).

  1. Quantum Physics (Phase 18 - Race Conditions):
    • Concept: Two things happen at the same time.
    • Execution: We have €10. We will send 50 purchase requests in the same millisecond. The database will check the balance 50 times (all saying “has €10”) before it can subtract the money. We will buy 50 things for the price of one.
  2. The Digital Brain (Phase 19 - AI):
    • Concept: Social Engineering applied to machines.
    • Execution: We won't inject code. We will convince the LLM to ignore its rules and write malicious code for us.
  3. Infrastructure (Phase 24 - Redis):
    • Concept: Redis speaks plaintext.
    • Execution: If the web communicates with Redis and we inject line breaks, we will be able to inject configuration commands so that Redis writes our SSH key to the server. We will gain root access without a password.
  • Installation: We will deploy a Redis container without a password and a web application that makes requests to it (SSRF simulation).
  • Exercise:
    1. We will attempt to write a Web Shell in the web directory using only Redis commands (CONFIG SET).
    2. We will use Burp Turbo Intruder to exploit a Race Condition in a simple coupon script.

To master this, we need discipline.

  1. Reading: We will read the Cheat Sheet (v4.0) every day before starting. We will memorize the basic payloads.
  2. Practice: We will dedicate 1 hour a day to PortSwigger Web Security Academy (it's free and has incredible SQLi labs covering Oracle, Blind, and Logic).
  3. Tools: We won't use SQLMap at first. We will learn to do it manually with Burp Suite Repeater. Only when we understand why it works will we use SQLMap to automate.
  4. Code: We will learn the basics of PHP, Python, and NodeJS. To break the code, we must first know how to read it.

Remember: The difference between a Script Kiddie and a Red Teamer is that the Kiddie launches tools hoping they work. The Red Teamer knows why they have failed and how to fix them.

Now, we will go and break something (ethically).