A crafted PostScript program defeats the -dSAFER sandbox and runs an attacker-chosen shell command when Ghostscript renders it. The exploit chains a Type 5 shading out-of-bounds heap write with a procedure-stream use-after-free information leak. The leak defeats ASLR and locates Ghostscript's SAFER path-control state in memory; the write flips that state to inactive; then the program opens a %pipe% stream to run the command.
Generate the core PostScript exploit for a chosen command:
Render it with Ghostscript on a standard headless raster device:
Confirm the command ran inside the sandboxed process:
package_payloads.py wraps the same exploit in the container and extension formats used by Ghostscript front ends. Generate all of them at once:
or a single sink, for example the EPS that office suites and ImageMagick feed to Ghostscript:
The pdf , EPT/image-extension, and SVG bundle sinks are routing formats for ImageMagick/Ghostscript delegates. They are not honest PDF/JPEG/PNG/GIF image encodings.
Ghostscript with a standard raster device ( pbmraw , ppmraw , pnggray , ...). The shading decomposition that carries the write primitive is elided on nullpage / bbox / pdfwrite , so the PoC must be rendered to a raster device. The exploit targets system Ghostscript 10.02.1 on x86-64 Linux. The ABI/layout constants live in the layout dict in build_payload.py and can be edited to retarget another build.
The PoC tries to be environment-agnostic and contains no hardcoded offsets. This allows us to use the same test file across a fairly wide range of Ghostscript deployements, as seen in the following table:
The full story
This article is one source in a clustered incident — the cluster page carries the summary, timeline and every other outlet covering it.
