> 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/active-directory/enumeration/ldapsearch.md).

# Búsqueda LDAP

### Probar el acceso anónimo a LDAP

{% code overflow="wrap" %}

```bash
ldapsearch -x -H ldap://172.16.0.100 -b "DC=whoami,DC=local"
```

{% endcode %}

Este comando intenta consultar LDAP sin autenticación.

En muchos entornos modernos, el acceso anónimo está limitado o deshabilitado.

### Conexión LDAP con credenciales

{% code overflow="wrap" %}

```bash
ldapsearch -x -H ldap://172.16.0.100 -D 'WHOAMI\user1' -w 'password' -b "DC=whoami,DC=local"
```

{% endcode %}

Explicación:

| Opción | Rol                                     |
| ------ | --------------------------------------- |
| `-x`   | Autenticación simple                    |
| `-H`   | Dirección del servidor LDAP             |
| `-D`   | Identidad utilizada para iniciar sesión |
| `-w`   | Contraseña                              |
| `-b`   | Buscar en la base de datos DN           |

<figure><img src="/files/1151e139a7b3372c8f99fe8f3a9160e08eb66ff5" alt=""><figcaption></figcaption></figure>

### Enumerar usuarios en `CN=Users`

{% code overflow="wrap" %}

```bash
ldapsearch -x -H ldap://172.16.0.100 -D 'WHOAMI\user1' -w 'password' -b "CN=Users,DC=whoami,DC=local"
```

{% endcode %}

Aquí, estamos buscando en el contenedor estándar `Users`.

### Enumerar una OU

Si los usuarios están en una unidad organizativa, usamos `OU` en lugar de `CN`:

{% code overflow="wrap" %}

```bash
ldapsearch -x -H ldap://172.16.0.100 -D 'WHOAMI\user1' -w 'password' -b "OU=Users,DC=whoami,DC=local"
```

{% endcode %}

Diferencia importante:

| Elemento | Significado                                |
| -------- | ------------------------------------------ |
| `CN`     | Nombre común, contenedor u objeto estándar |
| `OU`     | Unidad organizativa                        |
| `DC`     | Componente de dominio                      |

### Buscar un usuario específico

{% code overflow="wrap" %}

```bash
ldapsearch -x -H ldap://172.16.0.100 -D 'WHOAMI\user1' -w 'password' -b "CN=user1,CN=Users,DC=whoami,DC=local"
```

{% endcode %}

Este comando apunta directamente al `user1` objeto.

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

### Enumerar equipos

{% code overflow="wrap" %}

```bash
ldapsearch -x -H ldap://172.16.0.100 -D 'WHOAMI\user1' -w 'password' -b "CN=computers,DC=whoami,DC=local"
```

{% endcode %}

Tenga en cuenta: en Active Directory, el contenedor estándar generalmente se llama `CN=Computers`.

### Enumerar el grupo integrado de Administradores

{% code overflow="wrap" %}

```bash
ldapsearch -x -H ldap://172.16.0.100 -D 'WHOAMI\user1' -w 'password' -b "CN=Administrators,CN=Builtin,DC=whoami,DC=local"
```

{% endcode %}

Este comando apunta al grupo local integrado `Administrators` en el `Builtin` contenedor.

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

### Encontrar el DN de un usuario

```bash
ldapsearch -x -H ldap://172.16.0.100 -D 'WHOAMI\user1' -w 'password' -b "CN=user1,CN=Users,DC=whoami,DC=local" | grep dn
```

Resultado de ejemplo:

```bash
CN=user1,CN=Users,DC=whoami,DC=local
```

* El **DN**o **Nombre distinguido**, es la ruta LDAP completa del objeto.


---

# 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/active-directory/enumeration/ldapsearch.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.
