Upload2shell Cve 2026 125396 Ghostscript

Upload2Shell CVE-2026-125396: Ghostscript Risk

Upload2Shell CVE-2026-125396: Ghostscript Risk

Introduction

Upload2Shell (CVE-2026-125396) is a high-severity vulnerability in Ghostscript that can allow command execution through specially crafted PostScript or PDF files. The vulnerability affects document-processing workflows that use Ghostscript to render or convert files.

Applications such as WordPress, webmail platforms and print services may indirectly invoke Ghostscript through image-processing libraries. If an attacker can submit a malicious file to a vulnerable processing workflow, the vulnerability may allow commands to execute with the privileges of the rendering process.

Key Takeaways at a Glance

• Vulnerability Details:CVE-2026-125396 (Upload2Shell) is a high-severity Use-After-Free (UAF) flaw in the Ghostscript Type 1 font loader, scoring CVSS v4.0 8.5 / CVSS v3.1 7.8.

• Indirect Attack Surface:Exploitation occurs indirectly via routine background processing (thumbnail generation, preview rendering, print spooling) in software that delegates PostScript parsing to Ghostscript.

• Sandbox Bypass:The flaw enables an attacker to break out of Ghostscript -dSAFER confinement sandbox, restoring privileged operators to spawn system commands.

• Privilege Context:Commands execute strictly within the security context of the rendering process (e.g. www-data, lp, or the container user), not automatic root.

• Primary Fix & Workaround:Upgrade to Ghostscript 10.08.0 (or patched distro packages like Debian 10.05.1~dfsg-1+deb13u2) and disable PostScript/EPS/PDF coders in the ImageMagick policy.xml.

Vulnerability Overview

The table below outlines the core technical attributes, severity ratings, and component information associated with the Upload2Shell vulnerability.

Vulnerability AttributeTechnical Details
Vulnerability Identifier CVE-2026-125396 (Upload2Shell)
Common Weakness Enumeration CWE-416: Use After Free | CWE-693: Protection Mechanism Failure
CVSS v4.0 Base Score 8.5 High (CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:L/SI:L/SA:L)
CVSS v3.1 Base Score 7.8 High (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)
Affected Software Artifex Ghostscript (and downstream embedded libraries)
Affected Upstream Versions Upstream Ghostscript releases prior to 10.08.0
Fixed Upstream Version Ghostscript 10.08.0
Vulnerable Engine Component Type 1 font loader subsystem (t1load.c / font dictionary parser)
Subverted Security Control -dSAFER execution sandbox (PostScript command restriction mechanism)

What Is Ghostscript?

Ghostscript is an open-source interpreter for the PostScript language and Portable Document Format (PDF). First released in 1988, it remains the standard back-end rasterizer across the Unix and Linux software ecosystem.

Unlike static bitmap image encoders, PostScript contains flow control, stack manipulation, arithmetic, memory allocation, and file operations. Whenever a server converts a PostScript or PDF document into a PNG thumbnail, Ghostscript executes the document as code.

To prevent arbitrary code execution, Ghostscript relies on its -dSAFER security mode. In SAFER mode, operators that perform file writes, delete files, read unauthorized paths, or spawn external processes (such as %pipe%) are disabled or strictly restricted.

However, historical vulnerabilities in Ghostscript have repeatedly targeted -dSAFER. If an attacker can trigger memory corruption within the interpreter, they can manipulate internal data structures, restore restricted operators, and execute shell commands.

Technical Analysis: How Upload2Shell Works

CVE-2026-125396 resides in Ghostscript's Type 1 font loading implementation. When parsing embedded PostScript fonts, Ghostscript allocates temporary dictionaries to track font metadata, encoding vectors, and charstrings.

By supplying a malformed Type 1 font dictionary containing mismatched operator declarations and circular references, an attacker forces the font loader into an anomalous state where memory allocated for the font structure is freed prematurely.

The interpreter continues to reference the deallocated memory region through a dangling pointer (Use-After-Free). Through heap manipulation, the attacker fills this memory slot with controlled PostScript objects, corrupting internal interpreter tables.

Once heap memory is groomed, the attacker rewrites Ghostscript's internal system dictionary flags, clearing the SAFER constraint. With -dSAFER neutralized, the interpreter executes shell commands directly via the %pipe% file device under the running process UID.

Attack Flow Diagram

The diagram and structured breakdown below illustrate the complete attack lifecycle of Upload2Shell, showing how an untrusted document moves through server-side helper components to trigger command execution.

Figure 1. Upload2Shell Attack Flow: From Crafted File Submission to Potential Command Execution.

Affected Applications and Services

A key characteristic of Upload2Shell is that vulnerable servers rarely expose Ghostscript directly. The table below lists common server applications that delegate file rendering to Ghostscript.

