LDAP Admin Account Bypassed :)
The phpLDAPadmin login page was vulnerable to LDAP injection in the username (cn) field, allowing crafted input to bypass authentication. The author logged into the admin panel without valid credentials.
Published on medium.com
{{media:0}}
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This is a first-person account by Himanshu Pdy of finding an LDAP injection that let him log in to a phpLDAPadmin panel. The target is given only as xyz.com, with the affected host being the sub-domain ldap.xyz.com. The exposed product is phpLDAPadmin, reached at the path /phpldapadmin/htdocs/index.php. phpLDAPadmin is a web front end for browsing and administering an LDAP directory, and its login form is the feature under test: it takes a username and a password and binds to the directory with them.
The author frames the issue generally first: LDAP injection is an injection attack in which an attacker inserts malicious LDAP statements into the original LDAP query used by an application, so that malicious LDAP requests reach the LDAP server. The stated consequences are reading or updating sensitive information, and the stated cause is an application failing to properly sanitise untrusted data.
Setup
- Target:
xyz.com, scope described as limited. - Sub-domain found:
ldap.xyz.com. - Product: phpLDAPadmin, login page at
ldap.xyz.com/phpldapadmin/htdocs/index.php. - Tools:
dirsearchanddirbfor content discovery, plus a simple brute force attempt on the password. - No versions, accounts or credentials are given beyond the
cn=adminidentity visible in the login form.
The recon approach is credited to Behrouz Sadeghipour's method, and the author says a friend, Pratik Yadav, gave him ideas about exploiting the panel after admitting he had never exploited one himself.
Finding it
The sub-domain ldap.xyz.com initially served an ordinary Ubuntu Apache page. Directory brute forcing with dirsearch and dirb returned some 200 status paths, including robot.txt and an admin link, and an intense directory search eventually turned up the admin panel:
ldap.xyz.com/phpldapadmin/htdocs/index.php
On the login portal the username was already shown, so only a password had to be supplied. A simple brute force attempt produced nothing. Searching for related HackerOne reports found none, so the author read up on LDAP and tried command injection instead.
The login URL he worked against was:
ldap.xyz.com/phpldapadmin/htdocs/index.php?login=
The username field was the cn attribute, and he identified it as vulnerable to LDAP injection. The example he gives of the normal shape of the input is:
Username= cn=admin dc=ldap dc=xyz dc=com & userPassword=pass

The screenshot shows the login form with the cn value and the password field as described around it.
Exploitation
Step 1: A wildcard payload and an unexpected error
Following the OWASP testing guide page for LDAP injection (Testing_for_LDAP_Injection_(OTG-INPVAL-006)), he submitted this payload:
login=*)& Userpassword=*
The payload puts *) in the login field and * in the password field. Instead of a login, the application returned an unusual error:
you cannot perform updates while server is in read-only mode

