Skip to content
RCE Write-up Advanced

CVE-2024-29510 – Exploiting Ghostscript using format strings

A format string vulnerability in Ghostscript's uniprint device allows a Postscript file to read and write memory via crafted device parameters, bypassing the -dSAFER sandbox and leading to code execution. An attacker could exploit this by supplying a malicious document to any service that uses Ghostscript for conversion.

Thomas Rinsma Follow

Published on codeanlabs.com

This is a write-up for CVE-2024-29510, a format string vulnerability in Ghostscript ≤ 10.03.0 (but ≥ 9.50). We show how this can be exploited to bypass the -dSAFER sandbox and gain code execution.

Thomas Rinsma (@thomasrinsma), on codeanlabs.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the uniprint device uses user-controllable device parameters such as upYMoveCommand as a format string in gs_snprintf without validating format specifiers, allowing stack memory reads and writes.

Impact

An attacker could bypass the -dSAFER sandbox and achieve code execution on systems that process untrusted documents with Ghostscript, though the exploit requires a controlled pointer on the stack and may be limited by format string length constraints.

What the attacker needed

Ghostscript version 9.50 to 10.03.0; Ability to supply a Postscript file; Service uses Ghostscript for conversion

The fix

The vulnerability was fixed in Ghostscript 10.03.0 by updating to the latest version.

How it was found

  1. Create a Postscript file that calls setpagedevice to switch to the uniprint device with the Pcl output format.
  2. Set the upYMoveCommand parameter to a string containing format specifiers to read stack values.
  3. Render a page with showpage so the device writes output containing the leaked stack data.
  4. Read back the output file to observe leaked pointers and environment variables.
  5. Use %n or %hn in the format string to write to a controlled pointer on the stack, achieving arbitrary write.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Ghostscript is a program that converts documents like PDFs and Postscript files into other formats. A format string bug happens when a program treats user-supplied text as instructions for formatting output, letting an attacker read or write memory. Here, a malicious document could break out of Ghostscript's safety sandbox and run commands on the server.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by Thomas Rinsma

View all

2 more disclosed reports, best first.

More from Ghostscript

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.