Tag: Upload2Shell

Detecting Upload2Shell: 5 Sigma rules for Ghostscript shells and disguised uploads

Detecting Upload2Shell: 5 Sigma rules for Ghostscript shells and disguised uploads

Upload2Shell has no IOCs. No IP addresses, no hashes, no file names you can grep for. pwn.ai published a proof of concept on November 21, 2026 that turns a disguised PostScript file into commands running as www-data or lp, and the only artefacts it mentions are what its own proofs left behind: a marker file in /var/tmp on the print server and a PHP file on the WordPress test, with no path given. If you want to know whether someone tried this on your servers, you have to watch behaviour.

The good news is that the behaviour is unusually clean. Ghostscript is a document renderer, and a renderer that starts a shell or opens a network socket has stopped rendering. This post is the detection companion to my analysis of the bug: five Sigma rules, what each one catches, how to tune it and how to test it without an exploit.

At a glance

  • Rules: 5 (two high, two medium, one low hunting rule), all status: experimental.
  • Domains: Linux (four rules) and Network (one rule).
  • Log sources: Linux process creation, network connection and file creation (Sysmon for Linux, auditd or EDR), plus the Zeek HTTP log.
  • ATT&CK: T1059.004 Unix Shell, T1190 Exploit Public-Facing Application, T1105 Ingress Tool Transfer, T1036.008 Masquerade File Type.
  • CVEs: CVE-2026-125396 (Ghostscript), CVE-2026-65640 (WordPress upload path).
  • YAML: my Detection Rules repo on GitHub, folders Linux and Network.

The case in brief

An attacker uploads a file named like an image or a PDF that actually contains PostScript. It might come through a WordPress upload field, as a Roundcube attachment or as an anonymous IPP print job to a shared CUPS queue. ImageMagick and Pillow pick a decoder by content, libvips reaches Ghostscript through its magickload (ImageMagick) loader, and on the IPP path CUPS hands the job to Ghostscript through its gstopdf filter. Either way, the file lands in Ghostscript. The use-after-free in the Type 1 font loader switches off -dSAFER, and the document’s code runs as whichever account called Ghostscript. pwn.ai saw uid=33(www-data) for web apps and Roundcube, uid=7(lp) for CUPS, roundcube_sysuser on Plesk and uid 1000 inside a Mayan EDMS container. The full story is in the analysis.

That gives three places to look: the upload on the wire, the process tree on the host, and whatever the payload does next (a connection, a dropped file). pwn.ai describes no attacker post-exploitation beyond its proof artefacts, so everything past “a command runs” is my inference about what an attacker would do with a shell. That is why every rule here is experimental.

Detection map

Block diagram: Linux process creation, network connection and file creation logs plus the Zeek HTTP log feed five Sigma rules (PostScript upload posing as image or PDF, gs spawns shell or tool, renderer or CUPS filter child, gs network connection, temp-dir drops) mapped to T1190, T1036.008, T1059.004 and T1105, with print jobs, mail attachments and in-memory payloads marked as a gap.
Four log sources, five rules. Print and mail delivery and in-memory payloads stay outside Sigma.

Read it left to right. Host telemetry carries most of the weight: three of the four sources are Sysmon for Linux event types (or their auditd and EDR equivalents), and none of them is on by default on a typical web or print server. The Zeek rule is the only one that fires before any code runs, but it needs to see uploads in cleartext, which means a sensor behind your TLS terminator. The dashed box is what nothing here covers well: print jobs, mail attachments and payloads that never leave the Ghostscript process.

Rule overview

RuleDomainLog sourceATT&CK (tactic / technique)LevelStatus
Ghostscript spawning shell, interpreter or download toolLinuxlinux / process_creationExecution / T1059.004, Initial Access / T1190HighExperimental
Image converter, PHP or CUPS filter spawning suspicious child as service accountLinuxlinux / process_creationExecution / T1059.004, C2 / T1105MediumExperimental
Outbound network connection initiated by GhostscriptLinuxlinux / network_connectionC2 / T1105HighExperimental
Ghostscript or service account writing to temp directoriesLinuxlinux / file_eventC2 / T1105Low (hunting)Experimental
PostScript upload disguised as an image or PDFNetworkzeek / httpInitial Access / T1190, Defense Evasion / T1036.008MediumExperimental

The rules

Ghostscript spawning shell, interpreter or download tool

Context: this is the moment of compromise. Once -dSAFER is off, the obvious next move for a document is to open a pipe to a command, and Ghostscript does that by starting sh. SnapAttack’s 2024 write-up on CVE-2024-29510 showed exactly this tree (gs starting dash), and Splunk’s ESCU “Linux Ghostscript Exploitation” analytic alerts on gs parents with sh -c children. My rule uses the same idea with a broader child list. I wrote it independently and didn’t copy their search.

Condition: alert when the parent image is gs, gsc or ghostscript and the child is a shell, Python, Perl, Ruby, PHP, curl, wget, netcat, socat, telnet or openssl. Exclude it only if the gs command line itself carries a %pipe% output. The direction is what makes this work: callers starting gs is routine (ImageMagick’s delegates.xml defines its Ghostscript delegate as a shell-quoted command line), but gs starting a shell is not normal.

ATT&CK: Execution (TA0002) – T1059.004 Unix Shell; Initial Access (TA0001) – T1190 Exploit Public-Facing Application.

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

View on GitHub

False positives and tuning: the real false positives come from Ghostscript’s %pipe% output device, which some print setups use to send output to lpr. That pipe runs through sh, so you get gs, then sh, then lpr. The optional filter drops those, but only when the pipe sits on the gs command line, where the caller put it. A malicious document opens its pipe from inside the PostScript, so the parent command line stays clean and the alert still fires. Don’t widen the filter to match on the child command line. On desktops, scripted gs workflows can trip it too. Scope to servers if that’s noisy.

How to test: on a lab box, run gs -dNOSAFER -dNODISPLAY -dBATCH -c "(%pipe%id) (w) file closefile". That turns off the sandbox on purpose and asks gs to pipe to id, which should log gs starting sh without any exploit. Don’t expect a tidy gs, sh, id chain: dash often execs a single command in place, so id may show up with gs as its parent instead of sh. The rule fires on the sh event either way.

Image converter, PHP or CUPS filter spawning a suspicious child as a service account

Context: rule one depends on a process actually named gs. That isn’t always the case. ImageMagick can be built against libgs and run Ghostscript inside its own process, Pillow and libvips sit inside Python or PHP workers, and a bundled copy in a container may carry another name. This rule looks one level up, at the processes that hand files to Ghostscript, and only when they run as the accounts pwn.ai saw: www-data, lp and roundcube_sysuser, plus the usual apache, nginx and http.

Condition: the parent is ImageMagick (convert, magick, mogrify, identify, montage), vips, Apache, PHP or PHP-FPM, Python, or anything under a CUPS filter directory. The user is one of the service accounts. The child is either a download or network tool, or a shell whose command line fetches something, opens /dev/tcp, decodes base64 or touches /dev/shm. Shells that carry -sDEVICE= are excluded: every Ghostscript delegate command in ImageMagick’s delegates.xml sets an output device, so a shell with that flag is a delegate call, not a payload. CUPS parents are handled separately and only match download or network tools.

ATT&CK: Execution (TA0002) – T1059.004 Unix Shell; Command and Control (TA0011) – T1105 Ingress Tool Transfer; Initial Access (TA0001) – T1190.

title: Image Converter, PHP or CUPS Filter Spawning Download Tool or Suspicious Shell as Service Account
id: 82a7bb2c-e41d-4241-8367-913ab6251b2a
status: experimental
description: |
    Detects ImageMagick, libvips, PHP, Python, web server or CUPS filter processes running as a web or print service account
    that start a download or network tool, or a shell whose command line fetches or opens a connection. Catches the Upload2Shell
    chain one level up, including builds where Ghostscript runs in-process (libgs). Inferred from the pwn.ai process context, not from incident data.
