> 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/ports-and-services/ldap-389-636-3268-3269/ldapsearch-attack.md).

# Enumeración con ldapsearch

> El **ldapsearch** La herramienta te permite consultar un servidor LDAP para recuperar información sobre la estructura del dominio, usuarios, grupos y otros objetos almacenados en el directorio. Es especialmente útil para el reconocimiento en un entorno de Active Directory.

### **Obtención de contextos de denominación**

Este comando obtiene los **contextos de denominación** (raíces LDAP), que son los puntos de entrada para explorar la estructura del dominio:

```bash
ldapsearch -x -H ldap://<SERVER_IP> -s base namingcontexts
```

```bash
ldapsearch -x -H ldap://10.10.10.175 -s base namingcontexts
```

* `-x`: Usa autenticación simple (anónima).
* `-H ldap://10.10.10.175`: Especifica el protocolo LDAP y la dirección IP del servidor objetivo.
* `-s base`: Limita la búsqueda a la raíz del dominio.
* `namingcontexts`: Atributo solicitado para mostrar las raíces disponibles.

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

### **Análisis de la estructura del dominio**

Este comando explora la estructura LDAP para identificar usuarios, grupos u otros objetos:

```bash
ldapsearch -x -H ldap://<SERVER_IP> -b '<BASE_DN>'
```

```bash
ldapsearch -x -H ldap://10.10.10.175 -b 'DC=EGOTISTICAL-BANK,DC=LOCAL
```

* `-b 'DC=EGOTISTICAL-BANK,DC=LOCAL'`: Define la base de búsqueda (el punto de entrada LDAP).
* Este comando devuelve toda la información accesible con los permisos actuales.

### **Filtrado de usuarios**

Para extraer solo los usuarios del dominio, aplica un filtrado adicional con `grep` y `sed`:

```bash
ldapsearch -x -H ldap://<SERVER_IP> -b '<BASE_DN>' "(objectClass=user)" | grep "dn: CN=" | sed 's/dn: CN=//;s/,.*//'
```

```bash
ldapsearch -x -H ldap://10.10.10.175 -b 'DC=EGOTISTICAL-BANK,DC=LOCAL' | grep "dn: CN=" | sed 's/dn: CN=//;s/,DC=EGOTISTICAL-BANK,DC=LOCAL//'
```

* `grep "dn: CN="`: Filtra las líneas que contienen los nombres comunes (CN) de los usuarios.
* `sed`: Limpia los resultados para mostrar solo los nombres de usuario.

<div data-full-width="true"><figure><img src="/files/e17de5c262bc64ce1a96c51cb942d9c204919c75" alt=""><figcaption></figcaption></figure></div>

### **Búsqueda LDAP con autenticación**

Este comando usa una cuenta para autenticarse y consultar el servidor LDAP:

```bash
ldapsearch -x -H ldap://<SERVER_IP> -D '<DOMAIN>/<USER>' -w '<PASSWORD>' -b '<BASE_DN>'
```

```bash
ldapsearch -x -H ldap://10.10.11.174 -D 'support.htb/ldap' -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' -b "DC=<1_SUBDOMAIN>,DC=<TLD>"
```

* `-D 'support.htb/ldap'`: Especifica la cuenta de usuario para la autenticación.
* `-w 'password'`: Contraseña de la cuenta utilizada.
* Este comando devuelve todos los datos accesibles con esta cuenta.

### **Búsqueda de información específica (filtrado avanzado)**

Para buscar información específica, como una contraseña almacenada en un campo, aplica un filtro adicional:

```bash
ldapsearch -x -H ldap://<SERVER_IP> -D '<USER>@<DOMAIN>' -w '<PASSWORD>' -b '<BASE_DN>' | grep -i "<ATTRIBUTE>" -B <LINES_BEFORE>
```

```bash
ldapsearch -x -H ldap://10.10.11.174 -D 'ldap@support.htb' -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' -b "DC=support,DC=htb" | grep -i "info:" -B 20
```

* `grep -i "info:"`: Filtra las líneas que contienen el `atributo info` , por ejemplo una nota o una contraseña.
* `-B 20`: Muestra 20 líneas anteriores a cada resultado para dar contexto.

<figure><img src="/files/dba40edfba2ca99bc8336e367c3d3bbb6732bcd8" 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/ports-and-services/ldap-389-636-3268-3269/ldapsearch-attack.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.
