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

# Énumération avec ldapsearch

> Le **ldapsearch** L’outil vous permet d’interroger un serveur LDAP pour récupérer des informations sur la structure du domaine, les utilisateurs, les groupes et d’autres objets stockés dans l’annuaire. Il est particulièrement utile pour l’énumération dans un environnement Active Directory.

### **Récupération des contextes de nommage**

Cette commande obtient les **contextes de nommage** (racines LDAP), qui sont les points d’entrée pour explorer la structure du domaine :

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

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

* `-x` : Utilise une authentification simple (anonyme).
* `-H ldap://10.10.10.175` : Spécifie le protocole LDAP et l’adresse IP du serveur cible.
* `-s base` : Limite la recherche à la racine du domaine.
* `namingcontexts` : Attribut demandé pour afficher les racines disponibles.

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

### **Analyse de la structure du domaine**

Cette commande explore la structure LDAP afin d’identifier les utilisateurs, les groupes ou d’autres objets :

```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'` : Définit la base de recherche (le point d’entrée LDAP).
* Cette commande renvoie toutes les informations accessibles avec les droits actuels.

### **Filtrage des utilisateurs**

Pour extraire uniquement les utilisateurs du domaine, appliquez un filtrage supplémentaire avec `grep` et `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="` : Filtre les lignes contenant les noms distinctifs communs (CN) des utilisateurs.
* `sed` : Nettoie les résultats pour n’afficher que les noms d’utilisateur.

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

### **Recherche LDAP avec authentification**

Cette commande utilise un compte pour s’authentifier et interroger le serveur 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'` : Spécifie le compte utilisateur utilisé pour l’authentification.
* `-w 'password'` : Mot de passe du compte utilisé.
* Cette commande renvoie toutes les données accessibles avec ce compte.

### **Recherche d’informations spécifiques (filtrage avancé)**

Pour rechercher des informations spécifiques, comme un mot de passe stocké dans un champ, appliquez un filtre supplémentaire :

```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:"` : Filtre les lignes contenant l’ `info` attribut, par exemple une note ou un mot de passe.
* `-B 20` : Affiche 20 lignes avant chaque résultat pour contextualiser.

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