Upload2Shell: how a Ghostscript font bug turns upload boxes and printers into RCE

Upload2Shell: how a Ghostscript font bug turns upload boxes and printers into RCE

Someone sends a print job to a shared printer on a Debian 13 box. Nobody logs in, nobody clicks anything, and a command runs on the print server as the lp user. Swap the printer for a Roundcube inbox or a WordPress contact form with a file field and you get the same result as www-data. That is the core of Upload2Shell, the research Paulos Yibelo of pwn.ai published on November 21, 2026.

The bug itself, CVE-2026-125396, is a use-after-free in Ghostscript’s Type 1 font loader that lets a crafted document switch off the -dSAFER sandbox. The interesting part is not the memory bug. It is how many applications quietly hand an uploaded “JPG” or “PDF” to Ghostscript without anyone deciding they should. I rate this high: a public proof of concept exists, the fix (Ghostscript 10.08.0) has been out since September 8, 2026, and as of November 23 nobody has reported exploitation in the wild.

At a glance

  • CVE: CVE-2026-125396 (Ghostscript), plus CVE-2026-65640 for the WordPress core upload path.
  • CVSS: 8.5 under CVSS 4.0 and 7.8 under CVSS 3.1 in the CVE record (CNA VulnCheck), both with a local attack vector. WordPress scored its own fix 8.8. I could not retrieve an NVD assessment.
  • Affected: upstream Ghostscript before 10.08.0, including copies bundled into containers and application bundles.
  • Exploitation: public PoC from pwn.ai, replicated by iTnews. No in-the-wild exploitation reported as of November 23, 2026.
  • Fix: Ghostscript 10.08.0 or your distribution’s backport; WordPress 7.0.4, 6.9.7 and older-branch releases for CVE-2026-65640.
  • Who should care: anyone running a service that thumbnails, previews, converts or prints files from untrusted people. That is more of you than it sounds.

What we know

The CVE record, published November 9, 2026 by VulnCheck, describes the flaw plainly: a font helper called .putgstringcopy in gs_fonts.ps calls the privileged .forceput operator without checking what it was handed. A crafted PostScript or PDF file can trigger a type error, grab .forceput back through its own error handler, and cause a use-after-free across save/restore that leads to code execution. Ken Sharp is credited with the fix, which landed in Ghostscript 10.08.0 on September 8, 2026.

The disclosure history is messier than usual. WordPress shipped its mitigation on August 12, 2026, nearly a month before the Ghostscript release. Debian fixed trixie on September 25 (DSA-6516-1), and Ubuntu’s USN-8949-1 on October 21 covered a “font operand validation” issue with no CVE attached. According to iTnews, pwn.ai only requested a CVE on November 6, almost two months after the fix shipped. On oss-security, Jan Schaumann argued the bug should be treated as public from September 8 and said the coordination “leaves much to be desired.” I agree with him.

One date needs clearing up. CyberSecurityNews wrote that the research came out on November 17. The pwn.ai page itself, its timeline and iTnews all point to November 21, when Yibelo announced on X that the exploit would be released. I’m going with November 21.

Timeline of six dates: WordPress fix August 12, Ghostscript 10.08.0 September 8, Debian DSA September 25, Ubuntu USN October 21, CVE published November 9, and the pwn.ai write-up on November 21, 2026 with the PoC released that weekend
The fix shipped in September; the CVE arrived in November. Dates from pwn.ai, the CVE record and iTnews.

How it works

Ghostscript is a PostScript interpreter, and PostScript is a full programming language. -dSAFER is the sandbox that stops a document from opening files or running commands. Internally, Ghostscript’s own startup code still needs to do privileged things, so it has operators like .forceput that ignore access protections. The whole security model rests on those operators never being reachable from document code.

Per pwn.ai, the font helper needed that privileged store. If its copy step fails, a document’s error handler can catch the error and recover the operator. With it, the attacker gets a global object to keep a pointer into local memory, which a later restore frees. That dangling reference becomes native memory control, and from there the researchers changed the renderer’s sandbox state in memory, effectively switching -dSAFER off. I’m not going further than that; the mechanism is enough to understand the fix.

If this sounds familiar, it should. CVE-2018-16509 (Ghostscript before 9.24) abused failed restore handling to run commands. CVE-2019-14811 (before 9.50) was a privileged call left unprotected in .pdf_hook_DSC_Creator. iTnews notes that Tavis Ormandy found a related bug in the same font file in 2018. This is the same bug class coming back: privileged PostScript procedures that leak to user code via error handling. According to iTnews, Artifex is trying to remove the privileged internal operation that enables this class, which is the right answer.

The delivery chain is the real story

Ghostscript doesn’t listen on a port, which is why the CVE says “local.” The remote part comes from libraries that pick a decoder by file content, not file name. ImageMagick and Pillow both look at the magic bytes, so a file called invoice.jpg that actually contains PostScript gets routed to Ghostscript. Patchstack’s write-up of the WordPress fix shows exactly this: WP_Image_Editor_Imagick::load() trusted the extension, ImageMagick trusted the content, and a “.png” full of PostScript reached the interpreter.

Four-step chain: disguised PostScript file arrives, ImageMagick or Pillow route it to Ghostscript by content (print jobs via the gstopdf filter), font loader use-after-free disables -dSAFER, command runs as www-data or lp
How an ordinary upload, email or print job reaches Ghostscript. Based on the pwn.ai write-up and Patchstack.

The pwn.ai write-up lists the paths it confirmed:

  • CUPS on Debian 13: an unauthenticated IPP Print-Job to a shared network queue reached Ghostscript through the gstopdf filter, running as uid=7(lp).
  • Roundcube (1.7.2 per CyberSecurityNews): viewing an email with a disguised attachment triggered an ImageMagick thumbnail. The sender needed no account. This one depended on a permissive ImageMagick delegate policy.
  • WordPress core: Author-level users with upload_files. Forminator and Essential Addons for Elementor exposed the same path to signed-out visitors through public upload fields in the tested configurations.
  • MediaWiki with PdfHandler and anonymous uploads, DokuWiki with ImageMagick, Mayan EDMS email import, ResourceSpace, Plesk’s Roundcube and Paperless-ngx, which calls Ghostscript directly for PDF/A conversion.
  • Libraries that reached Ghostscript: Pillow’s EPS decoder, ImageMagick’s PostScript delegate, libvips via magickload, Qt KImageFormats and Matplotlib’s EPS path. PHP GD, OpenCV, Sharp, Jimp, Java ImageIO and Go’s decoders did not in their tests.

pwn.ai also named Google (closed November 10) and Dropbox, but says those were separate findings with different root causes, so don’t count them as CVE-2026-125396 victims.

Who is affected and how badly

The CVSS vector understates network exposure and overstates the blast radius at the same time. Understates, because “local” here means “any file that reaches the renderer,” and plenty of renderers sit behind anonymous upload fields. Overstates, because code runs as the service account (www-data, lp), not root, and many paths need a specific config: a shared CUPS queue, a permissive ImageMagick policy, a plugin with a public upload field.

The part that worries me is patch visibility. Distros backport without bumping the version: Debian 13’s fixed build is still 10.05.1 (10.05.1~dfsg-1+deb13u2). As of pwn.ai’s November 12 snapshot, Debian 12, Amazon Linux 2/2023, SUSE Linux Enterprise and openSUSE Leap 16.x were still open, and RHEL-family status was not established. Debian’s tracker now lists a bookworm fix in 10.0.0~dfsg-11+deb12u9 via DLA-4914-1, so check again before you decide. And none of that helps the old Ghostscript baked into a container image built in August. As CyberSecurityNews put it, “Updating the host does not replace Ghostscript inside an existing container or application bundle.”

What to do now

  1. Find every Ghostscript, not just the system package. Check dpkg -l 'ghostscript*' 'libgs*' or rpm -q ghostscript on hosts, then scan container images and app bundles with your SBOM tool for gs binaries and libgs.so. Compare against the distro advisory, not the upstream version string.
  2. Patch to Ghostscript 10.08.0 or the backport: Debian trixie 10.05.1~dfsg-1+deb13u2 or later, Ubuntu per USN-8949-1 (for example 10.02.1~dfsg1-0ubuntu7.10 on 24.04 and 9.55.0~dfsg1-0ubuntu5.15 on 22.04). Rebuild images; don’t just patch the host.
  3. Update WordPress to 7.0.4 or the branch fix (6.9.7 and backports to every branch down to 4.7.35). Then audit plugins with public upload fields that feed the Media Library.
  4. Require authentication on shared CUPS queues and restrict who can reach port 631. An anonymous print queue on a routable network is an anonymous code execution queue today.
  5. Turn off PostScript in image pipelines that never need it. In ImageMagick’s policy.xml, deny the PostScript-family coders and the gs delegate (example below). The pwn.ai write-up doesn’t name policy.xml; this is my own standard hardening. In Pillow, pass an explicit allow-list via Image.open(fp, formats=[...]) so EPS is never tried.
  6. Check real file types before generating previews, and if patching has to wait, disable automatic previews of untrusted files. Run renderers in a sandbox (seccomp, AppArmor, a separate container with no egress) so a compromised interpreter cannot start a shell, which is what pwn.ai recommends.
<!-- ImageMagick policy.xml: block PostScript-family input -->
<policy domain="coder" rights="none" pattern="{PS,PS2,PS3,EPS,EPSI,EPSF,PDF,XPS}" />
<policy domain="delegate" rights="none" pattern="gs" />

Drop PDF from that list only if you really need PDF thumbnails, and then patch first. Verify with magick -list policy (or convert -list policy on ImageMagick 6), since distros ship their policy files in different places.

Detection and monitoring

No IOCs have been published, and pwn.ai offers no signatures. Its only artefacts are what its own proofs left behind: a marker file under /var/tmp on the print server and a PHP file on the WordPress test (no path given). So this is behaviour detection, best done on the host, where Ghostscript starts doing things a renderer never does. That needs process telemetry (Sysmon for Linux, auditd execve or an EDR), usually off by default on web and print servers. A network sensor that sees uploads in cleartext can flag delivery too.

RuleCategoryLog sourceATT&CKLevel
Ghostscript spawning shell, interpreter or download toolLinux, generic TTPprocess_creationT1059.004, T1190High
Image converter, PHP or CUPS filter spawning suspicious child as service accountLinux, generic TTPprocess_creationT1059.004, T1105Medium
Outbound network connection initiated by GhostscriptLinux, generic TTPnetwork_connectionT1105High
Ghostscript or service account writing to temp directoriesLinux, huntingfile_eventT1105Low
PostScript upload disguised as an image or PDFNetwork, emerging threatZeek httpT1190, T1036.008Medium

The rule I’d turn on first is the simplest: alert when gs, gsc or ghostscript starts a shell, a script interpreter or a download tool. Callers starting gs is routine (ImageMagick runs it as a delegate command line); gs starting a shell is not. The one legitimate exception I know of is a print setup that puts a %pipe% output on the gs command line, which the optional filter covers. Splunk’s ESCU “Linux Ghostscript Exploitation” analytic uses the same idea.

title: Ghostscript Spawning Shell, Interpreter or Download Tool - Potential -dSAFER Escape
id: 9a8d85d9-4f81-45f2-906b-1bf101ade773
status: experimental
description: |
    Detects a Ghostscript process (gs, gsc, ghostscript) starting a shell, script interpreter or network/download tool.
    A -dSAFER escape such as CVE-2026-125396 (Upload2Shell) ends with the interpreter running commands as the service
    account that called it (www-data, lp). Direction matters: callers starting gs is normal (ImageMagick runs it as a delegate command line), gs starting a shell is not.
references:
    - https://pwn.ai/upload2shell/research.html
    - https://www.cve.org/CVERecord?id=CVE-2026-125396
    - https://research.splunk.com/endpoint/580f99d8-a4c8-4ef1-9c84-f355867bca41/
    - https://github.com/ImageMagick/ImageMagick/blob/main/config/delegates.xml.in
    - https://netsec101.com/?p=476
author: netsec101.com
date: 2026-11-23
tags:
    - attack.execution
    - attack.t1059.004
    - attack.initial-access
    - attack.t1190
    - cve.2026-125396
logsource:
    product: linux
    category: process_creation
detection:
    selection_parent:
        ParentImage|endswith:
            - '/gs'
            - '/gsc'
            - '/ghostscript'
    selection_child_name:
        Image|endswith:
            - '/sh'
            - '/bash'
            - '/dash'
            - '/zsh'
            - '/ksh'
            - '/busybox'
            - '/perl'
            - '/ruby'
            - '/php'
            - '/curl'
            - '/wget'
            - '/nc'
            - '/ncat'
            - '/netcat'
            - '/socat'
            - '/telnet'
            - '/openssl'
    selection_child_python:
        Image|re: '/python[0-9.]*$'
    filter_optional_pipe_output:
        # Print setups that put an output pipe on the gs command line itself (for example -sOutputFile=%pipe%lpr)
        ParentCommandLine|contains:
            - '-sOutputFile=%pipe%'
            - '-sOutputFile=|'
    condition: selection_parent and 1 of selection_child_* and not 1 of filter_optional_*
falsepositives:
    - Print or conversion setups that pipe Ghostscript output to another command (the %pipe% device runs it through sh); keep the optional filter only where the pipe is on the gs command line, not in the document
    - Desktop or batch workflows that script Ghostscript with %pipe% output
level: high

After you patch, keep these rules running. The next -dSAFER escape will produce the same process tree, and old Ghostscript copies inside container images will outlive the host patches. Retro-hunt your process data back to at least September 8, 2026, when the fix and its diff became public. With no IOCs, there is nothing to age out; the PoC marker file only flags someone’s lab test.

I wrote up all five rules, with tuning notes, lab tests and ATT&CK coverage, in a separate detection post. The YAML lives in my Detection Rules repo, under Linux and Network.

My take

I think the memory bug is the least interesting thing here. Ghostscript -dSAFER escapes are a recurring genre, and this one follows the same pattern as 2018 and 2019. What Upload2Shell shows well is that “we validate uploads” usually means “we check the extension and MIME type,” and then the file goes to a library that ignores both. Yibelo told iTnews that “Almost every application we tested with file uploads could be tricked” into that hand-off. I believe it, and it means your upload-security review needs to follow the file past storage into every thumbnailer, indexer and converter.

I’m also unhappy with the disclosure. A fix in September, a CVE in November, a teaser in between and a PoC that landed alongside the press coverage gives attackers a clean diff and defenders no CVE to scan for during the window that mattered. Scanners keyed on CVE IDs couldn’t flag this until November 9.

What I’d do first: inventory Ghostscript inside containers, lock down any anonymous CUPS queue, and push the policy.xml change everywhere ImageMagick runs, patched or not. The next .forceput bug is probably already sitting in someone’s fuzzing corpus, and that policy line keeps working when it shows up.

Sources

One thought on “Upload2Shell: how a Ghostscript font bug turns upload boxes and printers into RCE”

Leave a Reply