The error is shown in the response captured in the screenshot. The author found the error interesting because it was not an authentication failure.
Step 2: A filter that matches and logs in
After more reading and applying, he concentrated on the cn field and added this command to it:
(&(uid=*)(uid=*))(|(uid=*)
With that in the cn field he was logged in to the LDAP admin panel.

The screenshot shows the result: the panel reached after the successful login.
The payload is a filter fragment. (&(uid=*)(uid=*)) is an AND of two always-true wildcard matches, and (|(uid=* opens an OR with another wildcard match.
Root cause
The login form takes the cn value from the request and places it into the LDAP query without sanitising it, so metacharacters such as *, (, ), & and | change the meaning of the filter. The same applies to the password field, as the Userpassword=* attempt shows. The application therefore authenticates on the result of an attacker-controlled filter rather than on a comparison against a stored credential. The read-only error in step 1 suggests the directory server was configured read-only.
Impact
With a filter that evaluates true, an attacker reaches the phpLDAPadmin interface without knowing the admin password. From there the panel gives administrative access to the directory, which the author describes in general terms as the ability to read or update sensitive information. The server reported read-only mode, so updates would be refused.
Fix
The report does not describe a fix being applied. The report does not describe a fix.
Variants to test
- Submit a lone
*in the username field of any LDAP-backed login and watch for a different error or a successful bind. A positive result is a response that is not an authentication failure, such as a directory or server error. - Submit
*)to close the filter early, as inlogin=*)& Userpassword=*. A positive result is a server-side error revealing query execution, as happened here with the read-only message. - Submit an unbalanced always-true fragment such as
(&(uid=*)(uid=*))(|(uid=*in the username field. A positive result is a successful login without valid credentials. - Try the same metacharacters in the password field, as in the
Userpassword=*attempt.
What happened, in plain words
A security researcher found a login page for a tool that manages a directory of users, and he managed to get in without knowing the password. He did it by typing special characters into the username box. Those characters changed the query the server sent to its directory, and he was logged in. The researcher then saw the admin panel.
The tool in question is phpLDAPadmin. LDAP is a way of storing and looking up information about people and things, a bit like a very structured phone book that many organisations use to keep track of staff accounts, groups and permissions. phpLDAPadmin is a web page that lets an administrator browse and edit that phone book. To use it you log in, and the login form is the part that was broken.
The author is Himanshu Pdy, writing his first blog post. He gives the target only as xyz.com, with the affected machine being the sub-domain ldap.xyz.com. No version numbers, accounts or credentials appear in the write-up beyond the cn=admin identity that was visible on the login form.
Before the story, he explains the general idea. LDAP injection is an injection attack in which an attacker inserts malicious LDAP statements into the original LDAP query used by an application, so that malicious LDAP requests reach the LDAP server. The stated consequences are reading or updating sensitive information, and the stated cause is an application failing to properly sanitise untrusted data.
A useful comparison: imagine a librarian who takes your written request, "books by author X", and staples it onto a standard form. If you write "books by author X, or actually every book in the building", the librarian staples that on too and hands you everything. The form was supposed to contain only a name, but nothing stopped you writing extra instructions. That is injection: your input is treated as part of the instruction rather than as plain data.
Setting the scene
- Target:
xyz.com, with a scope the author describes as limited. - Sub-domain found:
ldap.xyz.com. - Product: phpLDAPadmin, with its login page at
ldap.xyz.com/phpldapadmin/htdocs/index.php. - Tools:
dirsearchanddirbfor content discovery, plus a simple brute force attempt on the password. - No versions, accounts or credentials are given beyond the
cn=adminidentity visible in the login form.
He credits the recon approach to Behrouz Sadeghipour's method. He also says a friend, Pratik Yadav, gave him ideas about exploiting the panel after admitting he had never exploited one himself.
Two terms worth unpacking here. Recon, short for reconnaissance, means looking around a target to see what is there before trying anything clever: which machines exist, which pages respond, which software is running. Content discovery tools such as dirsearch and dirb automate part of that by trying a long list of common file and folder names against a web server and reporting which ones exist. Brute force means trying many passwords in sequence, hoping one works; it is slow, noisy and often blocked, which is exactly what happened here.
Finding the login page
The sub-domain ldap.xyz.com initially served an ordinary Ubuntu Apache page. Apache is a very common web server program, and a default page like that tells you a server is running but not much else. Directory brute forcing with dirsearch and dirb returned some 200 status paths, including robot.txt and an admin link. A 200 status is the web's way of saying "here is the page you asked for"; other numbers mean other things, such as 404 for "not found". robot.txt is a small file sites use to tell search engines which parts not to crawl, and it sometimes hints at interesting folders. An intense directory search eventually turned up the admin panel:
ldap.xyz.com/phpldapadmin/htdocs/index.php
Line by line: ldap.xyz.com is the machine, phpldapadmin is the folder holding the tool, htdocs is a common folder name meaning "web documents", and index.php is the page the server loads by default when you visit a folder. Putting them together gives the address of the login screen.
On the login portal the username was already shown, so only a password had to be supplied. A simple brute force attempt produced nothing. Searching for related HackerOne reports found none. HackerOne is a platform where companies publish bug reports and pay researchers for finding them; looking for a similar public report is a normal first move, because someone may already have described the same weakness. Finding none, he read up on LDAP and tried command injection instead.
The login URL he worked against was:
ldap.xyz.com/phpldapadmin/htdocs/index.php?login=
The ?login= part is a query string: everything after the question mark is data the browser sends to the page. Here the page expects a value for login, and whatever you put after the equals sign is handed to the application.
The username field was the cn attribute, and he identified it as vulnerable to LDAP injection. In LDAP, an attribute is a named field on a record, and cn stands for common name, the display name of an entry. The example he gives of the normal shape of the input is:
Username= cn=admin dc=ldap dc=xyz dc=com & userPassword=pass
Line by line: Username= is the form field label. cn=admin says the entry's common name is admin. dc=ldap dc=xyz dc=com gives the directory's location, where dc stands for domain component, so this reads as the ldap part of xyz.com. The & separates this from the next field, userPassword=pass, which is the password being checked. In other words, the form is describing which record to look up and what password to compare against it.

The screenshot shows the login form with the cn value and the password field as described around it.
Trying to break in
Step 1: A wildcard payload and an unexpected error
Following the OWASP testing guide page for LDAP injection (Testing_for_LDAP_Injection_(OTG-INPVAL-006)), he submitted this payload:
login=*)& Userpassword=*
Line by line: login=*) puts a closing parenthesis and a star into the username field. In LDAP filters, a star is a wildcard meaning "anything", and parentheses group parts of the filter. The payload puts a closing parenthesis and a star into the login field. & joins the next field, and Userpassword=* sets the password to a wildcard, meaning "any password at all". The idea is to make the server compare against "anything" instead of a real value.
OWASP is a well-known non-profit that publishes free guidance on web security, and the page referenced is its testing guide entry on LDAP injection. Reading a public guide before trying a technique is the normal way to learn it.
Instead of a login, the application returned an unusual error:
you cannot perform updates while server is in read-only mode

The error is shown in the response captured in the screenshot. It is interesting because it is not an authentication failure. A normal wrong password gives a message like "invalid credentials". The author found the error interesting because it was not an authentication failure. Read-only mode means the server is configured to refuse changes.
Step 2: A filter that matches and logs in
After more reading and applying, he concentrated on the cn field and added this command to it:
(&(uid=*)(uid=*))(|(uid=*)
With that in the cn field he was logged in to the LDAP admin panel.

The screenshot shows the result: the panel reached after the successful login.
The payload is a filter fragment. (&(uid=*)(uid=*)) is an AND of two always-true wildcard matches: & means both sides must be true, and uid=* matches any user identifier, so the pair is always true. Then (|(uid=* opens an OR with another wildcard match; | means either side may be true. A bind is LDAP's word for logging in: the client proves its identity to the directory.
Why it worked
The login form takes the cn value from the request and places it into the LDAP query without sanitising it, so metacharacters such as *, (, ), & and | change the meaning of the filter. Sanitising means cleaning input so that characters with special meaning are neutralised, for example by escaping them so they are treated as ordinary text. The same applies to the password field, as the Userpassword=* attempt shows. The application therefore authenticates on the result of an attacker-controlled filter rather than on a comparison against a stored credential. The read-only error in step 1 suggests the injected query was executed against a directory server configured read-only, which limited what the injection could change but did not prevent the authentication bypass.
What an attacker could do with it
With a filter that evaluates true, an attacker reaches the phpLDAPadmin interface without knowing the admin password. From there the panel gives administrative access to the directory, which the author describes in general terms as the ability to read or update sensitive information. The server reported read-only mode, so updates would be refused.
How to fix it
The report does not describe a fix being applied. The report does not describe a fix. Parameterised means the query is written with placeholders and the values are handed over separately, so they can never be read as instructions.
Things to try on your own
- Submit a lone
*in the username field of any LDAP-backed login and watch for a different error or a successful bind. A positive result is a response that is not an authentication failure, such as a directory or server error. - Submit
*)to close the filter early, as inlogin=*)& Userpassword=*. A positive result is a server-side error revealing query execution, as happened here with the read-only message. - Submit an unbalanced always-true fragment such as
(&(uid=*)(uid=*))(|(uid=*in the username field. A positive result is a successful login without valid credentials. - Try the same metacharacters in the password field, as in the
Userpassword=*attempt.
Glossary
- LDAP: a protocol and data model for storing and looking up directory information such as users, groups and permissions, often described as a structured phone book.
- LDAP injection: an injection attack in which an attacker inserts malicious LDAP statements into the original LDAP query used by an application, so that malicious LDAP requests reach the LDAP server.
- phpLDAPadmin: a web front end for browsing and administering an LDAP directory.
- Injection: a class of bug where user input is treated as part of an instruction rather than as plain data.
- Sanitise: to clean input so that characters with special meaning cannot change the meaning of a query.
- Escape: to mark a special character so it is treated as ordinary text.
- Recon: short for reconnaissance; looking around a target to learn what exists before attacking.
- Content discovery: using tools to try many common file and folder names against a web server to find hidden pages.
- dirsearch / dirb: tools that automate content discovery.
- Brute force: trying many passwords in sequence, hoping one works.
- HTTP status 200: the web's way of saying the requested page exists and was returned.
- robot.txt: a file sites use to tell search engines which parts not to crawl; it can hint at interesting folders.
- Query string: the part of a URL after the question mark, carrying data to the page.
- Attribute: a named field on an LDAP record, such as
cnoruid. - cn: common name, the display name of an LDAP entry.
- dc: domain component, part of the directory's location, as in
dc=xyz dc=com. - uid: user identifier, another LDAP attribute naming a user.
- Filter: the expression an LDAP query uses to select records, built from attributes, operators and values.
- Wildcard (
*): a character meaning "anything" in a filter. - AND (
&) / OR (|): filter operators requiring both sides, or either side, to be true. - Bind: LDAP's word for logging in; the client proves its identity to the directory.
- Read-only mode: a server setting that refuses changes to its data.
- OWASP: a non-profit that publishes free web security guidance, including testing guides.
- HackerOne: a platform where companies publish bug reports and pay researchers for finding them.
- Parameterised API: an interface where a query is written with placeholders and values are passed separately, so values cannot be read as instructions.
- Input validation: checking input against expected rules and rejecting anything that does not fit.