LDAP Injection Lab: Log In as Admin by Breaking the Filter

✨ AI Summary
DirectoryBox authenticates against an LDAP directory, and it builds the search filter by gluing your username and password straight into it. LDAP filters have their own syntax — and once your input becomes part of that syntax, you can rewrite what the filter actually asks for.
Lab at a glance: Intermediate · 90 XP · about 15 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

LDAP injection is the same family as SQL injection, aimed at a directory service. When an app concatenates user input into an LDAP search filter, special filter characters let an attacker change the query's logic — for example turning a password check into a condition that is always true.

The lesson: directory filters are a query language too. Untrusted input must be escaped before it goes anywhere near the filter string.

How DirectoryBox checks your login

DirectoryBox builds a filter that means 'find the entry where the username matches and the password matches', concatenating both values in directly. Because your input lands inside the filter unescaped, filter metacharacters you send are interpreted as part of the query, not as literal text.

The attack approach

  • Notice the login builds an LDAP filter from your username and password.
  • Use LDAP filter syntax in the input so the password condition no longer has to be true.
  • Make the filter match the admin entry regardless of the password supplied.
  • Submit and land in the admin session.

Full walkthrough (spoiler)

If the filter still rejects you, the syntax is not closing the way you expect — open the steps.

Show the step-by-step solution
  1. In the username field, supply the admin account followed by LDAP filter syntax that makes the overall filter match on the username alone.
  2. Use a wildcard or an always-true condition in place of the password so that half of the filter is satisfied by anything.
  3. Submit. The filter now resolves to 'username is admin AND (anything)', so the admin entry matches without the real password.
  4. You are logged in as admin and the lab marks you solved.

Why it works

The server trusts your input to be plain text, but it is pasted into a structured filter. LDAP metacharacters such as parentheses, wildcards and the AND/OR operators then change the shape of the query. The password check is no longer a check — it is a condition you control.

Core principleNever concatenate user input into an LDAP filter. Escape it per RFC 4515, or use a parameterised directory API.

Where this happens in the real world

LDAP injection shows up in enterprise apps that authenticate against Active Directory or another directory service by building filters from form input. It is less common than SQL injection only because fewer apps talk LDAP directly, and it sits under Injection (A03) in the OWASP Top 10 (2021).

How to defend against it

  • Escape every user value that enters a filter using the RFC 4515 rules (the characters ()*\\/ and NUL).
  • Prefer a parameterised directory API that keeps data out of the filter syntax.
  • Bind with the user's credentials rather than string-matching a password inside a filter.
  • Validate input against an allowlist of expected characters where you can.
Mr Elite tip: If a login talks to a directory and your username with a stray parenthesis or asterisk changes the error or the result, the input is reaching an unescaped LDAP filter.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own approach before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is LDAP injection?
An attack on apps that build LDAP directory filters from untrusted input, letting an attacker inject filter syntax to change the query — for example to bypass authentication.
How is it like SQL injection?
Both come from concatenating user input into a query language. LDAP injection targets directory search filters instead of SQL, but the root cause and fix philosophy are the same.
How do I escape LDAP input?
Apply the RFC 4515 escaping rules to filter values (escape characters such as parentheses, asterisk and backslash), or use a directory API that parameterises the query.
Is binding safer than filter matching?
Yes. Authenticating by binding to the directory with the user's credentials avoids placing the password inside a filter string at all.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *