Hunting for Persistence via WMI Subscriptions
When to Use
- When proactively searching for fileless persistence mechanisms in Windows environments
- After threat intelligence reports indicate WMI-based persistence by APT groups (APT29, APT32, FIN8)
- When investigating systems where malware persists across reboots despite cleanup attempts
- During incident response when standard persistence locations (Run keys, scheduled tasks) are clean
- When WmiPrvSe.exe is observed spawning unexpected child processes
Detection Gaps & Validation
- Without Sysmon EID 19/20/21, you're relying on Event 5861 alone — and 5861 logs permanent consumer creation but not all filter activity, so partial visibility produces false-negative "clean" results.
- Payload lives in the consumer/filter properties (fileless): an
ActiveScriptEventConsumer carries the VBScript inline, so no child process appears until the trigger fires — process-only hunts miss dormant subscriptions.
- Non-standard consumers and namespaces evade
root\subscription enumeration: LogFileEventConsumer, NTEventLogEventConsumer, and subscriptions placed in root\default instead of root\subscription.
- Intrinsic-event timers look benign:
__InstanceModificationEvent on Win32_LocalTime/Win32_PerfFormattedData is a common timed trigger (FIN8-style) that resembles normal polling.
- Validate the hunt fires: install a test
__EventFilter + CommandLineEventConsumer binding via PowerShell or mofcomp.exe (Atomic Red Team T1546.003); confirm Sysmon EID 19/20/21 and Event 5861 fire and the WmiPrvSe child process is detected.
- FP tuning: SCCM, antivirus, and monitoring agents create legitimate permanent subscriptions — baseline existing bindings per host and alert only on new/unsigned ones.
Prerequisites
- Sysmon Event ID 19, 20, 21 (WMI Event Filter/Consumer/Binding) enabled
- Windows Event ID 5861 (WMI activity logging) from Microsoft-Windows-WMI-Activity
- PowerShell logging enabled (Script Block Logging, Module Logging)
- WMI repository access for enumeration
- SIEM platform for event correlation
Workflow
- Enumerate Existing WMI Subscriptions: Query all permanent WMI event subscriptions on target systems. A clean system typically has very few or zero permanent subscriptions, making anomalies easy to spot.
- Monitor WMI Event Creation (Sysmon 19/20/21): Sysmon Event 19 captures WmiEventFilter activity, Event 20 captures WmiEventConsumer activity, and Event 21 captures WmiEventConsumerToFilter binding.
- Analyze Consumer Types: Focus on ActiveScriptEventConsumer (runs VBScript/JScript) and CommandLineEventConsumer (executes commands) -- these are the dangerous types used for persistence.
- Check Event Filter Triggers: Examine what triggers the subscription. Common malicious triggers include system startup (Win32_ProcessStartTrace), user logon, or timer-based execution intervals.
- Investigate WmiPrvSe.exe Child Processes: When a WMI subscription fires, the action is executed by WmiPrvSe.exe. Hunt for unusual child processes of WmiPrvSe.exe.
- Correlate with MOF Compilation: Detect
mofcomp.exe usage which compiles MOF files to create WMI subscriptions programmatically.
- Validate and Respond: Confirm malicious subscriptions, remove them, and trace back to the initial infection vector.
Key Concepts
| Concept |
Description |
| T1546.003 |
Event Triggered Execution: WMI Event Subscription |
| __EventFilter |
WMI class defining the trigger condition |
| __EventConsumer |
WMI class defining the action to perform |
| __FilterToConsumerBinding |
Links a filter to a consumer |
| ActiveScriptEventConsumer |
Consumer that runs VBScript or JScript |
| CommandLineEventConsumer |
Consumer that executes command lines |
| WmiPrvSe.exe |
WMI Provider Host that executes subscription actions |
| MOF File |
Managed Object Format used to define WMI objects |
Detection Queries
Splunk -- WMI Subscription Creation via Sysmon
index=sysmon (EventCode=19 OR EventCode=20 OR EventCode=21)
| eval event_type=case(EventCode=19, "EventFilter", EventCode=20, "EventConsumer", EventCode=21, "FilterToConsumerBinding")
| table _time Computer User event_type EventNamespace Name Query Destination Operation
Splunk -- WMI Subscription via Windows Event 5861
index=wineventlog source="Microsoft-Windows-WMI-Activity/Operational" EventCode=5861
| table _time Computer NamespaceName Operation PossibleCause
PowerShell -- Enumerate WMI Subscriptions
Get-WmiObject -Namespace root\subscription -Class __EventFilter
Get-WmiObject -Namespace root\subscription -Class __EventConsumer
Get-WmiObject -Namespace root\subscription -Class __FilterToConsumerBinding
KQL -- WmiPrvSe.exe Spawning Suspicious Children
DeviceProcessEvents
| where Timestamp > ago(7d)
| where InitiatingProcessFileName =~ "wmiprvse.exe"
| where FileName in~ ("cmd.exe", "powershell.exe", "wscript.exe", "cscript.exe", "mshta.exe", "rundll32.exe")
| project Timestamp, DeviceName, FileName, ProcessCommandLine
Sigma Rule
title: WMI Event Subscription Persistence
status: stable
logsource:
product: windows
category: wmi_event
detection:
selection_consumer:
EventID: 20
Destination|contains:
- 'ActiveScriptEventConsumer'
- 'CommandLineEventConsumer'
condition: selection_consumer
level: high
tags:
- attack.persistence
- attack.t1546.003
Common Scenarios
- APT29 WMI Persistence: Creates an ActiveScriptEventConsumer that executes a VBScript backdoor on system startup, surviving reboots and credential resets.
- Turla WMI Backdoor: Uses Win32_ProcessStartTrace filter combined with CommandLineEventConsumer for covert command execution.
- FIN8 WMI Timer: Interval-based __IntervalTimerEvent triggering encoded PowerShell downloads every 30 minutes.
- MOF-Based Installation: Adversary drops a .mof file and compiles it with
mofcomp.exe to silently create persistent subscriptions.
Output Format
Hunt ID: TH-WMI-[DATE]-[SEQ]
Host: [Hostname]
Subscription Name: [Filter/Consumer name]
Filter Query: [WQL trigger condition]
Consumer Type: [ActiveScript/CommandLine]
Consumer Action: [Script content or command]
Binding: [Filter-to-Consumer link]
Created: [Timestamp]
User Context: [SYSTEM/User]
Risk Level: [Critical/High/Medium/Low]
1---2name: hunting-for-persistence-via-wmi-subscriptions3description: Hunt for adversary persistence through Windows Management Instrumentation event subscriptions by monitoring WMI consumer, filter, and binding creation events that execute malicious code triggered by system events.4license: Apache-2.05---67# Hunting for Persistence via WMI Subscriptions89## When to Use1011- When proactively searching for fileless persistence mechanisms in Windows environments12- After threat intelligence reports indicate WMI-based persistence by APT groups (APT29, APT32, FIN8)13- When investigating systems where malware persists across reboots despite cleanup attempts14- During incident response when standard persistence locations (Run keys, scheduled tasks) are clean15- When WmiPrvSe.exe is observed spawning unexpected child processes1617## Detection Gaps & Validation1819- **Without Sysmon EID 19/20/21, you're relying on Event 5861 alone** — and 5861 logs permanent consumer creation but not all filter activity, so partial visibility produces false-negative "clean" results.20- **Payload lives in the consumer/filter properties (fileless):** an `ActiveScriptEventConsumer` carries the VBScript inline, so no child process appears until the trigger fires — process-only hunts miss dormant subscriptions.21- **Non-standard consumers and namespaces evade `root\subscription` enumeration:** `LogFileEventConsumer`, `NTEventLogEventConsumer`, and subscriptions placed in `root\default` instead of `root\subscription`.22- **Intrinsic-event timers look benign:** `__InstanceModificationEvent` on `Win32_LocalTime`/`Win32_PerfFormattedData` is a common timed trigger (FIN8-style) that resembles normal polling.23- **Validate the hunt fires:** install a test `__EventFilter` + `CommandLineEventConsumer` binding via PowerShell or `mofcomp.exe` (Atomic Red Team T1546.003); confirm Sysmon EID 19/20/21 and Event 5861 fire and the WmiPrvSe child process is detected.24- **FP tuning:** SCCM, antivirus, and monitoring agents create legitimate permanent subscriptions — baseline existing bindings per host and alert only on new/unsigned ones.2526## Prerequisites2728- Sysmon Event ID 19, 20, 21 (WMI Event Filter/Consumer/Binding) enabled29- Windows Event ID 5861 (WMI activity logging) from Microsoft-Windows-WMI-Activity30- PowerShell logging enabled (Script Block Logging, Module Logging)31- WMI repository access for enumeration32- SIEM platform for event correlation3334## Workflow35361. **Enumerate Existing WMI Subscriptions**: Query all permanent WMI event subscriptions on target systems. A clean system typically has very few or zero permanent subscriptions, making anomalies easy to spot.372. **Monitor WMI Event Creation (Sysmon 19/20/21)**: Sysmon Event 19 captures WmiEventFilter activity, Event 20 captures WmiEventConsumer activity, and Event 21 captures WmiEventConsumerToFilter binding.383. **Analyze Consumer Types**: Focus on ActiveScriptEventConsumer (runs VBScript/JScript) and CommandLineEventConsumer (executes commands) -- these are the dangerous types used for persistence.394. **Check Event Filter Triggers**: Examine what triggers the subscription. Common malicious triggers include system startup (Win32_ProcessStartTrace), user logon, or timer-based execution intervals.405. **Investigate WmiPrvSe.exe Child Processes**: When a WMI subscription fires, the action is executed by WmiPrvSe.exe. Hunt for unusual child processes of WmiPrvSe.exe.416. **Correlate with MOF Compilation**: Detect `mofcomp.exe` usage which compiles MOF files to create WMI subscriptions programmatically.427. **Validate and Respond**: Confirm malicious subscriptions, remove them, and trace back to the initial infection vector.4344## Key Concepts4546| Concept | Description |47|---------|-------------|48| T1546.003 | Event Triggered Execution: WMI Event Subscription |49| __EventFilter | WMI class defining the trigger condition |50| __EventConsumer | WMI class defining the action to perform |51| __FilterToConsumerBinding | Links a filter to a consumer |52| ActiveScriptEventConsumer | Consumer that runs VBScript or JScript |53| CommandLineEventConsumer | Consumer that executes command lines |54| WmiPrvSe.exe | WMI Provider Host that executes subscription actions |55| MOF File | Managed Object Format used to define WMI objects |5657## Detection Queries5859### Splunk -- WMI Subscription Creation via Sysmon60```spl61index=sysmon (EventCode=19 OR EventCode=20 OR EventCode=21)62| eval event_type=case(EventCode=19, "EventFilter", EventCode=20, "EventConsumer", EventCode=21, "FilterToConsumerBinding")63| table _time Computer User event_type EventNamespace Name Query Destination Operation64```6566### Splunk -- WMI Subscription via Windows Event 586167```spl68index=wineventlog source="Microsoft-Windows-WMI-Activity/Operational" EventCode=586169| table _time Computer NamespaceName Operation PossibleCause70```7172### PowerShell -- Enumerate WMI Subscriptions73```powershell74Get-WmiObject -Namespace root\subscription -Class __EventFilter75Get-WmiObject -Namespace root\subscription -Class __EventConsumer76Get-WmiObject -Namespace root\subscription -Class __FilterToConsumerBinding77```7879### KQL -- WmiPrvSe.exe Spawning Suspicious Children80```kql81DeviceProcessEvents82| where Timestamp > ago(7d)83| where InitiatingProcessFileName =~ "wmiprvse.exe"84| where FileName in~ ("cmd.exe", "powershell.exe", "wscript.exe", "cscript.exe", "mshta.exe", "rundll32.exe")85| project Timestamp, DeviceName, FileName, ProcessCommandLine86```8788### Sigma Rule89```yaml90title: WMI Event Subscription Persistence91status: stable92logsource:93 product: windows94 category: wmi_event95detection:96 selection_consumer:97 EventID: 2098 Destination|contains:99 - 'ActiveScriptEventConsumer'100 - 'CommandLineEventConsumer'101 condition: selection_consumer102level: high103tags:104 - attack.persistence105 - attack.t1546.003106```107108## Common Scenarios1091101. **APT29 WMI Persistence**: Creates an ActiveScriptEventConsumer that executes a VBScript backdoor on system startup, surviving reboots and credential resets.1112. **Turla WMI Backdoor**: Uses Win32_ProcessStartTrace filter combined with CommandLineEventConsumer for covert command execution.1123. **FIN8 WMI Timer**: Interval-based __IntervalTimerEvent triggering encoded PowerShell downloads every 30 minutes.1134. **MOF-Based Installation**: Adversary drops a .mof file and compiles it with `mofcomp.exe` to silently create persistent subscriptions.114115## Output Format116117```118Hunt ID: TH-WMI-[DATE]-[SEQ]119Host: [Hostname]120Subscription Name: [Filter/Consumer name]121Filter Query: [WQL trigger condition]122Consumer Type: [ActiveScript/CommandLine]123Consumer Action: [Script content or command]124Binding: [Filter-to-Consumer link]125Created: [Timestamp]126User Context: [SYSTEM/User]127Risk Level: [Critical/High/Medium/Low]128```