references:
    - https://pwn.ai/upload2shell/research.html
    - https://www.cve.org/CVERecord?id=CVE-2026-125396
    - https://www.patchstack.com/articles/when-a-png-isnt-a-png-wordpress-patches-an-author-level-imagick-rce/
    - 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.command-and-control
    - attack.t1105
    - attack.initial-access
    - attack.t1190
    - cve.2026-125396
logsource:
    product: linux
    category: process_creation
detection:
    selection_parent_web_name:
        ParentImage|endswith:
            - '/convert'
            - '/magick'
            - '/mogrify'
            - '/identify'
            - '/montage'
            - '/vips'
            - '/apache2'
            - '/httpd'
    selection_parent_web_versioned:
        ParentImage|re: '/(php-fpm[0-9.]*|php[0-9.]*|python[0-9.]*)$'
    selection_parent_cups:
        ParentImage|contains: '/cups/filter/'
    selection_user:
        User:
            - 'www-data'
            - 'apache'
            - 'nginx'
            - 'http'
            - 'lp'
            - 'roundcube_sysuser'
    selection_child_tool:
        Image|endswith:
            - '/curl'
            - '/wget'
            - '/nc'
            - '/ncat'
            - '/netcat'
            - '/socat'
            - '/telnet'
            - '/busybox'
    selection_child_shell:
        Image|endswith:
            - '/sh'
            - '/bash'
            - '/dash'
        CommandLine|contains:
            - 'curl '
            - 'wget '
            - '/dev/tcp/'
            - '/dev/udp/'
            - 'nc '
            - 'ncat '
            - 'socat '
            - 'base64 -d'
            - '/dev/shm/'
    filter_main_gs_delegate:
        # ImageMagick's gs delegate commands (delegates.xml) set -sDEVICE=; a shell carrying that is a delegate call, not a payload
        CommandLine|contains: '-sDEVICE='
    # CUPS filters are often shell scripts, so CUPS parents only match download/network tools, never shells
    condition: ((1 of selection_parent_web_* and 1 of selection_child_*) or (selection_parent_cups and selection_child_tool)) and selection_user and not filter_main_gs_delegate
falsepositives:
    - PHP or Python applications that legitimately shell out to curl or wget (update checkers, webhooks); exclude by full command line after a baseline
    - CUPS backends or custom filters that fetch resources over the network
    - Service accounts named differently on your distribution; extend the user list rather than removing it
level: medium

View on GitHub

False positives and tuning: this is the noisiest of the process rules, because PHP and Python apps do call curl, for update checks and webhooks. Baseline for a week and exclude by full command line, not by parent. The CUPS branch only matches download and network tools, never shells, because many CUPS filters are shell scripts and their ordinary children would drown you. If your distribution names its web user differently, add the name to the list. Don’t delete the user clause, or this turns into a generic web shell rule that fires all day.

How to test: sudo -u www-data php -r 'system("curl -s http://127.0.0.1/");' produces php, then sh with a curl command line, under the right user.

Outbound network connection initiated by Ghostscript

Context: a payload that lives inside the gs process, such as a reverse connection built from the memory primitive rather than a child shell, gets past both process rules. A renderer has no business opening sockets, so any connection from gs is worth a look. pwn.ai published no network indicators. This rule is pure inference from the bug class.

Condition: alert when gs, gsc or ghostscript initiates a connection to anything other than loopback.

ATT&CK: Command and Control (TA0011) – T1105 Ingress Tool Transfer.

title: Outbound Network Connection Initiated by Ghostscript
id: c8efc9fe-8344-4263-a90a-a5093c46df3c
status: experimental
description: |
    Detects a Ghostscript process (gs, gsc, ghostscript) initiating a network connection to a non-loopback address. A renderer
    that converts or thumbnails documents has no reason to talk to the network, so a connection suggests the interpreter is
    running attacker code after a -dSAFER escape such as CVE-2026-125396. Inferred from the bug class; pwn.ai published no network indicators.
