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

# LDAP 検索

LDAP 検索、Kerberos、資格情報、ACL の悪用、横展開、悪用のワークフロー、検証手順を扱う Active Directory セキュリティメモ。

### 匿名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`  | ログインに使用するID   |
| `-w`  | パスワード         |
| `-b`  | DNデータベースを検索する |

<figure><img src="https://2001299964-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 %}

ここでは、標準コンテナを参照しています `ユーザー`.

### 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://2001299964-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`.

### 組み込みの管理者グループを一覧表示する

{% 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://2001299964-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/ja/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.
