Introduction
Imagine you check out of a hotel, but the receptionist forgets to cancel your key card. The next day, your old room is given to a new guest, and your old card still opens the door. You walk in and start rearranging their things.
That is the idea behind Upload2Shell (CVE-2026–125396): a use-after-free bug in Ghostscript, a tool hiding on millions of Linux servers that most people have never heard of.
The scary part? The attacker doesn't need to hack your server directly. They just upload a file that looks like a normal JPG.
Quick Facts
- Found by: Paulos Yibelo and the pwn.ai team (with AI help)
- Fixed in: Ghostscript
10.08.0(released 8 September 2026) - Details & PoC public: 21 November 2026
- Severity: CVSS 4.0 8.5 (High)
- Exploited in the wild? No attacks reported so far
Let's break it down step by step.
1. What Is Ghostscript, and Why Is It on My Server?
Ghostscript reads PDF and PostScript files and turns them into images or previews. You almost never call it yourself. It sits quietly underneath tools like ImageMagick, Pillow, libvips, CUPS (printing), WordPress thumbnails, and webmail previews.
Example: You upload your resume to a job portal. The site makes a small preview of it. Behind the scenes, it hands your file to Ghostscript.
Here is the catch: PostScript is a programming language. Opening one means running a program. To keep that safe, Ghostscript uses a sandbox called -dSAFER, which says: "You may draw, but you may not touch files or run commands."
Upload → App / Library → Ghostscript (-dSAFER sandbox) → Preview
2. What Is the Bug?
Part of Ghostscript's font loading is written in PostScript itself. One helper, .putgstringcopy, uses a very powerful internal operator called .forceput to write into protected areas. The problem: the helper never checked what it was handed.
1. Crafted Type 1 font → helper hits a type error
2. File's own error handler runs → recovers the privileged .forceput
3. Use-after-free → attacker keeps a pointer to freed memory
4. Memory read/write → -dSAFER path checks switched off
5. Command execution → arbitrary commands run on the server
Back to the hotel analogy: the memory is the room, and the pointer is the old key card. Ghostscript gives the room back (frees it) after save/restore, but the attacker's card still works, so they can read and change whatever now lives there.
The fix (upstream commit "validate operands to .putgstringcopy") checks the operand types first, so the error path can no longer reach the privileged write.
3. Attack Techniques
Disguised file (resume.jpg, really PostScript)
↓
App or library checks the content and passes it to Ghostscript
↓
Crafted Type 1 font → type error → .forceput recovered
↓
Use-after-free → memory read/write
↓
-dSAFER disabled → command runs as the service account
Three tricks make this dangerous:
- Disguise: The file can be named
.jpg,.png, or.pdf. Image and document libraries inspect the file bytes, not the filename extension. - Indirect reach: The attacker never talks to Ghostscript directly. Your web app or mail server does it for them.
- Zero or low access: Several attack paths required no login at all.
Routes pwn.ai Demonstrated
The command executes under the account that renders the file (for example lp for printing or www-data for a web server), so it is not instant root—but it gives the attacker a solid foothold.
MITRE ATT&CK mapping: T1190 Exploit Public-Facing Application · T1566.001 Spearphishing Attachment (Roundcube route) · T1036.008 Masquerade File Type · T1059.004 Unix Shell
[NOTE] Is one upload always a shell? Not necessarily. It depends on which libraries your app uses and how files are processed. Also, the public proof-of-concept only shows the core memory trick and fails on Ghostscript
10.08.0. Don't panic, but don't ignore it either.
4. Who Is Affected?
Anything running Ghostscript before 10.08.0 that processes files uploaded or sent by someone else.
[WARNING] Version trap: Linux distributions often backport security fixes, so an older-looking version number like
9.55can already be patched. Always check your distro's security advisory, not justgs --version.
WordPress also closed its own upload path in WordPress 7.0.4 (CVE-2026–65640), which addresses a different point in the same chain. You still need the Ghostscript fix.
5. Remediation
- Update Ghostscript to
10.08.0or your distribution's patched build:
# Debian / Ubuntu
sudo apt update && sudo apt upgrade ghostscript
# AlmaLinux / RHEL-family
sudo dnf clean metadata && sudo dnf upgrade 'ghostscript*' libgs
- Restart services that already loaded the old
libgsshared library (sudo dnf needs-restartinglists affected services on RHEL-family hosts). - Check containers and bundled copies. Patching the host OS does not patch a copy of Ghostscript inside a Docker image or an application bundle. Rebuild those images.
- Update WordPress to
7.0.4or later as well.
6. Mitigation (If You Can't Patch Today)
There is no Ghostscript flag that eliminates the bug, because -dSAFER itself is what gets bypassed. All you can do temporarily is reduce how easily an untrusted file reaches Ghostscript:
- ImageMagick: Block PostScript-type coders in
policy.xml:
<policy domain="coder" rights="none" pattern="{PS,PS2,PS3,EPS,EPSI,EPT,PDF,XPS}" />
- CUPS: Do not expose print queues to untrusted networks, and require authentication.
- Web apps: Validate the file's actual magic bytes/content type before thumbnailing, and disable previews for document formats you do not need.
- OS Hardening: In one
pwn.aitest, an AppArmor profile prevented the hijacked Ghostscript interpreter from spawning a shell.
[IMPORTANT] These measures only narrow exposure. Patching Ghostscript is the real fix.
For Blue Teamers: What to Watch
gsspawningsh,bash,curl, orwget. The process treephp-fpm/apache→convert/magick→gs→shshould never happen.- Ghostscript crashes (segfaults) immediately after a file upload.
- Uploads where the filename extension says
.jpgbut file content/magic bytes indicate PostScript (%!PS). - Anonymous print jobs originating from unknown IPs.
[TIP] A Wazuh or
auditdrule monitoringexecvesyscalls where the parent process isgsis a quick detection win.
30-Second Self-Check
- Does any site or app of yours accept files from strangers (resume, photo, PDF)?
- Does it generate a thumbnail, preview, or resize?
- Do you know which copy of Ghostscript it uses?
If you answered yes, yes, no — check it today.
Conclusion
Upload2Shell shows that the most dangerous code is often not the code you wrote, but the quiet helper sitting three layers underneath your application. A single forgotten type check turned a trusted sandbox into an open door.
Patch Ghostscript, check your containers, and treat every uploaded file as untrusted—even when it says .jpg.
References and Further Reading
- pwn.ai: Upload2Shell overview
- pwn.ai: Technical write-up
- The Hacker News: Ghostscript Sandbox-Escape RCE
- WordPress: 7.0.4 release notes
- CVE Record: CVE-2026-125396
Connect & Contact
- Buy Me a Coffee: buymeacoffee.com/jaseervk
- GitHub: github.com/jaseervk
- Portfolio: www.jaseervk.com
- Blog: blog.jaseervk.com
- LinkedIn: linkedin.com/in/jaseer-vk-
- Medium: https://medium.com/@jaseervk321