Detecting Impacket with Wazuh

Impacket is a collection of Python-based scripts designed for manipulating network protocols and exploiting Windows services. It contains several tools for remote service execution, Kerberos manipulation, Windows credential dumping, packet sniffing, and relay attacks.
Although Red teamers use Impacket for authorized testing, threat actors frequently misuse it for lateral movement, privilege escalation, and data exfiltration while remaining undetected. Its ability to mimic legitimate network activity makes detection and mitigation challenging. This strategy allows attackers to blend into normal system operations. Impacket has several modules tailored for specific attack techniques:
This blog post explores how to simulate realistic attacks on Windows endpoints using Impacket and demonstrates how Wazuh can monitor and detect such malicious activities.
We use the following infrastructure to demonstrate the detection of Impacket with Wazuh.
In this section, we configure the Windows 11 endpoint to forward Sysmon logs to the Wazuh server. We also enable remote administration services to facilitate the attack simulation.
Run the commands below on the Windows 11 endpoint in PowerShell with Administrator privileges to install Sysmon and forward the logs to the Wazuh server:
Sysmon
folder in the endpoint C:\
folder:> New-Item -ItemType Directory -Path C:\Sysmon
C:\Sysmon
folder:> Expand-Archive -Path "<PATH>\Sysmon.zip" -DestinationPath "C:\Sysmon"
Replace <PATH>
with the directory where the Sysmon.zip
file was downloaded.
C:\Sysmon
folder using the PowerShell command below:> wget -Uri https://wazuh.com/resources/blog/emulation-of-attack-techniques-and-detection-with-wazuh/sysmonconfig.xml -OutFile C:\Sysmon\sysmonconfig.xml
> cd C:\Sysmon > .\Sysmon64.exe -accepteula -i sysmonconfig.xml
<ossec_config>
block of the C:\Program Files (x86)\ossec-agent\ossec.conf
file of the Wazuh agent:<localfile> <location>Microsoft-Windows-Sysmon/Operational</location> <log_format>eventchannel</log_format> </localfile>
> Restart-Service -Name wazuh
Run the following commands on the Windows 11 endpoint in PowerShell with Administrator privileges to enable the Windows remote administration services:
<WINDOWS_USERNAME>
with your username and <WINDOWS_PASSWORD>
with the desired password:> net user <WINDOWS_USERNAME> <WINDOWS_PASSWORD>
> Set-NetFirewallRule -DisplayName "File and Printer Sharing (SMB-In)" -Enabled True > Restart-Service lanmanserver > Enable-WindowsOptionalFeature -Online -FeatureName "SMB1Protocol" -NoRestart > Set-Service -Name WinRM -StartupType Automatic > Start-Service -Name WinRM
> Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "LocalAccountTokenFilterPolicy" -Value 1
> net start RpcSs > net start RpcLocator > net start DcomLaunch > New-NetFirewallRule -DisplayName "Allow RPC" -Direction Inbound -Protocol TCP -LocalPort 135 -Action Allow > New-NetFirewallRule -DisplayName "Allow RPC Dynamic Ports" -Direction Inbound -Protocol TCP -LocalPort 49152-65535 -Action Allow
Wazuh has several out-of-the-box rules for detecting activities related to the use of Impacket. However, we write a few more rules to match the events more accurately and improve the detection confidence.
Perform the following steps on the Wazuh server to create the detection rules:
/var/ossec/etc/rules/local_rules.xml
file:<group name="impacket,"> <rule id="110010" level="12"> <if_sid>92069,92052</if_sid> <field name="win.eventdata.parentimage" type="pcre2">(?i)\\wmiprvse\.exe$|\\mmc\.exe$|\\explorer\.exe$|\\services\.exe$</field> <field name="win.eventdata.commandline" type="pcre2">(?i)cmd\.exe \/Q \/c</field> <description>Suspicious remote command execution via $(win.eventdata.parentimage).</description> <mitre> <id>T1047</id> <id>T1021.003</id> </mitre> </rule> <rule id="110011" level="8"> <if_sid>61613</if_sid> <field name="win.eventdata.image" type="pcre2">(?i)\\svchost\.exe$</field> <field name="win.eventdata.targetfilename" type="pcre2">(?i)\\Windows\\\\*System32\\\\*\w{8}\.tmp$|\\Windows\\\\*temp\\\\*\w{8}\.tmp$</field> <description>Possible attempt to dump credentials. svchost.exe created a temporary file $(win.eventdata.targetfilename).</description> <mitre> <id>T1003</id> </mitre> </rule> </group>
Where:
110010
detects potential lateral movement using Windows Management Instrumentation (WMI). It detects the usage of Impacket WMIexec or SMBExec modules, commonly used in remote administrative tasks and offensive operations.110011
triggers when svchost.exe creates a temporary file with an eight-character name in the C:\Windows\System32\
or the C:\Windows\Temp\
directory, indicative of the execution of the Impacket Secretsdump module.# systemctl restart wazuh-manager
This attack simulation demonstrates how malicious activities using Impacket tools are performed and subsequently detected by Wazuh. In this blog post, we use wmiexec.py
, secretsdump.py
, and smbexec.py
to execute remote commands, enumerate users, and dump credentials. Perform the following steps to test the configurations and observe how Wazuh detects these activities.
Note
Perform this only within a controlled environment.
Note
As a prerequisite, ensure that you have Python3, Pip, and Git installed on the Ubuntu endpoint.
Run the following commands on the Ubuntu endpoint to clone the Impacket repository and install the required Python modules:
# git clone https://github.com/fortra/impacket.git # cd impacket # python3 -m pip install .
Launch the following attacks from the attacker endpoint (Ubuntu) in the directory where Impacket is located. Replace <WINDOWS_USERNAME>
, <WINDOWS_PASSWORD>
, and <WINDOWS_IP_ADDRESS>
with the credentials of the target Windows endpoint:
wmiexec.py
:# python3 examples/wmiexec.py <WINDOWS_USERNAME>:<WINDOWS_PASSWORD>@<WINDOWS_IP_ADDRESS>
Verify access by running basic Windows commands on the spawned shell:
C:\> whoami C:\> ipconfig
secretsdump.py
:# python3 examples/secretsdump.py <WINDOWS_USERNAME>:<WINDOWS_PASSWORD>@<WINDOWS_IP_ADDRESS>
smbexec.py
:# python3 examples/smbexec.py <WINDOWS_USERNAME>:<WINDOWS_PASSWORD>@<WINDOWS_IP_ADDRESS>
You will gain semi-interactive shell access with NT Authority\System
privilege.
Confirm system access by running basic Windows commands on the spawned shell:
C:\Windows\system32> whoami C:\Windows\system32> ipconfig
When the attack is executed against the monitored Windows endpoint, the Wazuh manager detects the activity and triggers alerts visible on the Wazuh dashboard.
In the image below, the alerts are generated from the execution of wmiexec.py
. Some are triggered by in-built rules of Wazuh that flag remote logon events and suspicious Windows cmd shell activities. The alerts with rule ID 110010
provide high-confidence indicators of Impacket execution.
wmiexec.py
.The next image shows alerts with rule ID 110011
triggered by the execution of secretsdump.py
. This custom rule is triggered when svchost.exe
creates a temporary file. This behavior is commonly associated with secretsdump.py
. Additionally, there is an alert indicating a possible pass-the-hash attack, triggered by the attacker’s login method used to perform the credential dump.
secretsdump.py
.The image below shows alerts triggered by the execution of smbexec.py
, reflecting similar patterns to those observed with wmiexec.py
.
smbexec.py
.Wazuh provides capabilities for detecting malicious activities related to Impacket, leveraging both out-of-the-box and custom rules to identify suspicious behavior. The built-in rules detect remote logon events and Windows cmd shell execution associated with Impacket. By creating custom rules tailored to specific attack indicators, we improved detection confidence, especially for high-risk activities such as credential dumping and lateral movement.
This blog post demonstrates how Wazuh serves as a valuable solution for threat detection, helping security teams detect stealthy attacks that mimic legitimate network behavior. Our previous blog posts listed below show how versatile Wazuh is in enhancing organizational defense strategies.
As attackers continue to evolve their methods, combining simulation exercises with real-time monitoring solutions like Wazuh ensures that organizations can stay ahead of emerging threats and improve their security posture.