Application / ServiceIntegration WorkflowExposure Context & Blast Radius
WordPress Uploads to the Media Library processed by PHP Imagick for responsive image thumbnails. Authenticated authors or unauthenticated forms (e.g. user avatar uploads) trigger background delegate conversion.
Roundcube & Webmail Inbound email attachment previews automatically generate inline thumbnail renderings. Receiving an email containing a crafted attachment triggers rendering on the webmail server.
CUPS Print System Print spooler pipelines invoke cups-filters (pdftops, pstopdf) to format jobs. Submitting print jobs over local networks or IPP-exposed printing endpoints reaches Ghostscript.
Nextcloud & OwnCloud Document preview provider generates thumbnails for shared PDF and PostScript files. File synchronisation or public file-drop shares invoke thumbnail generation.
MediaWiki File upload verification and rendering pipelines utilize ImageMagick delegates. Wiki contributors or public upload portals trigger automated thumbnail generation.

Potential Security Impact

While command execution does not automatically confer root privileges, gaining code execution within the web or print context provides adversaries with a powerful foothold.

Security Impact DomainSeverityOperational & Business Risk
Remote Command Execution High Adversaries spawn interactive reverse shells, execute arbitrary system binaries, and deploy persistence scripts.
Application Credential Theft High Attackers read web application configuration files (e.g. wp-config.php), extracting cleartext database passwords and API tokens.
Data Exfiltration High Access to internal databases, customer records, and stored attachments residing on the web server.
Lateral Network Movement High The compromised server serves as an internal pivot point to scan and attack internal microservices and domain controllers.
Container Breakout Risk Moderate In containerized environments, attackers attempt kernel privilege escalation to escape the container boundary.

Detection and Threat Hunting

Because Upload2Shell exploits an underlying rendering engine, traditional network signatures on HTTP POST parameters often fail to detect disguised payloads. Defenders must focus on behavioral process telemetry and content validation anomalies.

Telemetry LayerAnomalous Behavioral IndicatorRecommended SOC Triage Action
Process Creation (EDR) Web server accounts (www-data, apache, nginx) spawning command interpreters (sh, bash, python). Immediately isolate the web server host, terminate suspicious child processes, and preserve memory.
Delegate Execution Logs gs binary spawned with unusual temporary file paths (/tmp/magick-*) or long execution times. Correlate gs process invocations with recent web upload access logs to identify the origin IP.
Content-Extension Mismatch Files uploaded with benign extensions (.png, .jpg) whose initial bytes match PostScript (%!PS) or PDF. Alert on application-level file-type validation bypasses and audit the uploaded file payload.
Network Egress Telemetry Outbound TCP connections initiated by web worker processes to uncategorized external IP addresses. Terminate the connection at the firewall and inspect the command line that initiated outbound network traffic.

Illustrative Splunk SIEM Hunting Query

The following Splunk SPL query detects web server service accounts spawning unauthorized child processes, which is the primary post-exploitation indicator for Upload2Shell.

Note: This hunting query is provided as an illustrative defensive example; tune field names and thresholds to match your enterprise schema.

index=edr_process (user IN ("www-data", "apache", "nginx", "nobody", "lp") OR ParentImage IN ("*php-fpm*", "*apache2*", "*httpd*", "*nginx*", "*cupsd*"))
Image IN ("*\\sh.exe", "*\\bash.exe", "*\\cmd.exe", "*\\powershell.exe", "*/sh", "*/bash", "*/dash", "*/python*", "*/perl*", "*/curl*", "*/wget*")
| stats count AS event_count, values(CommandLine) AS executed_commands, values(ParentImage) AS parent_processes BY host, user, Image, _time
| sort - _time

Remediation and Mitigation

Securing enterprise infrastructure against Upload2Shell requires a layered defense combining package patching, configuration hardening, and file validation.

Defensive LayerRecommended Remediation ActionVerification Method
Package Upgrade Upgrade Ghostscript to upstream 10.08.0 or install the patched distribution package revision. Execute gs --version or query dpkg/rpm package managers (e.g. >= 10.05.1~dfsg-1+deb13u2).
ImageMagick Hardening Disable PS, EPS, PDF, and XPS coder rights in /etc/ImageMagick-7/policy.xml. Run magick -list policy and confirm rights: None on target patterns.
Content Validation Enforce MIME magic-byte validation (libmagic) prior to invoking any image manipulation libraries. Verify file headers reject %!PS and %PDF streams disguised with .png extensions.
Service Isolation Run web workers and rendering queues inside minimal, unprivileged container namespaces. Confirm container runs with drop-capabilities, no-new-privileges, and read-only root filesystems.
Process Restriction Disable dangerous PHP execution functions (proc_open, shell_exec, system) in php.ini. Inspect phpinfo() or run php -i | grep disable_functions.

Practical Lab Analysis: Weak vs Secure Configuration

To examine the concrete behavior of upload delegate pipelines, our Threat Intelligence team evaluated a controlled research lab. The lab runs two side-by-side Docker Compose pipelines on Windows 11:

  • Configuration A (Port 8081 — vulnerable-sim):Simulates a permissive upload pipeline where incoming files are processed by ImageMagick without strict coder restrictions or magic-byte verification.

  • Configuration B (Port 8082 — secure):Implements a hardened pipeline with strict content-type validation, explicit coders, and an ImageMagick security policy disabling PostScript delegates.

