> 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 搜索的 Active Directory 安全笔记，涵盖枚举、Kerberos、凭据、ACL 滥用、横向移动、利用流程和验证步骤。

### 测试匿名 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bd40b7a438e5eec9974aeea789e6d51159e7851f%2Fimage%20(3214).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-87dcb4c2eb100a4353cad9981e8c36cdd2e8bc2a%2Fimage%20(3215).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b9249ba2f57947b2b9ae0a30afb70f0b8fd11403%2Fimage%20(3216).png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/zh/active-directory/enumeration/ldapsearch.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
