Webshells are web scripts (PHP/ASPX/etc.) that act as a control panel for the server running them. A webshell may be legitimately used by the administrator to perform actions on the server, such as:
Create a user
Restart a service
Clean up disk space
Therefore, a webshell simplifies server management for administrators that are not familiar with (or are less comfortable with) internal system commands using the console. However, webshells have bad connotations as well – they are a very popular post-exploitation tool that allow an attacker to gain full system control.
An example of a webshell may be as simple as the following script:
<?php echo(system($_GET["q"])); ?>
This script will read a user-provided value and pass it on to the underlying operating system as a shell command. For instance, issuing the following request will invoke the ‘ls’ command and print the result to the screen: http://example.com/webshell.php?q=ls
An even simpler example for a webshell may be this:
From this point, the options are limitless. An attacker that uses a webshell on a compromised server effectively has full control over the application. If the web application is running under root – the attacker has full control over the entire web server as well. In many cases, the neighboring servers on the local network are at risk as well.
How does a webshell attack work?
We’ve now seen that a webshell script is a very powerful tool. However, a webshell is a “post-exploitation” tool – meaning an attacker first has to find a vulnerability in the web application, exploit it, and upload their webshell onto the server. One way to achieve this is by first uploading the webshell through a legitimate file upload page (for instance, a CV submission form on a company website) and then using an LFI (Local File Include) weakness in the application to include the webshell in one of the pages.
A different approach may be an application vulnerable to arbitrary file write. An attacker may simply write the code to a new file on the server.
From the readme: This PHP Shell is a useful tool for system or web administrator to do remote management without using cpanel, connecting using ssh, ftp etc. All actions take place within a web browser
Search file, file content, folder (also using regex)
Once we get the webshell up and running, we can view information and perform actions on the server. Listed below are a few use cases for this webshell that will demonstrate the power of webshells and how attackers can benefit from running them on a compromised web server:
View process information and varied system information.
Open a terminal and execute various commands, or open a code evaluator to run arbitrary code.
Open a reverse shell on the server, to make sure access to the server is preserved. Issue outgoing HTTP requests from the server.
Perform social engineering activities to broaden the scope of the attack.
Mitigation using F5 ASM
The F5 ASM module uses detection and prevention methods for each variation of this attack.
For RFI (Remote File Include):
ASM will detect any request that attempts to include an external URL, and prevent access.
For Unrestricted File Upload + LFI (Local File Include):
During upload or creation attempt of the webshell, ASM will detect the active code and prevent it from reaching the server.
If the webshell is already on the server, ASM will detect when the application tries to reach the file using LFI and prevent access.
If the webshell is already on the server and part of the application, ASM will detect when a suspicious page is requested, and prevent that page from being displayed.