Important Safety Note: The research lab utilizes a harmless simulator script to safely assess delegate routing and policy boundaries without running real exploit code or deploying vulnerable renderers.

13.1 Application Upload & Ingestion Results

When a PostScript file disguised with a PNG extension (ps-named-png.png) was submitted to Configuration A, the application performed only superficial extension checking. The upload was accepted and passed to the thumbnail renderer.

Figure 2. Upload Result on Configuration A (vulnerable-sim): Disguised file accepted by weak extension check.

In contrast, when the identical file was submitted to Configuration B, the secure pipeline inspected the actual content bytes using libmagic, identified the PostScript signature, and immediately rejected the file.

Figure 3. Upload Result on Configuration B (secure): Disguised file rejected due to content-type mismatch.

13.2 ImageMagick Policy Hardening Verification

The primary line of defense against delegate exploitation is configuring ImageMagick's security policy. Inspection of the policy on Configuration B confirms that rights are explicitly set to None for PostScript and PDF coders.

Figure 4. Hardened ImageMagick Policy Dump: PS, EPS, PDF, and related coders denied (rights: None).

13.3 Processing Pipeline Test Suite Results

The test suite evaluated ten distinct file fixtures against both configurations. In Configuration A, all ten fixtures passed weak checks, and PostScript/PDF files invoked the simulated Ghostscript renderer.

Figure 5. Safe Pipeline Test on Configuration A (app-vulnsim): 10/10 expectations matched with simulated delegate invocation.

In Configuration B, every disguised fixture was correctly blocked by content validation and policy rules, verifying 10/10 matched security expectations.

Figure 6. Safe Pipeline Test on Configuration B (app-secure): 10/10 expectations matched with hostile delegates blocked.

13.4 Ghostscript Delegate Execution Tracing

To confirm whether ImageMagick delegates execution to Ghostscript, trace tests were executed against a valid PDF file. Under the permissive policy, Ghostscript was executed directly.

Figure 7. Ghostscript Execution Trace under Permissive Policy: GHOSTSCRIPT_EXECED=yes.

13.5 Linux Distribution Package Revision Inventory

Administrators must recognize that Linux distributions backport security fixes without changing upstream major version numbers. An inventory query confirms that Debian 13 (trixie) package 10.05.1~dfsg-1+deb13u2 incorporates the patch.

Figure 9. Container Inventory Output: GS_VERDICT=FIXED based on distribution package revision.

How TechOwl Shield Helps

Addressing delegate vulnerabilities like Upload2Shell requires continuous asset discovery, rigorous application testing, and real-time detection telemetry:

  • External Attack Surface Management (EASM):TechOwl Shield continuously scans internet-facing assets, identifying exposed web application instances (WordPress, Nextcloud, Roundcube), outdated software libraries, and vulnerable external gateways.

  • Vulnerability Assessment & Penetration Testing (VAPT):TechOwl's certified offensive security engineers test document processing pipelines, assessing whether web application upload workflows can be coerced into executing arbitrary delegate commands.

  • 24/7 Managed SOC & Threat Intelligence:TechOwl's Managed SOC monitors endpoint and container process telemetry around the clock, alerting on anomalous child processes spawned by web server daemons.

Frequently Asked Questions (FAQs)

1. Does Upload2Shell require Ghostscript to be directly exposed to the internet?

No. In almost all real-world scenarios, Ghostscript is not internet-facing. Vulnerabilities are triggered indirectly when web applications (like WordPress or Roundcube) invoke ImageMagick or PHP Imagick to process uploaded documents, which in turn launches Ghostscript as a delegate.

2. Does successful exploitation grant immediate root access to the host?

No. Commands executed through the -dSAFER bypass run strictly under the user account of the process that launched Ghostscript (typically www-data, apache, or lp). However, this foothold allows an attacker to steal database credentials, inspect local files, and attempt local privilege escalation.

3. Why is checking the file extension insufficient to prevent Upload2Shell?

Many image libraries determine file type by inspecting magic bytes rather than trusting file extensions. If an attacker names a PostScript file image.png, weak upload filters accept it, but ImageMagick identifies the PostScript header and invokes Ghostscript.

4. What upstream and Linux distribution versions of Ghostscript are fixed?

Upstream Ghostscript resolved the issue in version 10.08.0. Linux distributions (Debian, Ubuntu, Red Hat) backport the fix into existing package streams; administrators must verify package revisions (such as Debian's 10.05.1~dfsg-1+deb13u2) rather than upstream version numbers alone.

5. How does disabling PostScript coders in ImageMagick's policy.xml mitigate the vulnerability?

Setting rights='none' for PS, EPS, and PDF coders instructs ImageMagick to refuse processing those file formats entirely. This prevents ImageMagick from ever invoking Ghostscript, neutralizing the delegate attack surface.

6. Can WordPress sites protected by web application firewalls (WAFs) still be vulnerable?

Yes. Many WAFs inspect HTTP request parameters but fail to parse binary or encoded file uploads. If the WAF allows multipart/form-data uploads to reach the application server, the underlying delegate pipeline remains exposed.

References & Source Documentation