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

# Pesquisa LDAP

### Testar acesso anônimo ao LDAP

{% code overflow="wrap" %}

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

{% endcode %}

Este comando tenta consultar o LDAP sem autenticação.

Em muitos ambientes modernos, o acesso anônimo é limitado ou desativado.

### Conexão LDAP com credenciais

{% code overflow="wrap" %}

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

{% endcode %}

Explicação:

| Opção | Função                            |
| ----- | --------------------------------- |
| `-x`  | Autenticação simples              |
| `-H`  | Endereço do servidor LDAP         |
| `-D`  | Identidade usada para fazer login |
| `-w`  | Senha                             |
| `-b`  | Pesquisar banco de dados DN       |

<figure><img src="/files/0b3268940485a466f363c50d2fd36609c09592af" alt=""><figcaption></figcaption></figure>

### Listar usuários em `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 %}

Aqui, estamos procurando no contêiner padrão `Users`.

### Listar uma UO

Se os usuários estiverem em uma unidade organizacional, usamos `OU` em vez 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 %}

Diferença importante:

| Elemento | Significado                             |
| -------- | --------------------------------------- |
| `CN`     | Common Name, contêiner ou objeto padrão |
| `OU`     | Unidade Organizacional                  |
| `DC`     | Componente de domínio                   |

### Procurar um usuário 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 aponta diretamente para o `user1` objeto.

<figure><img src="/files/231340a86c1c2d6f2c99d217ba272fa69e090a57" alt=""><figcaption></figcaption></figure>

### Listar computadores

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

Observe: no Active Directory, o contêiner padrão geralmente é chamado `CN=Computers`.

### Listar o grupo Administrators integrado

{% 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 aponta para o grupo local integrado `Administrators` no `Builtin` contêiner.

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

### Encontrar o DN de um usuário

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

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

* O **DN** , ou **Nome distinto**, é o caminho LDAP completo do 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/pt-br/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.
