Web shells and remote code execution: how servers get taken over and how defenders find it
The bug classes that lead to code execution on a web server, what a web shell is and how it is planted, the file, process, and log evidence defenders hunt for, and how to respond. Defensive only; no shells or exploit modules.
Diagram
From a bug to persistent access
Step 1 of 4
Bug
Unrestricted upload, deserialization, template injection, command injection, or an unpatched framework.
# Bug # Unrestricted upload, deserialization, template # injection, command injection, or an unpatched framework.
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Uploads that execute
- What fails
- An upload stored under the web root with an executable extension becomes code.
- Who is affected
- The whole server and the data it can reach.
- What you would notice
- User uploads served from the same origin and folder as the application.
- What you change
- Store uploads outside the web root, rename them, serve from a separate domain, and never execute them.
Process lineage tells
- What fails
- Web servers rarely need to start shells or network tools.
- Who is affected
- The host and its credentials.
- What you would notice
- w3wp.exe, httpd, php-fpm, or java spawning cmd.exe, sh, powershell, or curl.
- What you change
- Alert on that lineage and block it with application control where possible.
Patch the framework
- What fails
- Many takeovers use known bugs in frameworks and appliances.
- Who is affected
- Every internet-facing instance on an old release.
- What you would notice
- A KEV-listed CVE in a public-facing framework version.
- What you change
- Patch internet-facing apps on the KEV timeline and keep an inventory of versions.
Hunting for a planted shell
Compare the deployed files against the release artifact or version control; anything extra is suspect. Look for recently modified scripts in upload, cache, and static folders, and for access-log entries where a static-looking path receives POST requests with 200 responses.
$ git -C /var/www/app status --porcelain ?? public/uploads/cache/img_thumb.php <- not in the release $ grep "POST /uploads/cache/img_thumb.php" /var/log/nginx/access.log | head -3 198.51.100.23 - - [02/Nov/2026:03:14:07] "POST /uploads/cache/img_thumb.php HTTP/1.1" 200 412
Responding
Isolate the host, preserve the web root, logs, and memory, identify the entry bug from logs around the file’s creation time, rotate every secret the application could read, and redeploy from a clean build. Deleting the file alone leaves the entry bug and any second shell.
About offensive frameworks
Penetration-testing frameworks and web-shell tools exist and appear in older tutorials. In an engagement they are used only under explicit scope, and the report focuses on the entry bug and the fix. This page stays on the defender’s side.
Check yourself
Recognition and the fix. Nothing here is a procedure.
php-fpm spawns /bin/sh which runs curl. What should a detection rule do?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.