Home / Blog / Incident Response

Intermediate Incident Response

How to Scope a Web Shell Incident on a Client IIS Server

Confirm a web shell, collect IIS and endpoint evidence, find first access and every command run, then contain and report to the client with a clear timeline.

A web shell gives an attacker a command line on your client's web server through ordinary HTTP requests, and it often survives password resets and patching. When an alert fires, the client wants three answers fast: how did they get in, what did they do, and is it over?

This guide walks incident responders in an MSP through scoping a web shell on a Windows IIS server, from the first alert to the client report.

TechniquesT1505.003 Web Shell, T1190 Exploit Public-Facing Application, T1059.003 Windows Command Shell
EvidenceIIS W3C logs, EDR process and file events, the shell file itself
GoalA defensible timeline from first access to containment
>

Scenario: Defender for Endpoint raises an alert for a client: on WEB-07, an internet facing IIS server running the client's customer portal, w3wp.exe has spawned cmd.exe, which ran whoami and nltest /dclist:. The client's IT manager asks whether they should just reboot the server. Your job is to answer the three questions before anything gets wiped.

Confirm the alert is a web shell

The IIS worker process, w3wp.exe, serves web requests. It has little reason to start command shells or discovery tools, so a parent and child pair like w3wp.exe to cmd.exe is the classic web shell signal that MITRE ATT&CK describes for T1505.003. Some applications do legitimately launch helper processes, so check before you declare an incident.

Defender XDR advanced huntingKQL
DeviceProcessEvents
| where Timestamp > ago(30d)
| where DeviceName startswith "WEB-07"
| where InitiatingProcessFileName =~ "w3wp.exe"
| where FileName in~ ("cmd.exe", "powershell.exe", "pwsh.exe", "whoami.exe", "net.exe", "net1.exe", "nltest.exe", "certutil.exe", "rundll32.exe", "reg.exe", "systeminfo.exe")
| project Timestamp, AccountName, FileName, ProcessCommandLine, InitiatingProcessCommandLine
| order by Timestamp asc

The InitiatingProcessCommandLine for w3wp.exe contains the -ap argument naming the application pool. That tells you which site was abused, which matters on servers hosting several client applications.

Who ran itThe app pool identity, such as IIS APPPOOL\PortalPool, shows what rights the attacker inherited.
What ranDiscovery commands such as whoami, nltest and net group suggest hands on keyboard activity.
When it startedThe earliest child process gives you a first anchor for the timeline.
!

Watch out: Ask the client not to reboot, recycle the app pool or delete files yet. A reboot clears the worker process memory, which may hold an in memory shell that never touched disk, and deleting the file destroys your best evidence.

Preserve the evidence before you contain

Agree the order with the client in writing, then collect. In a multi client MSP, work from a case folder per client and record every action with a UTC time, because IIS W3C logs and Defender both record time in UTC.

  1. 1
    Volatile firstCollect an EDR investigation package or memory capture, including the w3wp.exe process.
    IR lead
  2. 2
    IIS logsCopy every W3SVC folder, not just today's file, and hash the copies.
    IR analyst
  3. 3
    Web rootCopy the site folder, web.config files and any suspicious scripts with their timestamps.
    IR analyst
  4. 4
    Windows logsExport Security, System and application logs, plus Sysmon if installed.
    IR analyst

IIS writes W3C logs to %SystemDrive%\inetpub\logs\LogFiles by default, in one W3SVC folder per site ID, with daily files named u_exYYMMDD.log. The client may have moved them, so confirm the path in IIS Manager under Logging.

Run as administrator on WEB-07PowerShell
$case = 'E:\IR\CLIENT-ACME\CASE-0412'
New-Item -ItemType Directory -Path "$case\iislogs", "$case\webroot" -Force | Out-Null
Copy-Item -Path 'C:\inetpub\logs\LogFiles\*' -Destination "$case\iislogs" -Recurse
Copy-Item -Path 'C:\inetpub\wwwroot\*' -Destination "$case\webroot" -Recurse
Get-ChildItem -Path $case -Recurse -File |
    Get-FileHash -Algorithm SHA256 |
    Export-Csv -Path "$case\hashes.csv" -NoTypeInformation
+

Tip: Write the collection to removable or network storage, never to the system drive of the server you are investigating. Writing to the same disk can overwrite deleted files you may later want to recover.

Find the shell file and how it arrived

Next, find the script that answered the attacker's requests. Look for script files written by the web server process itself, which usually means an upload feature or a vulnerability was used to drop them.

Defender XDR advanced huntingKQL
DeviceFileEvents
| where Timestamp > ago(90d)
| where DeviceName startswith "WEB-07"
| where ActionType in ("FileCreated", "FileModified", "FileRenamed")
| where FileName matches regex @"(?i)\.(aspx|ashx|asmx|asp|cshtml|config)$"
| where InitiatingProcessFileName in~ ("w3wp.exe", "cmd.exe", "powershell.exe", "certutil.exe")
| project Timestamp, FolderPath, SHA1, InitiatingProcessFileName, InitiatingProcessCommandLine
| order by Timestamp asc

Folders such as aspnet_client, upload directories and image folders are common hiding places because nobody reviews them. A shell file written by w3wp.exe points to an upload or exploitation path (T1190). One written by cmd.exe or powershell.exe suggests the attacker already had access and planted a second, backup shell.

