LDAP Injection Fundamentals
What you'll learn: How attackers manipulate LDAP queries by injecting special characters into user input to bypass authentication or extract unauthorized data.
What is LDAP and Why Does It Matter?
LDAP (Lightweight Directory Access Protocol) is like a phonebook for networks—it stores and retrieves information about users, computers, and resources in organizations. Applications query LDAP directories using filters to find entries, often incorporating user-supplied input like usernames or email addresses.
How LDAP Queries Work
LDAP filters use a structured syntax with parentheses and operators. A typical authentication query might look like:
(&(uid=john)(userPassword=secret123))
This translates to: "Find an entry where the username is 'john' AND the password is 'secret123'."
The Injection Problem
When applications blindly insert user input into LDAP filters without validation, attackers can inject LDAP metacharacters to change the query's logic—similar to how SQL injection manipulates database queries.
Example Attack:
If the application builds a filter like:
(&(uid=USER_INPUT)(userPassword=PASSWORD_INPUT))
An attacker entering username *)(uid=*))(|(uid=* could transform the query into:
(&(uid=*)(uid=*))(|(uid=*)(userPassword=secret123))
This malformed query might bypass authentication by always returning true, or extract all user entries because * is a wildcard matching everything.
Basic Injection Techniques
- Wildcard injection (
*): Matches any value - OR operator (
|): Creates alternative conditions - Comment-like behavior: Closing parentheses prematurely to ignore password checks
- Filter chaining: Adding conditions to extract additional data
Think of it like asking a librarian for "books by Smith" but sneakily changing your request mid-sentence to "books by anyone" by exploiting how the request form is processed.
Key Takeaway: LDAP injection exploits occur when user input is concatenated directly into LDAP filter strings without proper sanitization, allowing attackers to manipulate query logic using special characters like *, (, ), and |.