📕 FIELD MANUAL 21.1: LDAP INJECTION (THE DIRECTORY DRILL)
Objective: We will manipulate LDAP (Lightweight Directory Access Protocol) filters to bypass authentication or enumerate users and groups in the Directory...
Classification: RED TEAM EYES ONLY
Objective: We will manipulate LDAP (Lightweight Directory Access Protocol) filters to bypass authentication or enumerate users and groups from Active Directory.
MITRE ATT&CK: T1078 (Valid Accounts), T1087 (Account Discovery).
1. INTEL & RECON: ALIEN SYNTAX
Sección titulada «1. INTEL & RECON: LA SINTAXIS ALIENÍGENA»LDAP does not use SELECT. We will use Filters.
A typical login filter looks like this:
(&(cn=username)(userPassword=password))(Translation: AND the name is ‘username’ AND the password is ‘password’).
The Magic Character:
In SQL, it is ' (quote). In LDAP, they are * (wildcard), ( and ) (parentheses).
2. WEAPONIZATION: BREAKING THE FILTER
Sección titulada «2. WEAPONIZATION: ROMPIENDO EL FILTRO»TECHNIQUE A: Authentication Bypass (The Silent Injection)
Sección titulada «TÉCNICA A: Authentication Bypass (La Inyección Silenciosa)»We want the filter to be TRUE without knowing the password.
- Attacker Input (User):
admin*)(cn=* - Resulting Filter:
(&(cn=admin*)(cn=*)(userPassword=password)) - Parser Analysis:
cn=admin*-> Does the name start with admin? YES.cn=*-> Is the name something? YES.- The rest
(userPassword=...)will remain “outside” the main logic or will be ignored depending on the code implementation (OpenLDAP vs AD).
- Variant:
admin))(|((password=*-> We will inject an OR (|) to create a tautology.
TECHNIQUE B: Blind LDAP Injection (Enumeration)
Sección titulada «TÉCNICA B: Blind LDAP Injection (Enumeración)»If the application does not show errors but responds differently depending on whether the user exists or not.
- Question: “Is there a user that starts with ‘A’?”
- Payload:
admin*)(cn=A*- If login is correct/specific error -> Exists.
- If login fails -> Does not exist.
- We will iterate:
cn=Ad*,cn=Adm*…
3. PURPLE TEAM VIEW (DEFENSE)
Sección titulada «3. PURPLE TEAM VIEW (DEFENSA)»- Defense:
- Escaping: The characters
( ) * \ NULmust be escaped to their HEX representation (\28,\29,\2a). - Frameworks: We will use libraries that abstract the construction of filters (such as LINQ to LDAP in .NET) instead of concatenating strings.
- Escaping: The characters

