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

# Recherche LDAP

### Tester l'accès LDAP anonyme

{% code overflow="wrap" %}

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

{% endcode %}

Cette commande tente d'interroger LDAP sans authentification.

Dans de nombreux environnements modernes, l'accès anonyme est limité ou désactivé.

### Connexion LDAP avec des identifiants

{% code overflow="wrap" %}

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

{% endcode %}

Explication :

| Option | Rôle                                |
| ------ | ----------------------------------- |
| `-x`   | Authentification simple             |
| `-H`   | Adresse du serveur LDAP             |
| `-D`   | Identité utilisée pour se connecter |
| `-w`   | Mot de passe                        |
| `-b`   | Base DN de recherche                |

<figure><img src="/files/3060bf8324277bb6b732831206b9808a579d2b3b" alt=""><figcaption></figcaption></figure>

### Lister les utilisateurs dans `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 %}

Ici, nous recherchons dans le conteneur standard `Utilisateurs`.

### Lister une OU

Si les utilisateurs se trouvent dans une unité organisationnelle, nous utilisons `OU` au lieu 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 %}

Différence importante :

| Élément | Signification                           |
| ------- | --------------------------------------- |
| `CN`    | Nom commun, conteneur ou objet standard |
| `OU`    | Unité organisationnelle                 |
| `DC`    | Composant de domaine                    |

### Rechercher un utilisateur spécifique

{% 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 %}

Cette commande cible directement l' `user1` objet.

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

### Lister les ordinateurs

{% 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 %}

Veuillez noter : dans Active Directory, le conteneur standard est généralement appelé `CN=Computers`.

### Lister le groupe Administrators intégré

{% 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 %}

Cette commande cible le groupe local intégré `Administrators` dans le `Builtin` conteneur.

<figure><img src="/files/69867bba2db065262b3dd6ca4d2effca06814064" alt=""><figcaption></figcaption></figure>

### Trouver le DN d'un utilisateur

```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
```

Résultat d'exemple :

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

* Le **DN**, ou **Nom distinctif**, est le chemin LDAP complet de l'objet.


---

# 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/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.
