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

# LDAP 搜索

### 测试匿名 LDAP 访问

{% code overflow="wrap" %}

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

{% endcode %}

此命令尝试在未进行身份验证的情况下查询 LDAP。

在许多现代环境中，匿名访问受到限制或已禁用。

### 使用凭据连接 LDAP

{% code overflow="wrap" %}

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

{% endcode %}

说明：

| 选项   | 作用         |
| ---- | ---------- |
| `-x` | 简单身份验证     |
| `-H` | LDAP 服务器地址 |
| `-D` | 用于登录的身份标识  |
| `-w` | 密码         |
| `-b` | 搜索 DN 数据库  |

<figure><img src="/files/5aed28777d0301757835d75a6ecb95dd15d7f1f1" alt=""><figcaption></figcaption></figure>

### 列出位于 `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 %}

这里，我们在标准容器中查找 `Users`.

### 列出一个 OU

如果用户位于组织单元中，我们使用 `OU` 而不是 `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 %}

重要区别：

| 元素   | 含义           |
| ---- | ------------ |
| `CN` | 通用名称、容器或标准对象 |
| `OU` | 组织单元         |
| `DC` | 域组件          |

### 搜索特定用户

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

此命令直接指向 `user1` 对象。

<figure><img src="/files/7d6257ff72a2cedd3f17772b6fefcd10cce3600f" alt=""><figcaption></figcaption></figure>

### 列出计算机

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

请注意：在 Active Directory 中，标准容器通常称为 `CN=Computers`.

### 列出内置 Administrators 组

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

此命令指向内置的本地组 `Administrators` 在 `Builtin` 容器中。

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

### 查找用户的 DN

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

示例结果：

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

* 该 **DN**，或 **可分辨名称**，是对象完整的 LDAP 路径。


---

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