Web shell
A web shell is a shell-like interface that facilitates remote access to a web server, commonly exploited for cyberattacks. Unlike traditional shells, it is accessed via a web browser, making it a versatile tool for malicious activities.
Web shells can be coded in any programming language supported by a server, with PHP being the most prevalent due to its widespread use in web applications. Other languages, such as Active Server Pages, ASP.NET, Python, Perl, Ruby, and Unix shell scripts, are also employed.
Attackers identify vulnerabilities often in web server application using network monitoring tools, which can be exploited to deploy a web shell.
Once installed, a web shell allows attackers to execute shell commands, perform privilege escalation, and manage files by uploading, deleting, downloading, or executing them on the server.
General usage
Web shells are favored in cyberattacks for their versatility and elusiveness. Common applications include:- Data theft
- Infecting visitors through watering hole attacks
- Website defacement by altering files with malicious intent
- Launching DDoS attacks
- Relaying commands to inaccessible network segments
- Serving as a command and control hub, such as in botnet systems or to compromise external networks
Delivery of web shells
Web shells are deployed by exploiting vulnerabilities in web applications or weak server configurations, including:- SQL injection
- Flaws in applications and services
- File processing and upload vulnerabilities
- Remote file inclusion and local file inclusion vulnerabilities
- Remote code execution
- Exposed administration interfaces
Content-Type header during file uploads to bypass weak file validation, enabling shell deployment.Example
The following is a basic PHP web shell that executes a shell command and displays the output:With a filename of
example.php, the command to display the /etc/passwd file could be:This executes the command
cat /etc/passwd. Such risks can be mitigated by disabling PHP shell functions to prevent arbitrary command execution.Prevention and mitigation
Preventing web shell installation requires addressing server vulnerabilities. Key measures include:- Regularly updating applications and the host server's operating system to patch known bugs
- Implementing a demilitarized zone between web-facing servers and internal networks
- Securing web server configurations
- Closing unused ports and services
- Validating user input to limit local and remote file inclusion vulnerabilities
- Using a reverse proxy to restrict administrative URLs to legitimate sources
- Conducting frequent vulnerability scans
- Deploying a firewall
- Disabling directory browsing
- Avoiding default passwords
Detection
Web shells are challenging to detect due to their modifiability, often evading antivirus software.Indicators of a web shell include:
- Unusually high web server activity from downloading/uploading
- Files with abnormal timestamps
- Unknown files on the server
- Suspicious references
- Unusual connections in server logs
Web shells may include disguised login forms, such as fake error pages.
Attackers can modify the .htaccess file to redirect search engine queries to malware or spam pages, often tailoring content based on user-agent detection. Identifying the shell may require altering the crawler's user-agent, after which it can be easily removed.
Analyzing server logs can pinpoint the web shell's location, as legitimate users typically have diverse user-agents and referers, while attacker access is more uniform.