How to Evict an Attacker from Active Directory After Detection

Summary
Using a fictional Active Directory scenario, the article shows how to investigate WinRM, Impacket WMIexec and RDP activity, then evict attackers by securing accounts and ending sessions while accounting for the risk of tipping them off.
Key points
- The fictional scenario uses suspicious processes and account activity to investigate possible attacker access to a Windows server.
- WinRM activity can be investigated through logs or server-side session details; disabling the compromised Active Directory account terminates access.
- Impacket WMIexec activity may leave process and ADMIN$ redirection traces. The guidance recommends changing the compromised password twice, disabling the account, and removing administrator privileges.
- RDP investigations can use session telemetry and logs, including the connecting username and source IP; defenders can sign out the user and then secure the account.
- Domain-wide session tools can help identify other accounts and machines where an adversary may be active.
- Before disrupting an attacker, investigate initial access and persistence where possible: intervention may prompt them to cover their tracks or cause damage.
- The article recommends coordinating immediate containment with log review and post-incident security improvements.
Article Details
- Defense Focus
- Detect and evict adversaries using compromised accounts for WinRM, WMIexec, or RDP access, while investigating initial access and persistence before disrupting the attacker when feasible.
- Detection Methods
- Review process and command-line activity, including unexpected whoami or net time execution and output redirection to ADMIN$ or a local SMB share.
- Use Elastic telemetry to identify wsmprovhost.exe spawning commands and to inspect RDP session activity, including the source domain.
- Inspect active PowerShell remoting sessions and their user and session duration.
- Query RDP logs for remote sign-in times, usernames, and source IP addresses.
- Review Windows endpoint prefetch data and enumerate domain-wide user sessions and remote PowerShell sessions.
- Data Sources
- Elastic-collected process and session logs
- Process and command-line data
- PowerShell remoting session information
- RDP logs, including username and source IP address
- Windows endpoint prefetch data
- Active Directory domain-wide user-session information
- Rule Types
- Elastic process-activity detections
- PowerShell one-liners for process and remoting-session inspection
- RDP log queries
- Platforms
- Elastic
- Active Directory
- Windows
- Defensive Actions
- Before disrupting the adversary when circumstances allow, investigate initial access and identify and remove persistence mechanisms; intervene immediately if the adversary reaches key machines or begins destructive activity.
- Disable compromised accounts to terminate or prevent further remote access.
- For suspected WMIexec access, rotate the compromised password twice, disable the account, and remove it from the administrators group.
- Force the compromised RDP user to sign out, then change the password or disable the account.
- Review other accounts and machines for active sessions across the domain.
- Coordinate post-incident IT and security changes to reduce the risk of re-compromise.
MITRE ATT&CK
T1021.001 · Remote Desktop ProtocolThe article describes an adversary using stolen credentials to establish an RDP session to a server.T1021.006 · Windows Remote ManagementThe article describes an adversary using WinRM and PowerShell remoting with a user's credentials to access a server and run commands.T1047 · Windows Management InstrumentationThe article identifies Impacket's WMIexec as using Windows Management Instrumentation to execute commands on a victim machine.T1078 · Valid AccountsThe described remote access through WinRM, WMIexec, and RDP relies on compromised user accounts and their credentials.
People
Products
Elasticexamination, AFairfax’s only running process on the server was wsmprovhost.exe. If we take a look at our Elastic instance, which collects our logs, we see that it has detected that wsmprovhost has spawned a ‘whoami’.Microsoft Active DirectoryGoogling “how to kick out an attacker from my active directory” or “how to kill hacker shell from Windows computer” doesn’t really offer us much advice. And the real kicker is this is the type of advice we defendersMicrosoft WindowsGoogling “how to kick out an attacker from my active directory” or “how to kill hacker shell from Windows computer” doesn’t really offer us much advice. And the real kicker is this is the type of advice we defenders
Tools
Get-RemotePSSession.ps1To dig deeper into this, I’d recommend YossiSassi's Get-UserSession.ps1 and Get-RemotePSSession.ps1.Get-UserSession.ps1To dig deeper into this, I’d recommend YossiSassi's Get-UserSession.ps1 and Get-RemotePSSession.ps1.ImpacketImpacket's WMIexecPowerShellin your Active Directory, but they definitely wouldn’t be working at 2am! You can dig further with some PowerShell to find out what they are currently doing on this server:SharpHoundare legitimate programs (like rdpclip and wsmprovhost.exe), whereas other processes look really bad (sharphound.exe has a strange re-directed relationship with a local SMB share).wmiexecImpacket's WMIexec