i

Note: Attackers often change file timestamps to blend in. Trust the EDR file event time and the first IIS log request over the timestamps shown in Explorer.

Reconstruct activity from the IIS logs

The IIS logs are where scoping really happens. Search for every request to the shell, note the client IPs, then pivot on those IPs to find the earliest request of any kind, which is often the exploit itself.

Microsoft Sentinel

If the client sends IIS logs to Sentinel, they land in the W3CIISLog table.

Microsoft Sentinel, shell requestsKQL
let shell = "/aspnet_client/system_web/err.aspx";
W3CIISLog
| where TimeGenerated > ago(90d)
| where csUriStem =~ shell
| summarize Requests = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated), Methods = make_set(csMethod), Statuses = make_set(scStatus), Agents = make_set(csUserAgent, 5) by cIP, Computer
| order by FirstSeen asc
Microsoft Sentinel, attacker IP pivotKQL
let attackerIPs = dynamic(["203.0.113.45", "198.51.100.17"]);
W3CIISLog
| where TimeGenerated > ago(90d)
| where cIP in (attackerIPs)
| summarize Requests = count(), FirstSeen = min(TimeGenerated), Statuses = make_set(scStatus) by csUriStem, csMethod
| order by FirstSeen asc

Splunk

Splunk, Microsoft IIS add-onSPL
index=iis cs_uri_stem="/aspnet_client/system_web/err.aspx"
| stats count, min(_time) as first_seen, max(_time) as last_seen, values(cs_method) as methods, values(sc_status) as statuses by c_ip, host
| convert ctime(first_seen) ctime(last_seen)
| sort first_seen

Raw logs from the collection

Analysis workstationPowerShell
Get-ChildItem -Path 'E:\IR\CLIENT-ACME\CASE-0412\iislogs' -Recurse -Filter 'u_ex*.log' |
    Select-String -Pattern 'err\.aspx|203\.0\.113\.45' |
    Select-Object Filename, LineNumber, Line |
    Export-Csv -Path 'E:\IR\CLIENT-ACME\CASE-0412\shell_hits.csv' -NoTypeInformation
!

Watch out: If the server sits behind a load balancer, WAF or reverse proxy, c-ip shows the proxy address, not the attacker. Check whether the client logs the X-Forwarded-For header as a custom field, or pull the matching logs from the WAF.

Most web shells take commands in a POST body, which IIS does not log, so the logs show when the shell was used but not always what was sent. Match each POST time against the w3wp.exe child processes from the first query to recover the actual commands.

Contain without tipping off the attacker

Once the timeline and scope are clear, contain in one coordinated step so the attacker cannot react halfway through.

Shell used for discovery or lateral movement

High
Indicator

Commands such as nltest, net group or connections from WEB-07 to domain controllers and internal servers.

Response

Isolate the host with EDR, reset the app pool identity and any credentials seen, and widen scope to every system it touched.

Configuration or secrets exposed

High
Indicator

web.config read or copied, connection strings or the ASP.NET machine key visible to the attacker.

Response

Rotate database credentials and the machine key, since a stolen key can let an attacker re enter through ViewState even after the shell is gone.

Shell present but barely used

Medium
Indicator

A few requests, no child processes beyond basic discovery, no outbound connections.

Response

Block attacker IPs at the WAF, remove the shell after preserving it, patch the entry point and monitor closely.

  • Preserve the shell file and its hash before removing it.
  • Hunt the shell's SHA1 and file name across every web server you manage for this client.
  • Close the entry point: patch the vulnerable component or disable the abused upload feature.
  • Recycle the app pool and confirm no new w3wp.exe children appear afterwards.
  • Keep enhanced monitoring on the server for at least two weeks.

Report the timeline to the client

The client needs a report a manager can read and an engineer can act on. Build it from the timeline, with every entry backed by a log line or query result.

Level 1

Initial update

What was found, what you have asked them not to touch, and when the next update will come.

Within the agreed SLA
Level 2

Scoping summary

Entry point, first access time, commands run, systems touched and containment status.

Once scope is confirmed
Level 3

Final report

Full UTC timeline, evidence list with hashes, root cause, data exposure assessment and hardening actions.

Supports their regulatory decisions

Be explicit about what you could not prove. If POST bodies were not logged, say so, and state whether data access can be ruled out or only judged unlikely. That distinction drives the client's decision on breach notification, which is theirs to make with their own advisers.

Key takeaways

  1. w3wp.exe spawning shells or discovery tools is the core web shell signal; confirm it before declaring an incident.
  2. Stop the client rebooting or deleting anything until memory, IIS logs and the web root are preserved.
  3. Find the shell through file events written by w3wp.exe, then pivot on IPs in the IIS logs to find first access.
  4. Check for proxies hiding the real client IP and remember POST bodies are not logged.
  5. Contain in one step, rotate exposed secrets including the machine key, and report a timeline the client can act on.

Web shell incidents reward patience. Preserve first, scope from the logs, and contain once you know the full picture, and the client gets clear answers to how the attacker got in, what they did and whether it is really over.

Written by Chris, Lead IR Consultant, MSP

Keep going

More in Incident Response