A web shell is a malicious script uploaded to a web server that provides attackers with remote command execution, persistent access, and control over compromised systems.
A web shell is a malicious server-side script that provides attackers with a web-based interface for executing operating system commands on compromised web servers. Written in languages like PHP, ASP, JSP, or Python, web shells enable persistent remote access, file management, database interaction, and lateral movement. They are a primary post-exploitation tool because they leverage existing web server infrastructure, blending with legitimate web traffic.
Attackers deploy web shells through unrestricted file upload vulnerabilities, SQL injection enabling file write operations, remote code execution exploits, compromised CMS plugins or themes, exploited web server misconfigurations, server-side template injection, and deserialization vulnerabilities. Supply chain attacks on website components can also introduce web shells. Once deployed, web shells persist until specifically detected and removed during incident response.
Web shells provide attackers with operating system command execution, file system browsing and manipulation, database query execution, network reconnaissance and pivoting, credential harvesting, additional malware deployment, log manipulation to cover tracks, and reverse shell establishment for interactive sessions. Advanced web shells include authentication mechanisms, encrypted communications, and modular functionality for extended post-exploitation operations.
Detect web shells through file integrity monitoring identifying unauthorized server-side scripts, web access log analysis for unusual URL patterns with command parameters, endpoint detection monitoring web server process behavior, network traffic analysis identifying command-and-control patterns, YARA rule scanning for known web shell signatures, behavioral analysis detecting web server processes spawning system commands, and regular comparison of deployed files against known-good baselines.
Common web shell families include China Chopper (minimal 73-byte PHP shell), WSO (Web Shell by Orb with file manager interface), b374k (feature-rich PHP shell), c99 and r57 (classic PHP web shells), ASPXSpy for .NET servers, and JspSpy for Java application servers. Advanced variants include memory-resident web shells that exist only in server processes and fileless web shells operating through server configuration modifications.
Prevent web shell deployment through secure file upload validation restricting allowed file types and content, web application firewall rules detecting shell upload attempts, principle of least privilege for web server file system permissions, disabling unnecessary server-side scripting engines, implementing content security policies, conducting regular source code and file integrity audits, patching CMS platforms and plugins promptly, and deploying runtime application protection.
Remove web shells by first preserving forensic evidence including the shell file, access logs, and system artifacts. Identify the deployment vector to prevent redeployment. Search for additional shells using YARA rules and file integrity comparison. Remove all identified shells and verify through rescanning. Patch the vulnerability that enabled deployment. Reset compromised credentials. Monitor for reappearance and suspicious post-removal activity indicating additional persistence mechanisms.
Web shells are difficult to detect because they use the same scripting languages as legitimate application code, communicate over standard HTTP/HTTPS ports blending with normal traffic, can be as small as a single line of code, may be obfuscated using encoding and encryption, can be embedded within legitimate files as modifications, operate within existing web server processes without creating new ones, and increasingly use fileless techniques residing only in memory.