Back to Intelligence

Ghostscript Sandbox Escape via Crafted File Uploads: Detection and Hardening Guide for Linux Servers

SA
Security Arsenal Team
November 22, 2026
12 min read

Security firm pwn.ai this week demonstrated a now-patched sandbox-escape vulnerability in Ghostscript, the open-source interpreter that quietly sits behind an enormous percentage of Linux-based file-processing pipelines. The flaw allows a crafted document to break out of Ghostscript's -dSAFER sandbox and execute arbitrary operating system commands on the server that processes it — a classic and dangerous pattern that has historically led to remote code execution through nothing more exotic than an ordinary file upload.

The reason this matters to defenders is the attack surface, not the exploit mechanics. Ghostscript is almost never invoked directly by an application developer. It is reached transitively — ImageMagick delegates PDF and PostScript handling to it, ghostscript is called by print queues (CUPS), by OCR pipelines, by thumbnail generators, by document preview features in popular web applications, and by countless CI/CD document-conversion jobs. That means a vulnerable Ghostscript interpreter is reachable through any application that accepts a PDF, PostScript, EPS, or image file from an untrusted user — which is to say, most web applications, ticketing systems, document management platforms, and e-commerce backends in production today.

If your environment processes user-supplied documents on a Linux host anywhere in the stack, treat this as an immediate patch-and-verify exercise, not a routine update. The proof-of-concept is public, the research is circulating, and this class of bug has been weaponized within days of disclosure in prior cycles.

Technical Analysis

Affected component and attack surface

The vulnerable component is the Ghostscript interpreter (gs) on Linux systems. The critical detail for scoping is the set of callers that reach it:

  • ImageMagick (convert, magick, identify, mogrify) — delegates PDF, PS, and EPS decoding to Ghostscript via its delegates configuration (delegates.xml). Any application using ImageMagick to thumbnail or convert uploads is exposed.
  • CUPS print infrastructure — cups-filters invokes Ghostscript for PostScript/PDF rendering on many distributions.
  • Direct invocations — applications, scripts, and job workers that shell out to gs for PDF→image or PDF→PDF conversion.
  • Framework-level integrations — document preview, OCR, and PDF manipulation libraries in PHP, Python, Ruby, and Node ecosystems frequently wrap one of the two paths above.

Platforms of concern are any Linux server running a vulnerable Ghostscript build with a file-processing path reachable by untrusted input. Containerized workloads are not automatically safe — an interpreter escape inside a container still yields code execution in that container's context, and container escape is a separate, often-trivial problem if the container is privileged or shares host mounts.

How the exploitation chain works (defender's view)

The pwn.ai research demonstrates a pattern familiar to anyone who has tracked Ghostscript's long history of sandbox escapes: Ghostscript's -dSAFER mode is designed to prevent PostScript programs from accessing the filesystem and executing commands, but the sandbox is enforced in the interpreter itself — so a flaw in the interpreter's own logic can disable it. From a defensive perspective, the observable attack chain is:

  1. Delivery — attacker uploads a crafted PDF/PostScript/EPS file through a legitimate application feature (avatar upload with PDF conversion, document attachment, invoice upload, print job submission).
  2. Invocation — the application (or a library like ImageMagick) invokes gs against the attacker-controlled file. This is visible as a web-server or worker process spawning gs or convert.
  3. Sandbox escape — the malicious document triggers the flaw, regaining access to dangerous PostScript operators. The sandbox bypass is invisible at the OS level; the interpreter simply begins doing things -dSAFER was supposed to forbid.
  4. Execution — Ghostscript's %pipe% device (or equivalent operator abuse) is used to run arbitrary shell commands with the privileges of the service account (commonly www-data, apache, nginx, or a worker user). At the OS level, this is observable as gs spawning sh, bash, curl, wget, python, or writing executables to /tmp or /dev/shm.
  5. Post-exploitation — reverse shells, credential theft from environment variables and config files, lateral movement from what is typically an internet-facing application tier.

Key defensive insight: you cannot reliably detect step 3 — the escape happens inside interpreter logic. You can reliably detect step 4: Ghostscript spawning child processes or establishing network connections is virtually never legitimate in a document-conversion pipeline. That is your highest-fidelity detection anchor.

Exploitation status

  • A working proof-of-concept was publicly demonstrated by pwn.ai alongside the disclosure.
  • The vulnerability is patched — updated Ghostscript packages are available through distribution channels (see Remediation).
  • At the time of writing there is no confirmed in-the-wild mass exploitation and no CISA KEV listing, but public PoC plus an enormous transitive attack surface is precisely the profile that moves to active scanning and exploitation quickly. Do not wait for a KEV entry to act.

Detection & Response

Sigma Rules

The following rules target the highest-fidelity behaviors: Ghostscript spawning an interpreter or shell, and a web-server/worker process invoking Ghostscript or ImageMagick in the first place (useful for scoping exposure and catching reconnaissance of the upload path). The third rule catches command-line configurations that disable or weaken the sandbox — worth hunting even post-patch, since -dNOSAFER in any invocation is a hard red flag.

YAML
---
title: Ghostscript Spawning Shell or Script Interpreter
id: 3f8c1a2e-6b47-4d92-9e51-7a2c4f8b1d3e
status: experimental
description: Detects the Ghostscript interpreter spawning a shell, script interpreter, or common post-exploitation tool. Ghostscript performing document conversion should never create child processes; this is a high-fidelity indicator of sandbox-escape exploitation via a crafted PDF/PS/EPS file.
references:
  - https://thehackernews.com/2026/11/researchers-demonstrate-ghostscript.html
  - https://attack.mitre.org/techniques/T1203/
  - https://attack.mitre.org/techniques/T1059/
author: Security Arsenal
date: 2026/11/18
tags:
  - attack.execution
  - attack.exploitation_for_client_execution
  - attack.t1203
  - attack.t1059.004
logsource:
  category: process_creation
  product: linux
detection:
  selection_parent:
    ParentImage|endswith:
      - '/gs'
      - '/ghostscript'
  selection_child:
    Image|endswith:
      - '/sh'
      - '/bash'
      - '/dash'
      - '/zsh'
      - '/python'
      - '/python3'
      - '/perl'
      - '/php'
      - '/curl'
      - '/wget'
      - '/nc'
      - '/ncat'
      - '/base64'
      - '/chmod'
      - '/id'
  condition: selection_parent and selection_child
falsepositives:
  - Extremely rare; legitimate Ghostscript document conversion does not spawn shells. Investigate any hit as a probable intrusion.
level: critical
---
title: Web Server or Application Worker Spawning Ghostscript or ImageMagick
id: 8b2e5d41-1f6a-4c83-b7d9-2e4a6c8f0b15
status: experimental
description: Detects web server, PHP-FPM, or application worker processes invoking Ghostscript or ImageMagick binaries. Establishes which hosts expose Ghostscript to user-controlled uploads and highlights exploitation attempts reaching the interpreter. Use primarily for exposure scoping and hunt pivoting.
references:
  - https://thehackernews.com/2026/11/researchers-demonstrate-ghostscript.html
  - https://attack.mitre.org/techniques/T1190/
author: Security Arsenal
date: 2026/11/18
tags:
  - attack.initial_access
  - attack.t1190
logsource:
  category: process_creation
  product: linux
detection:
  selection_parent:
    ParentImage|endswith:
      - '/apache2'
      - '/httpd'
      - '/nginx'
      - '/php-fpm'
      - '/php'
      - '/gunicorn'
      - '/uwsgi'
      - '/node'
      - '/java'
  selection_child:
    Image|endswith:
      - '/gs'
      - '/convert'
      - '/magick'
      - '/identify'
      - '/mogrify'
  condition: selection_parent and selection_child
falsepositives:
  - Legitimate document conversion features (thumbnailing, PDF preview, OCR). Tune to known-good application paths, then alert on deviations and on any invocation coinciding with the Ghostscript child-process rule.
level: medium
---
title: Ghostscript Invoked With Sandbox Disabled or Dangerous Flags
id: 5c1d9a07-3e82-4b64-a1f8-9d3b7e5c2a46
status: experimental
description: Detects Ghostscript invocations that disable the SAFER sandbox, permit arbitrary file access, or reference pipe execution in embedded documents. Any occurrence of -dNOSAFER or -dDELAYSAFER in production is a strong indicator of malicious configuration or attempted exploitation support.
references:
  - https://thehackernews.com/2026/11/researchers-demonstrate-ghostscript.html
  - https://attack.mitre.org/techniques/T1059/
author: Security Arsenal
date: 2026/11/18
tags:
  - attack.defense_evasion
  - attack.execution
  - attack.t1059
logsource:
  category: process_creation
  product: linux
detection:
  selection_img:
    Image|endswith: '/gs'
  selection_flags:
    CommandLine|contains:
      - '-dNOSAFER'
      - '--permit-file-all'
      - '-dDELAYSAFER'
      - '%pipe%'
  condition: selection_img and selection_flags
falsepositives:
  - Legacy conversion scripts or misconfigured applications that explicitly disable the sandbox. These should be remediated, not whitelisted.
level: high

KQL — Microsoft Sentinel / Defender

This hunt query targets Linux endpoint telemetry ingested into Sentinel (via the Syslog/CEF connector or Defender for Endpoint on Linux). It hunts Ghostscript child processes first — the critical signal — then pivots to inventory which hosts have Ghostscript reachable from web-facing processes. Run it over at least 14 days to establish a baseline before any hits get dismissed as noise.

KQL — Microsoft Sentinel / Defender
// Hunt 1: Ghostscript spawning child processes (high-fidelity exploit signal)
DeviceProcessEvents
| where TimeGenerated > ago(14d)
| where InitiatingProcessFileName has_any ("gs", "ghostscript")
| where FileName in~ ("sh", "bash", "dash", "zsh", "python", "python3", "perl", "php", "curl", "wget", "nc", "ncat", "base64")
| project TimeGenerated, DeviceName, InitiatingProcessFileName, InitiatingProcessCommandLine,
          FileName, ProcessCommandLine, AccountName, InitiatingProcessAccountName, ReportId
| order by TimeGenerated desc;

// Hunt 2: Syslog-ingested Linux hosts — gs invocation with dangerous flags or %pipe% abuse
Syslog
| where TimeGenerated > ago(14d)
| where SyslogMessage has "gs" and SyslogMessage has_any ("-dNOSAFER", "--permit-file-all", "%pipe%", "-dDELAYSAFER")
| project TimeGenerated, Computer, ProcessName, SyslogMessage
| order by TimeGenerated desc;

// Hunt 3: Exposure inventory — web/worker processes reaching Ghostscript or ImageMagick
DeviceProcessEvents
| where TimeGenerated > ago(7d)
| where InitiatingProcessFileName has_any ("apache2", "httpd", "nginx", "php-fpm", "php", "gunicorn", "uwsgi", "node", "java")
| where FileName in~ ("gs", "convert", "magick", "identify", "mogrify")
| summarize InvocationCount = count(),
            DistinctUsers = dcount(AccountName),
            ExampleCmd = any(ProcessCommandLine)
         by DeviceName, FileName
| order by InvocationCount desc;

Velociraptor VQL

Use this artifact during triage of a host where Ghostscript exploitation is suspected, or as a fleet-wide sweep for live indicators. It enumerates Ghostscript/ImageMagick processes with their full lineage and flags outbound network connections from those processes — a strong post-exploitation indicator, since a document converter should never hold a socket.

VQL — Velociraptor
-- Hunt Ghostscript / ImageMagick processes, their children, and any network connections
LET procs = SELECT Pid, Ppid, Name, Exe, CommandLine, Username, CreateTime
  FROM pslist()
  WHERE Name =~ '(?i)^(gs|convert|magick|identify|mogrify)$'
     OR Exe =~ '(?i)(ghostscript|imagemagick)'

SELECT Pid,
       Ppid,
       Name,
       Exe,
       CommandLine,
       Username,
       CreateTime,
       netstat(Pid=Pid).Status AS NetStatus,
       netstat(Pid=Pid).Raddr AS RemoteAddr,
       netstat(Pid=Pid).Rport AS RemotePort
FROM procs

Remediation and Verification Script

The following Bash script checks the installed Ghostscript version, updates it via the system package manager, verifies that the SAFER sandbox is the enforced default, audits for dangerous delegate configurations, and optionally removes Ghostscript where it is not required. Test in staging before running against production conversion pipelines.

Bash / Shell
#!/bin/bash
# Ghostscript sandbox-escape remediation and verification — Security Arsenal
# Run as root on each Linux host that processes uploaded documents.
set -u

echo "=== [1/6] Installed Ghostscript version ==="
if command -v gs >/dev/null 2>&1; then
    gs --version
    dpkg -l ghostscript 2>/dev/null || rpm -q ghostscript 2>/dev/null
else
    echo "Ghostscript not installed."
fi

echo "=== [2/6] Applying vendor security update ==="
if command -v apt-get >/dev/null 2>&1; then
    apt-get update && apt-get install --only-upgrade -y ghostscript libgs10 2>/dev/null || \
    apt-get install --only-upgrade -y ghostscript
elif command -v dnf >/dev/null 2>&1; then
    dnf update -y ghostscript
elif command -v yum >/dev/null 2>&1; then
    yum update -y ghostscript
elif command -v zypper >/dev/null 2>&1; then
    zypper update -y ghostscript
fi

echo "=== [3/6] Post-update version verification ==="
gs --version 2>/dev/null || echo "gs not present"
echo "Confirm this build matches or exceeds your distro's patched release from the security advisory."

echo "=== [4/6] Auditing ImageMagick delegates for unsafe Ghostscript flags ==="
grep -rEi 'dNOSAFER|dDELAYSAFER|permit-file' /etc/ImageMagick* /usr/lib*/ImageMagick* /usr/local/etc/ImageMagick* 2>/dev/null || \
echo "No unsafe flags found in ImageMagick delegates."

echo "=== [5/6] Confirming ImageMagick PDF/PS policy restrictions (defense-in-depth) ==="
POLICY=$(find /etc /usr/local/etc -name 'policy.xml' -path '*ImageMagick*' 2>/dev/null | head -1)
if [ -n "$POLICY" ]; then
    grep -E 'pattern="(PDF|PS|EPS|XPS)"' "$POLICY" || \
    echo "WARNING: No PDF/PS/EPS restrictions in $POLICY — consider disabling these coders if not required."
else
    echo "No ImageMagick policy.xml found."
fi

echo "=== [6/6] Finding any lingering -dNOSAFER usage in scripts and configs ==="
grep -rEl -- 'dNOSAFER' /etc /opt /srv /home 2>/dev/null | head -20 || \
echo "No -dNOSAFER references found."

echo "Done. If Ghostscript is not required on this host, remove it: apt-get purge ghostscript / dnf remove ghostscript"

Remediation

1. Patch Ghostscript everywhere, immediately. Apply the patched Ghostscript packages from your distribution's security channel on every host that has the package installed — including application servers, worker nodes, containers, and build agents. Do not limit remediation to internet-facing hosts; the interpreter is invoked by internal pipelines (mail gateways, DLP, print servers) that process attacker-controlled content just as readily. Rebuild and redeploy container images — updating the base image tag is not sufficient if Ghostscript is pinned in a layer.

2. Inventory transitive exposure. Identify every application path that reaches Ghostscript: search for gs in ImageMagick's delegates.xml, enumerate package dependencies (apt rdepends ghostscript / dnf repoquery --whatrequires ghostscript), and use the KQL exposure hunt above to find which web-facing processes actually invoke it. This inventory is your real attack surface — many teams will discover Ghostscript on hosts whose owners did not know it existed.

3. Remove Ghostscript where it is not required. The cheapest interpreter to exploit is the one that is not installed. If a host uses ImageMagick only for JPEG/PNG work, Ghostscript is removable. Where ImageMagick must remain but PDF/PS handling is unnecessary, disable those coders via policy.xml (deny PDF, PS, EPS, XPS) — this severs the delegation path entirely and is a permanent hardening win regardless of patch state.

4. Enforce sandbox flags at the invocation layer. Where Ghostscript must stay, standardize invocations on explicit restrictive flags (-dSAFER -dBATCH -dNOPAUSE -dPARANOIDSAFER where the workload permits) and audit for any -dNOSAFER usage in scripts, configs, and application code — the grep in the script above covers this. Any application shipping with the sandbox disabled is an unpatched vulnerability by configuration.

5. Contain the blast radius. Document-conversion services should run as dedicated low-privilege service accounts with no network egress, on hosts or in containers with read-only root filesystems, no mounted secrets, and AppArmor/seccomp profiles that deny gs the ability to exec other binaries. If an escape yields a shell that cannot talk to anything and cannot persist, the incident becomes a logging event instead of a breach.

6. Deploy the detections above and hunt retroactively. Load the Sigma rules into your pipeline, run the KQL hunts across at least 14 days of telemetry, and sweep with the VQL artifact on any host that processed untrusted documents while unpatched. Prioritize any gs child-process or network-connection finding as a probable intrusion and escalate to IR.

Related Resources

Security Arsenal Penetration Testing Services AlertMonitor Platform Book a SOC Assessment vulnerability-management Intel Hub

Is your security operations ready?

Get a free SOC assessment or see how AlertMonitor cuts through alert noise with automated triage.