references:
    - https://pwn.ai/upload2shell/research.html
    - https://www.cve.org/CVERecord?id=CVE-2026-125396
    - https://netsec101.com/?p=476
author: netsec101.com
date: 2026-11-23
tags:
    - attack.command-and-control
    - attack.t1105
    - cve.2026-125396
logsource:
    product: linux
    category: network_connection
detection:
    selection:
        Image|endswith:
            - '/gs'
            - '/gsc'
            - '/ghostscript'
        Initiated: 'true'
    filter_main_loopback:
        DestinationIp|cidr:
            - '127.0.0.0/8'
            - '::1/128'
    condition: selection and not filter_main_loopback
falsepositives:
    - Print servers where Ghostscript itself writes to a network printer socket configured on its command line; confirm which printer ports your print path uses and scope out those hosts and ports
level: high

View on GitHub

False positives and tuning: on most web hosts I’d expect it to stay silent. On print servers, check whether gs ever writes straight to a printer socket before you page anyone, and exclude those hosts and printer ports if it does. Which ports that means depends on your print path, so check rather than assume. Sysmon for Linux only logs network connections if your config includes event 3, so check that first.

How to test: a benign gs run seldom opens a socket itself (in the rule one test, the connection would come from the child). The easiest check is to replay a synthetic Sysmon event 3 with Image set to /usr/bin/gs into your SIEM and confirm the converted query matches.

Ghostscript or service account writing to temp directories

Context: the one concrete artefact pwn.ai mentions is a marker file its proof wrote under /var/tmp on the Debian print server (/var/tmp/GS_CUPS_PIPE_RCE). That name only tells you the proof ran, so I treat it as a lab artefact, not an indicator. The broader pattern is worth hunting, though: attackers who land as www-data or lp tend to stage things in world-writable temp directories.

Condition: match any of three things. First, gs writes into /var/tmp, /dev/shm or a /tmp file that isn’t one of its own scratch files or an ImageMagick temp file. I assumed the prefixes gs_ and magick- for those; check what your builds actually write before you trust the filter. Second, a web or print service account creates a script, shared object or binary-looking file in any of the three directories. Third, the PoC marker file shows up.

ATT&CK: Command and Control (TA0011) – T1105 Ingress Tool Transfer.

title: Ghostscript or Web/Print Service Account Writing Scripts or Unexpected Files to Temp Directories
id: fce501fb-70ab-4899-b2a0-1634140ed9cd
status: experimental
description: |
    Hunts for Ghostscript writing files in /var/tmp or /dev/shm, or outside its own scratch files in /tmp, and for web or print
    service accounts dropping scripts or binaries into /tmp, /var/tmp or /dev/shm. The pwn.ai proof wrote a marker file under
    /var/tmp on the Debian print server; that exact name is included as a lab and PoC artefact, not an in-the-wild indicator.
references:
    - https://pwn.ai/upload2shell/research.html
    - https://www.cve.org/CVERecord?id=CVE-2026-125396
    - https://netsec101.com/?p=476
author: netsec101.com
date: 2026-11-23
tags:
    - attack.command-and-control
    - attack.t1105
    - cve.2026-125396
    - detection.threat-hunting
logsource:
    product: linux
    category: file_event
detection:
    selection_gs_image:
        Image|endswith:
            - '/gs'
            - '/gsc'
            - '/ghostscript'
    selection_gs_path:
        TargetFilename|startswith:
            - '/tmp/'
            - '/var/tmp/'
            - '/dev/shm/'
    filter_gs_scratch:
        # Assumed prefixes, verify on your hosts: gs scratch files gs_, ImageMagick temp files magick-
        TargetFilename|startswith:
            - '/tmp/gs_'
            - '/tmp/magick-'
    selection_svc_user:
        User:
            - 'www-data'
            - 'apache'
            - 'nginx'
            - 'http'
            - 'lp'
            - 'roundcube_sysuser'
    selection_svc_path:
        TargetFilename|startswith:
            - '/tmp/'
            - '/var/tmp/'
            - '/dev/shm/'
    selection_svc_ext:
        TargetFilename|endswith:
            - '.sh'
            - '.py'
            - '.pl'
            - '.php'
            - '.elf'
            - '.so'
            - '.bin'
    selection_poc_marker:
        TargetFilename: '/var/tmp/GS_CUPS_PIPE_RCE'
    condition: (selection_gs_image and selection_gs_path and not filter_gs_scratch) or (selection_svc_user and selection_svc_path and selection_svc_ext) or selection_poc_marker
