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

# استطلاع ldapsearch

> الـ **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="/files/239bb398774189bcb3d0b77ae37f73e92f6a1989" 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="/files/79cbb06c81f39ca67c80ee02161784f409586067" 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="/files/1b0c555babf0b67081ea36415a151cba423300a0" 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 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/ar/ports-and-services/ldap-389-636-3268-3269/ldapsearch-attack.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.
