> 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/ports-and-services/ldap-389-636-3268-3269/ldapsearch-attack.md).

# ldapsearchによる列挙

ldapsearchを使ったLDAP列挙。名前付けコンテキスト、ドメインオブジェクト、ユーザー、グループ、機微な属性を対象。

> その **ldapsearch** このツールを使用すると、LDAPサーバーに問い合わせて、ドメイン構造、ユーザー、グループ、その他ディレクトリに保存されているオブジェクトに関する情報を取得できます。Active Directory環境での列挙に特に便利です。

### **名前付けコンテキストの取得**

このコマンドは **名前付けコンテキスト** (LDAPルート) を取得します。これはドメイン構造を探索するためのエントリポイントです:

```bash
ldapsearch -x -H ldap://<SERVER_IP> -s base namingcontexts
```

```bash
ldapsearch -x -H ldap://10.10.10.175 -s base namingcontexts
```

* `-x`：シンプル（匿名）認証を使用します。
* `-H ldap://10.10.10.175`：LDAPプロトコルと対象サーバーのIPアドレスを指定します。
* `-s base`：検索をドメインのルートに限定します。
* `namingcontexts`：利用可能なルートを表示するための属性を指定します。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7693fc0d7faa3efcfec825d3530ac90ba336e39d%2Fimage%20(1595).png?alt=media" alt=""><figcaption></figcaption></figure>

### **ドメイン構造の分析**

このコマンドはLDAP構造を探索し、ユーザー、グループ、その他のオブジェクトを特定します：

```bash
ldapsearch -x -H ldap://<SERVER_IP> -b '<BASE_DN>'
```

```bash
ldapsearch -x -H ldap://10.10.10.175 -b 'DC=EGOTISTICAL-BANK,DC=LOCAL
```

* `-b 'DC=EGOTISTICAL-BANK,DC=LOCAL'`：検索ベース（LDAPの起点）を定義します。
* このコマンドは、現在の権限でアクセス可能なすべての情報を返します。

### **ユーザーの絞り込み**

ドメインユーザーのみを抽出するには、 `grep` および `sed`:

```bash
ldapsearch -x -H ldap://<SERVER_IP> -b '<BASE_DN>' "(objectClass=user)" | grep "dn: CN=" | sed 's/dn: CN=//;s/,.*//'
```

```bash
ldapsearch -x -H ldap://10.10.10.175 -b 'DC=EGOTISTICAL-BANK,DC=LOCAL' | grep "dn: CN=" | sed 's/dn: CN=//;s/,DC=EGOTISTICAL-BANK,DC=LOCAL//'
```

* `grep "dn: CN="`：ユーザーの共通名（CN）を含む行をフィルタリングします。
* `sed`：結果を整理してユーザー名だけを表示します。

<div data-full-width="true"><figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fc5fbff793904922b072c824e04af25214a0ea04%2Fimage%20(1596).png?alt=media" alt=""><figcaption></figcaption></figure></div>

### **認証付きLDAP検索**

このコマンドはアカウントを使用して認証し、LDAPサーバーに問い合わせます：

```bash
ldapsearch -x -H ldap://<SERVER_IP> -D '<DOMAIN>/<USER>' -w '<PASSWORD>' -b '<BASE_DN>'
```

```bash
ldapsearch -x -H ldap://10.10.11.174 -D 'support.htb/ldap' -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' -b "DC=<1_SUBDOMAIN>,DC=<TLD>"
```

* `-D 'support.htb/ldap'`：認証に使用するユーザーアカウントを指定します。
* `-w 'password'`：使用するアカウントのパスワードです。
* このコマンドは、このアカウントでアクセス可能なすべてのデータを返します。

### **特定の情報の検索（詳細フィルタリング）**

フィールドに保存されたパスワードなどの特定の情報を検索するには、追加のフィルターを適用します：

```bash
ldapsearch -x -H ldap://<SERVER_IP> -D '<USER>@<DOMAIN>' -w '<PASSWORD>' -b '<BASE_DN>' | grep -i "<ATTRIBUTE>" -B <LINES_BEFORE>
```

```bash
ldapsearch -x -H ldap://10.10.11.174 -D 'ldap@support.htb' -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' -b "DC=support,DC=htb" | grep -i "info:" -B 20
```

* `grep -i "info:"`： `info` 属性を含む行をフィルタリングします。たとえば、メモやパスワードなどです。
* `-B 20`：各結果の前20行を表示して、文脈を補います。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-66d7b358420350e9c73aef45179ffd790a85cffc%2Fimage%20(1547).png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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/ports-and-services/ldap-389-636-3268-3269/ldapsearch-attack.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.