falsepositives:
    - Applications that point Ghostscript's TMPDIR or -sOutputFile into /var/tmp or /dev/shm; add that prefix to the filter
    - PHP applications that cache compiled templates or plugin files as .php under /tmp
    - Package or plugin installers running as www-data
level: low

View on GitHub

False positives and tuning: it’s a hunting rule at level: low for a reason. PHP apps cache templates as .php under /tmp, plugin installers run as www-data, and some apps point gs’s TMPDIR at /var/tmp. Review it weekly, add the prefixes your apps legitimately use, and don’t alert on it. Note that the User field depends on your Sysmon for Linux version and field mapping. With auditd you’ll match on uid instead.

How to test: sudo -u lp touch /var/tmp/test.sh.

PostScript upload disguised as an image or PDF

Context: this is the delivery trick, and the only rule that fires before any code runs. Patchstack’s analysis of the WordPress fix (CVE-2026-65640) shows the gap: WordPress picked the editor by file extension, while ImageMagick read the magic bytes. A file named .png or .jpg that starts with %!PS is almost never innocent on an upload form.

Condition: an HTTP POST or PUT whose request body Zeek identifies as application/postscript, with an uploaded file name ending in an image or PDF extension. Zeek records both in http.log as orig_mime_types and orig_filenames.

ATT&CK: Initial Access (TA0001) – T1190 Exploit Public-Facing Application; Defense Evasion (TA0005) – T1036.008 Masquerade File Type.

title: HTTP Upload of PostScript Content With an Image or PDF File Name - Upload2Shell Delivery
id: 7bd3de21-4aff-4be3-b42d-2244ebbee66c
status: experimental
description: |
    Detects an HTTP upload whose body Zeek's content sniffing identifies as PostScript (it starts with %!PS) while the uploaded
    file name ends in an image or PDF extension. This is the Upload2Shell delivery trick: ImageMagick and Pillow pick a decoder
    by content, so a .jpg, .png or .pdf full of PostScript reaches Ghostscript. Needs cleartext HTTP visibility (after TLS termination).
references:
    - https://pwn.ai/upload2shell/research.html
    - https://www.patchstack.com/articles/when-a-png-isnt-a-png-wordpress-patches-an-author-level-imagick-rce/
    - https://www.cve.org/CVERecord?id=CVE-2026-125396
    - https://netsec101.com/?p=476
author: netsec101.com
date: 2026-11-23
tags:
    - attack.initial-access
    - attack.t1190
    - attack.defense-evasion
    - attack.t1036.008
    - cve.2026-125396
    - cve.2026-65640
    - detection.emerging-threats
logsource:
    product: zeek
    service: http
detection:
    selection_method:
        method:
            - 'POST'
            - 'PUT'
    selection_mime:
        orig_mime_types|contains: 'application/postscript'
    selection_name:
        orig_filenames|endswith:
            - '.jpg'
            - '.jpeg'
            - '.png'
            - '.gif'
            - '.bmp'
            - '.tif'
            - '.tiff'
            - '.webp'
            - '.pdf'
    condition: all of selection_*
falsepositives:
    - Print, prepress or design portals where users upload EPS artwork under the wrong extension; scope to upload endpoints of apps that never accept PostScript
    - Zeek only fills orig_filenames when the multipart part carries a file name; drop selection_name for a broader, noisier hunt
level: medium

View on GitHub

