This guide shows you how to hunt for web shells and other persistence mechanisms on a Microsoft Exchange Server that may have been compromised. You’ll learn where to look, what patterns indicate malicious activity, and how to confirm your findings. You’ll need administrative access to the server, including the ability to run PowerShell and review IIS logs.
What You’ll Need
- Administrator access to the Exchange Server (local admin or equivalent).
- PowerShell access (preferably with Exchange Management Shell).
- Access to the IIS Manager or the ability to read IIS configuration files.
- A text editor or log parser to review IIS logs.
- Optional: A malware scanner or hash lookup tool (like VirusTotal) to check suspicious files.
Step-by-Step
- Check for known Exchange vulnerabilities. Before hunting for shells, check if the server is patched against known Exchange vulnerabilities (ProxyLogon, ProxyShell, etc.). Use
Get-ExchangeServer | Format-List Name,AdminDisplayVersionto see the build number and compare it with Microsoft’s documented patched versions. Unpatched servers are prime targets. - Search for web shells in IIS web directories. Web shells are typically placed in the
inetpub\wwwroot\aspnet_client,inetpub\wwwroot\owa,inetpub\wwwroot\ecp, orinetpub\wwwroot\exchangefolders. Run the following PowerShell command to list files modified in the last 90 days that have suspicious extensions:Get-ChildItem -Path C:\inetpub\wwwroot -Recurse -Include *.aspx,*.ashx,*.asmx,*.asp,*.jsp,*.php -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-90) } | Select-Object FullName,Length,LastWriteTimeLook for files with random names (e.g.,
aspx_web.aspx,help.aspx) or names that mimic legitimate files but are in wrong locations. - Inspect suspicious file contents. For any files found, open them in a text editor and search for common web shell patterns:
eval(,base64_decode,System.Net.WebClient,Process.Start,cmd.exe,whoami, orResponse.Writewith unusual arguments. Legitimate Exchange files rarely contain these strings. - Check for unauthorized scheduled tasks. Persistence often uses scheduled tasks. Run
Get-ScheduledTask | Where-Object { $_.State -ne 'Disabled' }and review tasks that run as SYSTEM or with high privileges. Look for tasks with random names or that run PowerShell or cmd.exe with encoded commands. - Examine Windows services. Attackers may install a service to maintain access. Run
Get-WmiObject win32_service | Select-Object Name,DisplayName,PathName,StartModeand look for services with unusual paths or names. Pay special attention to services pointing to files inC:\Windows\Temp,C:\Users\Public, or web directories. - Review IIS logs for suspicious requests. IIS logs are in
C:\inetpub\logs\LogFiles\W3SVC1(and other W3SVC folders). Use PowerShell to parse them for requests containing.aspx,.ashx, or.asmxwith query strings likecmd,exec,eval, orbase64:Select-String -Path C:\inetpub\logs\LogFiles\W3SVC1\*.log -Pattern 'cmd|exec|eval|base64|whoami' | Select-Object -First 20Also look for POST requests to unusual .aspx files that you didn’t recognize in step 2.
- Check for new or modified files in Exchange directories. Exchange stores web applications in
C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxyandC:\Program Files\Microsoft\Exchange Server\V15\ClientAccess. Run a recursive scan for files modified in the last 90 days, similar to step 2, but also include .dll and .exe files. - Look for unusual PowerShell history or profile modifications. Check
$PSHistory(if enabled) and the PowerShell profile files ($PROFILE). Attackers may add commands to the profile to run on every PowerShell start. UseGet-Content $PROFILEto see if it contains anything unexpected. - Review registry Run keys. Persistence often uses registry keys. Check the following locations for suspicious entries:
Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'Get-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run'Look for entries pointing to scripts or executables in temp folders.
- Check for new user accounts or modified groups. Attackers may create a backdoor account. Run
Get-LocalUserandGet-LocalGroupMember -Group 'Administrators'to see if any unexpected accounts exist, especially those with$at the end (machine accounts) or with recent password changes.
Common Mistakes
- Only looking in one location. Web shells can be anywhere IIS serves content, not just the default directories. Always scan the entire web root and Exchange directories.
- Ignoring file timestamps. Attackers often modify timestamps to blend in. Don’t rely solely on LastWriteTime; also check CreationTime and LastAccessTime, and compare them.
- Not checking for encoded payloads. Web shells often use base64 or hex encoding to hide their commands. Look for long strings of characters that decode to executable code.
- Forgetting about alternate data streams (ADS). Some shells hide in ADS. Use
Get-Item -Path file -Stream *to check for streams. - Assuming patching is enough. Even patched servers can be compromised if credentials were stolen. Always perform a thorough hunt after any incident.
Tips
- Use a baseline. If you have a known-good image or backup, compare the current state to that baseline to spot changes.
- Enable auditing. Turn on PowerShell logging and process creation auditing (via GPO) to have a trail for future incidents.
- Check all Exchange virtual directories. Use
Get-ECPVirtualDirectory,Get-OABVirtualDirectory, etc., to see if any have been modified or if new ones exist. - Look for suspicious outbound connections. Use
netstat -anoto see if any process is connecting to unknown IPs on unusual ports. Cross-reference the PID with the file path. - Search for common web shell names. Some known shells have predictable names like
cmd.aspx,shell.aspx,webshell.aspx. Use a search for these in addition to pattern-based hunting.
Troubleshooting
- No files found, but you suspect a shell. Check if the server is using a different web root. Open IIS Manager, select the Default Web Site, and click “Explore” to see the actual physical path. Also check if there are other websites on the server.
- PowerShell commands are blocked or slow. If you cannot run PowerShell, use Command Prompt or the IIS Manager GUI to browse directories. For log analysis, you can use
findstrinstead of Select-String. - You find a suspicious file but it’s locked. Use
Unlock-Item(if available) or copy the file to a different location before examining it. Do not delete it immediately; preserve it as evidence. - Scheduled tasks are hidden. Some malware hides tasks using special registry flags. Use
schtasks /query /v /fo LISTto see verbose details, and check theTask Schedulerlibrary underMicrosoft\Windowsfor unusual task names. - Logs are too large to search. Use
Get-ContentwithSelect-Stringand filter by date. Alternatively, use a log parser tool like Log Parser 2.2 to query the logs efficiently.
Frequently Asked Questions
What exactly is a web shell?
A web shell is a small script (usually .aspx, .asp, or .php) that an attacker uploads to a web server to execute commands remotely. It acts as a backdoor, allowing the attacker to run commands, upload files, or pivot to other systems.
How do web shells get onto an Exchange server?
They are typically uploaded via vulnerabilities like ProxyLogon or ProxyShell, which allow unauthenticated remote code execution. Attackers exploit these flaws to write a file to the web root, often via a crafted HTTP request.
Can I detect web shells with antivirus software?
Some AV products can detect known web shells, but many are polymorphic or custom-made. Manual hunting is essential because AV may miss new or obfuscated shells.
What should I do if I find a web shell?
Immediately isolate the server from the network, preserve evidence (copy files and logs), and then follow your incident response plan. Do not delete the shell without forensic analysis, as it may be needed for investigation.
How often should I check for web shells?
After any suspected compromise, and regularly thereafter (e.g., monthly) as part of security maintenance. Also check after applying Exchange updates, as attackers sometimes use known vulnerabilities before patches are applied.
Are there automated tools to scan for web shells?
Yes, there are scripts like the Microsoft Safety Scanner or open-source tools like find-web-shells.ps1 from the PowerShell Gallery. However, these are not foolproof, so manual verification is still recommended.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- How to Choose an Amplifier for Magico A3 Speakers
- How to Ban a Player from Your FiveM Server
- Pokemon Go Friend Codes: How to Add & Use Them33.33 XP/day
- Google Algorithm Change: Original Reporting Boost
- Create Folder for Selected Item on Mac: Full Guide
- Data Center Location Questions for AI Workloads