Skip to content
Path traversal Write-up Advanced

CVE-2024-29511 – Abusing Ghostscript’s OCR device

Ghostscript's OCR device passes the OCRLanguage parameter to Tesseract without path traversal checks, allowing an attacker to load a crafted traineddata file from any path. This enables reading arbitrary files (via debug_file and user_patterns_file) and writing to arbitrary files, bypassing the -dSAFER sandbox.

Thomas Rinsma Follow

Published on codeanlabs.com

This is an overview of CVE-2024-29511. A vulnerability in Ghostscript ≤ 10.02.1, leading to an arbitrary file read/write (under certain conditions).

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

Impact

An attacker could read arbitrary files and write somewhat arbitrary content to any file, potentially leading to remote code execution in document conversion services.

What the attacker needed

Ghostscript with OCR device compiled in; Ability to supply a PostScript file

The fix

Update Ghostscript to v10.03.0 or later, or apply a backported patch.

How it was found

  1. Create a PostScript file that writes a crafted traineddata bundle to /tmp/foo.traineddata.
  2. Set the OCR device's OCRLanguage parameter to a path traversal pointing to that file.
  3. Trigger the OCR device via setpagedevice, causing Tesseract to load the bundle.
  4. The bundle's config sets debug_file to /tmp/out and user_patterns_file to /etc/passwd.
  5. Tesseract writes error messages containing /etc/passwd lines to /tmp/out.
  6. Read /tmp/out from PostScript and print the leaked data.

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 interprets PostScript and PDF files. It has a security sandbox called -dSAFER that should stop a document from reading or writing files outside a safe list. This bug lets a malicious document trick Ghostscript's OCR feature into loading a file from anywhere on the system, which can then be used to read or write other files.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

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.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.