False positives and tuning: design and prepress portals do get EPS artwork with the wrong extension, so scope the rule to upload endpoints of apps that never accept PostScript. Both fields are arrays in Zeek, so check how your backend handles contains and endswith on lists. The bigger limit is visibility: Zeek must see the request after TLS termination, so a sensor on the internet side of your load balancer sees nothing useful.

How to test: upload any benign EPS file renamed to test.jpg to a lab application behind your Zeek sensor.

Coverage and gaps

Step in the caseTacticTechniqueRuleCovered?
Disguised PostScript uploaded over HTTPInitial Access, Defense EvasionT1190, T1036.008PostScript upload disguised as image or PDFYes, with cleartext Zeek visibility
Anonymous IPP print job to shared CUPS queueInitial AccessT1190NoneGap: no content check in CUPS logs (my understanding, verify)
Disguised attachment in Roundcube or mail importInitial AccessT1190NoneGap: mail path not covered
gs escapes -dSAFER and runs a commandExecutionT1059.004Ghostscript spawning shell or toolYes
In-process libgs or renamed gs runs a commandExecutionT1059.004Renderer or CUPS filter childPartial: needs a suspicious child
Tool download or reverse connectionCommand and ControlT1105Ghostscript outbound connection, renderer childYes
Files staged in temp directoriesCommand and ControlT1105Temp-dir writes (hunting)Hunting only
PHP file written by the WordPress proofPersistenceT1505.003NoneGap: path not published
Payload that stays inside gs memoryn/an/aNoneGap

The two delivery paths I can’t cover in Sigma are print and mail. For CUPS, the practical control is configuration, not detection: require authentication on shared queues and watch /var/log/cups/access_log for Print-Job requests from hosts that never print. That’s a manual hunt: as far as I know, the access log tells you who printed, not what the file was, so check your own CUPS logs before relying on that. For mail, a gateway or Zeek files.log with MIME sniffing on SMTP can apply the same “PostScript posing as an image” logic. The WordPress proof wrote a PHP file, but pwn.ai doesn’t say where, so file integrity monitoring on the web root is the honest answer there. A payload that never leaves the gs process needs syscall-level telemetry (eBPF tools such as Falco or Tetragon) or, better, a seccomp or AppArmor profile that stops gs from calling execve or connect at all.

Deploying the rules

Grab the YAML from GitHub and convert it with sigma-cli. The Linux rules use Sysmon for Linux field names (Image, ParentImage, CommandLine, User), so either your data already uses those names or you add a small custom pipeline that maps them to auditd, ECS or your EDR schema. Converting without a pipeline, as below, keeps the Sysmon names. The Zeek rule uses native Zeek field names.

sigma convert -t splunk --without-pipeline proc_creation_lnx_ghostscript_spawns_shell_or_tool.yml
sigma convert -t lucene --without-pipeline net_connection_lnx_ghostscript_outbound_connection.yml
sigma convert -t lucene -p ecs_zeek_beats zeek_http_upload_postscript_disguised_as_image_or_pdf.yml

Check the converted queries by hand, especially the |re modifiers and the array fields, because backends treat both differently. Run every rule in alert-only mode for a week before it pages anyone, and use the lab tests above to prove each one fires in your SIEM rather than just compiles.

My take

This is one of the more detectable bugs I’ve written rules for, as long as you have process telemetry on the boxes that render files. That’s the catch. Thumbnailing workers, print servers and webmail hosts are exactly the machines that tend to get no EDR and no Sysmon, because nobody thinks of them as exposed. If you only do one thing, put process-creation logging on those hosts and turn on the gs-spawns-shell rule. It’s cheap, it’s quiet, and it will catch the next -dSAFER escape too, not just this one.

I’d also argue the best “detection” here is prevention that leaves a log. A seccomp or AppArmor profile that stops gs from executing anything turns a successful exploit into a denied syscall in the audit log, and that’s a better alert than any of my five rules. Ghostscript distributions could ship such a profile by default. Until they do, the process tree is your best bet.

Sources

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