T1505.003

Web Shell

Adversaries install web shells on compromised web servers to maintain persistent access. A web shell is a script (PHP, ASP, ASPX, JSP, etc.) that provides command execution, file upload/download, and network proxying capabilities via HTTP. Web shells are used by dozens of threat groups including APT28, APT39, HAFNIUM, OilRig, GALLIUM, and Sandworm. China Chopper and P.A.S. Webshell are widely-used examples. IcedID, WIREFIRE, and BUSHWALK target specific appliances (Ivanti VPN).

Microsoft Sentinel / Defender
kusto
// T1505.003 — Web Shell detection
// Web shells executed via web server processes spawning OS commands
// Part 1: Detect web server processes spawning shells/utilities (primary web shell signal)
let WebServerProcesses = dynamic(["w3wp.exe", "httpd.exe", "nginx.exe", "php.exe",
                                   "php-cgi.exe", "tomcat.exe", "catalina.exe",
                                   "java.exe", "javaw.exe", "wsgi.py"]);
let SuspiciousChildren = dynamic(["cmd.exe", "powershell.exe", "wscript.exe", "cscript.exe",
                                   "mshta.exe", "rundll32.exe", "regsvr32.exe", "certutil.exe",
                                   "bitsadmin.exe", "msiexec.exe", "whoami.exe", "net.exe",
                                   "net1.exe", "ipconfig.exe", "systeminfo.exe", "wmic.exe",
                                   "nltest.exe", "netstat.exe", "ping.exe", "nslookup.exe"]);
let WebShellSpawn = DeviceProcessEvents
| where Timestamp > ago(24h)
| where InitiatingProcessFileName has_any (WebServerProcesses)
| where FileName has_any (SuspiciousChildren)
| extend DetectionType = "WebServer_Shell_Spawn"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine,
          InitiatingProcessFileName, InitiatingProcessCommandLine, DetectionType;
// Part 2: Detect suspicious script files written to web directories
let WebDirPaths = dynamic(["\\inetpub\\", "\\wwwroot\\", "\\htdocs\\",
                            "\\www\\", "\\public_html\\", "\\webapps\\"]);
let WebShellExtensions = dynamic([".asp", ".aspx", ".ashx", ".asmx",
                                   ".php", ".jsp", ".jspx", ".cfm", ".shtml"]);
let WebShellDrop = DeviceFileEvents
| where Timestamp > ago(24h)
| where ActionType in ("FileCreated", "FileModified")
| where FolderPath has_any (WebDirPaths)
| where FileName has_any (WebShellExtensions)
| where InitiatingProcessFileName !in~ ("w3wp.exe", "httpd.exe", "nginx.exe", "php.exe")
| extend DetectionType = "WebShell_File_Drop"
| project Timestamp, DeviceName, AccountName, FileName, FolderPath,
          InitiatingProcessFileName, InitiatingProcessCommandLine, DetectionType;
// Part 3: Detect web shell pattern in IIS logs via network connections from w3wp.exe
let WebShellNetwork = DeviceNetworkEvents
| where Timestamp > ago(24h)
| where InitiatingProcessFileName in~ ("w3wp.exe", "php.exe", "php-cgi.exe", "httpd.exe")
| where RemoteIPType == "Public"
| where RemotePort !in (80, 443, 8080, 8443)
| extend DetectionType = "WebServer_External_Connection"
| project Timestamp, DeviceName, AccountName, RemoteIP, RemotePort,
          InitiatingProcessFileName, DetectionType;
union WebShellSpawn, WebShellDrop, WebShellNetwork
| sort by Timestamp desc
critical severity high confidence

Data Sources

Process: Process Creation File: File Creation Network Traffic: Network Connection Microsoft Defender for Endpoint

Required Tables

DeviceProcessEvents DeviceFileEvents DeviceNetworkEvents

False Positives

  • IIS application pools that legitimately use cmd.exe for application integration (rare but exists in legacy systems)
  • PHP or JSP applications that use exec() or shell_exec() for legitimate system operations (image processing, file conversion)
  • Legitimate web deployment pipelines (CI/CD) that write files to web directories as part of automated deployment
  • System administration scripts that run under the IIS application pool identity for configuration management

Unlock Pro Content

Get the full detection package for T1505.003 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections