📕 FIELD MANUAL 13.1: HQL & JPQL INJECTION (ENTERPRISE JAVA)
Objective: We will inject into common ORM (Hibernate/JPA) abstraction layers in large banking and corporate environments.
Classification: RED TEAM EYES ONLY
Objective: We will inject into ORM abstraction layers (Hibernate/JPA) common in large banking and corporate environments.
MITRE ATT&CK: T1190.
1. INTEL & RECON: WE'RE NOT IN SQL KANSAS
Sección titulada «1. INTEL & RECON: NO ESTAMOS EN SQL KANSAS»In Java Enterprise, developers do not write direct SQL. We write HQL (Hibernate Query Language) or JPQL.
- Pure SQL:
SELECT * FROM tbl_users WHERE name = 'x' - HQL/JPQL:
FROM User WHERE name = 'x'
Key Recognition Differences:
Sección titulada «Diferencias Clave de Reconocimiento:»- Objects, not Tables: We do not select tables (
tbl_users), we select Java Classes (User). - No UNION: Standard HQL does not support
UNION. This kills most fast extraction payloads. - Case Sensitive: Class (table) names are case-sensitive.
2. WEAPONIZATION: ATTACKING THE ABSTRACTION
Sección titulada «2. WEAPONIZATION: ATAQUE A LA ABSTRACCIÓN»TECHNIQUE A: Blind Column Enumeration
Sección titulada «TÉCNICA A: Enumeración de Columnas a Ciegas»Since there is no UNION, we will use errors or inference to map the Java object.
Payload to discover attributes (columns): If we attempt to access a property that does not exist in the mapped Java Class, Hibernate will throw a specific exception.
- Payload:
' AND x=1- Error:
Could not resolve property: x of: com.bank.User(We confirm that 'x' does not exist).
- Error:
- Payload:
' AND password=1- Error:
Incompatible typesorData type mismatch(This means thatpasswordDOES exist, but we are attempting to compare it to a number).
- Error:
TECHNIQUE B: Escaping to Native SQL
Sección titulada «TÉCNICA B: Saltando al SQL Nativo»Sometimes we can trick the Hibernate translator into passing native functions to the underlying database (Oracle/MySQL).
- Payload:
' OR 1=1 --- This usually works because Hibernate passes the
WHEREpart quite directly to the final SQL engine.
- This usually works because Hibernate passes the
3. AUTOMATION
Sección titulada «3. AUTOMATION»- SQLMap: Supports HQL Injection but often requires manual assistance.
- Flags:
-dbms="HQL"(though sometimes it is better to let it detect the actual backend).
4. PURPLE TEAM VIEW (DEFENSE)
Sección titulada «4. PURPLE TEAM VIEW (DEFENSA)»- Defense: We will use “Named Parameters” in JPA/Hibernate.
- Insecure:
entityManager.createQuery("FROM User WHERE name = '" + input + "'") - Secure:
entityManager.createQuery("FROM User WHERE name = :username").setParameter("username", input)
- Insecure:
- Detection: Java exception logs (Stack Traces) showing
org.hibernate.QueryException.

