| ID | Technique | Tactic |
|---|---|---|
| T1546.003 | Windows Management Instrumentation Event Subscription | Persistence |
Detection: WMI Permanent Event Subscription
Description
Detects permanent WMI event subscriptions that are containing CommandLineEventConsumer or ActiveScriptEventConsumer. Due to their command execution capabilties, given WMI consumers are often leveraged by adversaries for both execution and persistence purposes.
Search
1`wmi`
2EventCode=5861
3
4| spath input=_raw output=possible_cause path=Event.UserData.Operation_ESStoConsumerBinding.PossibleCause
5
6| spath input=_raw output=consumer_xml path=Event.UserData.Operation_ESStoConsumerBinding.CONSUMER
7
8| eval possible_cause=coalesce(possible_cause, Message)
9
10| rex field=Message "(?i)Consumer\s*=\s*(?<consumer_message>[^;\r\n]+)"
11
12| eval consumer=coalesce(consumer_xml, consumer_message)
13
14| where isnull(consumer) OR consumer!="NTEventLogEventConsumer=\"SCM Event Log Consumer\""
15
16| rex field=possible_cause "(?ms)instance of __EventFilter\s+\{(?<event_filter>.*?)\};\s*Perm\. Consumer:"
17
18| rex field=event_filter "(?m)^\s*Name\s*=\s*\"(?<filter_name>[^\"]*)\"\s*;"
19
20| rex field=event_filter "(?m)^\s*Query\s*=\s*\"(?<filter_query>.*?)\"\s*;"
21
22| rex field=event_filter "(?m)^\s*EventNamespace\s*=\s*\"(?<filter_event_namespace>[^\"]*)\"\s*;"
23
24| rex field=event_filter "(?m)^\s*QueryLanguage\s*=\s*\"(?<filter_query_language>[^\"]*)\"\s*;"
25
26| rex field=possible_cause "(?s)Perm\. Consumer:\s+instance of (?<consumer_type>[A-Za-z0-9_]+)\s+\{(?<consumer_properties>.*?)\};\s*\Z"
27
28| rex field=consumer_properties "(?m)^\s*Name\s*=\s*\"(?<consumer_name>[^\"]*)\"\s*;"
29
30| rex field=consumer_properties "(?m)^\s*CommandLineTemplate\s*=\s*\"(?<command_line_template>.*?)\"\s*;"
31
32| rex field=consumer_properties "(?m)^\s*RunInteractively\s*=\s*(?<run_interactively>[^;]+)\s*;"
33
34| rex field=consumer_properties "(?m)^\s*ScriptingEngine\s*=\s*\"(?<scripting_engine>[^\"]*)\"\s*;"
35
36| rex field=consumer_properties "(?ms)^\s*ScriptText\s*=\s*\"(?<script_text>.*?)\"\s*;\s*$"
37
38| where consumer_type IN ("CommandLineEventConsumer", "ActiveScriptEventConsumer")
39
40| eval command=coalesce(command_line_template, script_text)
41
42| fillnull value=NULL
43
44| stats count min(_time) as firstTime
45 max(_time) as lastTime
46 values(consumer) as consumer
47 values(consumer_type) as consumer_type
48 values(consumer_name) as consumer_name
49 values(command_line_template) as command_line_template
50 values(run_interactively) as run_interactively
51 values(scripting_engine) as scripting_engine
52 values(script_text) as script_text
53 values(command) as command
54 by Computer, filter_name, filter_query, filter_event_namespace, filter_query_language
55
56| `security_content_ctime(firstTime)`
57
58| `security_content_ctime(lastTime)`
59
60| rename Computer as dest
61
62| `wmi_permanent_event_subscription_filter`
Data Source
| Name | Platform | Sourcetype | Source |
|---|---|---|---|
| Windows Event Log WMI Activity 5861 | 'XmlWinEventLog' |
'XmlWinEventLog:Microsoft-Windows-WMI-Activity/Operational' |
Macros Used
| Name | Value |
|---|---|
| security_content_ctime | convert timeformat="%Y-%m-%dT%H:%M:%S" ctime($field$) |
| wmi_permanent_event_subscription_filter | search * |
wmi_permanent_event_subscription_filter is an empty macro by default. It allows the user to filter out any results (false positives) without editing the SPL.
Annotations
Default Configuration
This detection is configured by default in Splunk Enterprise Security to run with the following settings:
| Setting | Value |
|---|---|
| Disabled | true |
| Cron Schedule | 0 * * * * |
| Earliest Time | -70m@m |
| Latest Time | -10m@m |
| Schedule Window | auto |
| Creates Finding (Notable) | No |
| Creates Intermediate Finding (Risk Event) | Yes |
Implementation
Ingest Microsoft-Windows-WMI-Activity/Operational events and ensure EventCode, Computer, and the raw XML event are available. The search uses spath to extract the binding details, then regex to parse the embedded __EventFilter and the supported CommandLineEventConsumer and ActiveScriptEventConsumer properties. For non-XML rendered events, Message is used as a fallback for the consumer details.
Known False Positives
Administrators and software may use permanent WMI event subscriptions. Review the consumer, filter query, and creator context; tune known authorized subscriptions with the detection filter macro.
Associated Analytic Story
Intermediate Findings
| Message | Entity Field | Entity Type | Risk Score |
|---|---|---|---|
| WMI event filter [$filter_name$] in [$filter_event_namespace$] watches [$filter_query$] and is bound to [$consumer_type$] [$consumer_name$] on [$dest$], which can execute [$command$]. | dest | system | 20 |
Threat Objects
| Field | Type |
|---|---|
| command | command |
References
-
https://learn.microsoft.com/en-us/windows/win32/wmisdk/commandlineeventconsumer
-
https://learn.microsoft.com/en-us/windows/win32/wmisdk/activescripteventconsumer
Atomic Tests
Learn more about Atomic Red Team tests here.
| Atomic Test ID | Atomic Test Name | Supported Platform |
|---|---|---|
| 3c64f177-28e2-49eb-a799-d767b24dd1e0 | Persistence via WMI Event Subscription - CommandLineEventConsumer | Windows |
| fecd0dfd-fb55-45fa-a10b-6250272d0832 | Persistence via WMI Event Subscription - ActiveScriptEventConsumer | Windows |
| 29786d7e-8916-4de6-9c55-be7b093b2706 | Windows MOFComp.exe Load MOF File | Windows |
Detection Testing
| Test Type | Status | Dataset | Source | Sourcetype |
|---|---|---|---|---|
| Validation | ✅ Passing | N/A | N/A | N/A |
| Unit | ✅ Passing | Dataset | XmlWinEventLog:Microsoft-Windows-WMI-Activity/Operational |
XmlWinEventLog |
| Integration | ✅ Passing | Dataset | XmlWinEventLog:Microsoft-Windows-WMI-Activity/Operational |
XmlWinEventLog |
Replay any dataset to Splunk Enterprise by using our replay.py tool or the UI.
Alternatively you can replay a dataset into a Splunk Attack Range
Source: GitHub |
Version: 11