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)

  1. Client-side only: intercept in Burp, upload shell.php directly.
  2. Content-Type check: keep .php, set header Content-Type: image/png.
  3. 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 .jpg unhandled, Apache falls back to .php), shell.jpg.php.
    • Legacy truncation: null byte shell.php%00.jpg, IIS semicolon shell.php;.jpg, trailing shell.php. / shell.php%20 / shell.php::$DATA.
  4. Config-file upload (no code extension needed):
    • Apache .htaccess → AddType application/x-httpd-php .jpg, then upload a .jpg web shell.
    • IIS web.config → remap handlers / add an ASP handler.
  5. 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.
  6. Where name is server-controlled: if the server forces a UUID/.png name, 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_FUNCTIONS unset) — upload a malicious XSLT that calls Java Runtime → 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/.pdf name, 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 .png name 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 noexec with 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: attachment and a safe Content-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.

See also: Path Traversal · Zip Slip and Archive Extraction

Sources