LDAP Injection Explained: The Bug That Bypasses Logins in Enterprise Apps
Every bug bounty hunter learns SQL injection. Far fewer learn its enterprise cousin: LDAP injection. It works the same way — untrusted input smuggled into a query — but the target is a directory server like Active Directory or OpenLDAP, and the prize is often a login bypass on an internal application. If you hunt in enterprise programs, this bug is worth knowing.
What LDAP Is
LDAP, the Lightweight Directory Access Protocol, is how organizations store their user directory: names, usernames, groups, email addresses and more. When you log in to a corporate app, the app often asks the LDAP server "does this user exist, and is this the right password?" using a search filter that looks like this:
(&(uid=alice)(userPassword=secret123))
That filter says: find an entry whose username is alice AND whose password is secret123. If the server returns a match, the app logs you in. The filter is built by pasting the user's input straight into the query string — and that is where the bug lives.
How the Attack Works
LDAP filters use a handful of special characters: * means "anything", ( and ) group conditions, & means AND, | means OR, and = separates attributes from values. If the app does not escape those characters in your input, you can rewrite the query.
Imagine the login filter is:
(&(uid=USERINPUT)(userPassword=PASSWORDINPUT))
An attacker enters * as the username and anything as the password. The filter becomes:
(&(uid=*)(userPassword=anything))
That asks for any user whose password is anything — which matches nobody. But a smarter input breaks the logic entirely. Enter admin)(& as the username and the filter becomes:
(&(uid=admin)(&)(userPassword=anything))
The parentheses are now unbalanced in the attacker's favour, and depending on how the app handles the result, the search may return the admin entry without ever checking the password properly. Other classic payloads use * as a wildcard to enumerate accounts — a* returns every user starting with "a" — or close the filter early and inject an OR condition that always matches.
The result ranges from information disclosure (listing users and their attributes) to full authentication bypass. In bug bounty programs, LDAP injection on a login form is usually rated high severity, because it targets the front door of an enterprise app.
Finding It in a Lab
Set up a deliberately vulnerable lab — never test a real company's directory. A local OpenLDAP container with a small test app is enough. Try these inputs in the username field and watch what the app returns:
*— a wildcard; if the app returns a user or a different error, the input is reaching the filter unescapedadmin*— tests whether wildcard matching works on a real account*)(uid=*))(|(uid=*— a classic filter-breaking payload; a changed response means the filter structure is under your control)(cn=*— another way to close the filter early and inject a new condition
The signal is not always a login. Sometimes it is a different error message, a longer response time, or an extra user in the output. In a CTF, the flag is usually a successful login as the admin user.
How to Prevent It
The fix is the same family as SQL injection, but LDAP-specific:
- Escape user input before it reaches the filter. LDAP has its own escaping rules:
*becomes\2a,(becomes\28,)becomes\29,\becomes\5c, and the null byte becomes\00. Every LDAP library provides an escaping function — use it on every value that comes from a user. Never build filters with string concatenation. - Use parameterized LDAP queries. Modern directory libraries let you pass values as parameters instead of pasting them into the filter string. This removes the injection entirely.
- Run the directory connection with least privilege. The account your app uses to talk to LDAP should be able to read only the attributes it needs, and nothing else. Even if an injection happens, there is less to steal.
- Validate input at the door. Usernames have a known shape — letters, numbers, dots, underscores. Reject anything else before it reaches the query.
Why Hunters Miss It
LDAP injection is less common than SQL injection, which is exactly why it pays. Developers who sanitize SQL often forget that the same app talks to a directory server too, and automated scanners are weaker at LDAP than at SQL. In enterprise bug bounty programs, the login form backed by Active Directory is one of the most rewarding places to look — if the program's scope covers it.
Remember the golden rule: only test systems you own or have written permission to test. Build your LDAP lab locally, practice the payloads there, and only ever test a live target inside a bug bounty program whose scope explicitly allows it.



Comments
Post a Comment