Ir al contenido

📕 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...

0views

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).

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).

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:
    1. cn=admin* -> Does the name start with admin? YES.
    2. cn=* -> Is the name something? YES.
    3. 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*…
  • Defense:
    1. Escaping: The characters ( ) * \ NUL must be escaped to their HEX representation (\28, \29, \2a).
    2. Frameworks: We will use libraries that abstract the construction of filters (such as LINQ to LDAP in .NET) instead of concatenating strings.