Chapter 61

WMI Architecture

The WMI stack from CIMOM to providers, the repository database, namespaces, classes, and the instrumentation layer attackers exploit for invisible persistence.

Scenario

A threat hunter queries WMI subscriptions on a suspected host: Get-WMIObject -Namespace root\subscription -Class __EventFilter. The result shows a filter named "WindowsUpdate" — checking every 60 seconds, querying Win32_ProcessStartTrace for processes named "calc.exe". There's also a matching consumer: a CommandLineEventConsumer running a PowerShell download cradle. This is a WMI persistence triad — filter, consumer, binding — and it's been running silently since the attacker left. No new registry keys. No scheduled tasks. The only trace is in the WMI repository. This chapter explains exactly how that works.

WMI Stack Overview


  WMI Architecture Stack
  ══════════════════════════════════════════════════════════════════

  ┌─────────────────────────────────────────────────────────────┐
  │  WMI Clients                                                │
  │  PowerShell  │  WMI Tools  │  WMIC  │  Scripts  │  Remote  │
  └──────────────────────────────┬──────────────────────────────┘
                                 │ COM / DCOM
                                 ▼
  ┌─────────────────────────────────────────────────────────────┐
  │  WMI Service  (winmgmt.dll in svchost.exe)                  │
  │                                                             │
  │  ┌──────────────────────┐  ┌──────────────────────────┐    │
  │  │  CIMOM               │  │  WMI Repository           │   │
  │  │  (CIM Object Manager)│  │  %SystemRoot%\System32\  │   │
  │  │  Routes queries to   │  │  wbem\Repository\         │   │
  │  │  providers           │  │  (OBJECTS.DATA)           │   │
  │  └──────────┬───────────┘  └──────────────────────────┘    │
  │             │                                               │
  └─────────────┼───────────────────────────────────────────────┘
                │ Provider registration
                ▼
  ┌─────────────────────────────────────────────────────────────┐
  │  WMI Providers  (COM DLLs registered in repository)         │
  │                                                             │
  │  Win32 Provider  │  Event Log  │  Security  │  Custom       │
  │  (cimwin32.dll)  │  Provider   │  Provider  │  Providers    │
  │                                                             │
  │  Proxy process: WmiPrvSE.exe (per-provider isolation)       │
  └─────────────────────────────────────────────────────────────┘
                │
                ▼
  ┌─────────────────────────────────────────────────────────────┐
  │  Managed Objects (WMI instrumented system resources)        │
  │  Processes │ Services │ Registry │ Network │ Hardware       │
  └─────────────────────────────────────────────────────────────┘

    

The WMI Repository

The WMI repository is a proprietary binary database stored at %SystemRoot%\System32\wbem\Repository\OBJECTS.DATA. It contains:

Why this matters

WMI persistence lives in the repository, not the file system or registry. Standard security tools that scan for autorun locations in the registry miss WMI subscriptions entirely. Even after reboots, the subscription survives — it's stored persistently in OBJECTS.DATA. This is why WMI is called "fileless persistence" — the malicious code can be stored as a string inside the repository, with no corresponding file on disk.

Namespaces and Classes

NamespaceContentsRelevant for attackers
root\cimv2Standard Windows classes: processes, services, OS info, hardwareWin32_Process (SpawnInstance_), Win32_ProcessStartTrace
root\subscriptionEvent subscription classes__EventFilter, __EventConsumer subtypes, __FilterToConsumerBinding — persistence lives here
root\defaultDefault namespace, deprecatedUsed by older WMI-based malware
root\Microsoft\Windows\DefenderWindows Defender instrumentationDefenders can query scan results; attackers can query to check if Defender is active
root\SecurityCenter2AV product registrationEnumerate installed AV products: WMICLS AntiVirusProduct

WmiPrvSE.exe — Provider Host

WMI providers are COM DLLs, but they don't run inside the WMI service. They run in isolated WmiPrvSE.exe (WMI Provider Service) processes. Each provider gets its own host for isolation. Key detection points:

WMI Eventing Model

WMI supports two types of events:

Intrinsic events
Generated by WMI automatically when a CIM instance is created, modified, or deleted. E.g., __InstanceCreationEvent for new processes, __InstanceModificationEvent for changed services.
Extrinsic events
Fired by WMI providers. E.g., Win32_ProcessStartTrace fires whenever a process starts. Win32_VolumeChangeEvent fires on drive mount.

Temporary subscriptions exist only while the subscriber is connected. Permanent subscriptions (the persistence mechanism) survive reboots and are stored in root\subscription.


  WMI Permanent Subscription (Persistence Triad)
  ══════════════════════════════════════════════════════════════════

  root\subscription namespace
  ┌─────────────────────────────────────────────────────────────┐
  │                                                             │
  │  __EventFilter                                              │
  │  Name: "WindowsUpdate"                                      │
  │  Query: "SELECT * FROM Win32_ProcessStartTrace              │
  │          WHERE ProcessName = 'calc.exe'"                    │
  │  QueryLanguage: "WQL"                                       │
  │         │                                                   │
  │         │ __FilterToConsumerBinding (links the two)         │
  │         │                                                   │
  │         ▼                                                   │
  │  CommandLineEventConsumer                                   │
  │  Name: "WindowsUpdateConsumer"                              │
  │  CommandLineTemplate: "powershell.exe -enc JABjAC..."       │
  │                                                             │
  └─────────────────────────────────────────────────────────────┘

  Flow:
  calc.exe starts
       │
       ▼ Win32_ProcessStartTrace fires
  EventFilter evaluates WQL query
       │ Match
       ▼
  FilterToConsumerBinding triggers consumer
       │
       ▼
  WmiPrvSE.exe spawns powershell.exe
  (parent: WmiPrvSE.exe, no user interaction)

    

WQL — WMI Query Language

WQL is a subset of SQL for querying WMI classes and subscribing to events. Key syntax:

WQL
-- Enumerate running processes
SELECT * FROM Win32_Process

-- Get process by name
SELECT ProcessId, CommandLine FROM Win32_Process WHERE Name = 'svchost.exe'

-- EventFilter query for persistence
-- Fires every 60 seconds (TimerInterval in 100ns units: 60s = 600,000,000)
SELECT * FROM __TimerEvent WITHIN 60 WHERE TimerID = 'PollTimer'

-- Fires when any process starts
SELECT * FROM Win32_ProcessStartTrace

Remote WMI

WMI supports remote access via DCOM (port 135 for endpoint mapper + dynamic RPC ports) or WinRM. Remote WMI is a lateral movement technique:

PowerShell
# Remote process creation via WMI (classic lateral movement)
$wmi = [wmiclass]"\\TARGET\root\cimv2:Win32_Process"
$wmi.Create("cmd.exe /c whoami > C:\out.txt")

Detection: Event 4624 (logon type 3) on target + Sysmon Event 3 to port 135 from source + new process with WmiPrvSE.exe as parent on target.

Q & A

Q: Where exactly does WMI persistence survive — and how do you remove it?

Permanent subscriptions are stored in the WMI repository database (OBJECTS.DATA) under the root\subscription namespace. They survive reboots. To remove: Get-WMIObject -Namespace root\subscription -Class __EventFilter | Remove-WmiObject, then same for __EventConsumer subtypes and __FilterToConsumerBinding. Can also use the WMI Explorer tool or CIM cmdlets. Note: the WMI service must be running. Some malware re-creates deleted subscriptions using another subscription — always check for meta-subscriptions that fire on subscription deletion events.

Q: A process is spawned by WmiPrvSE.exe on a workstation at 3am. Why is this almost certainly malicious?

Legitimate permanent WMI subscriptions on workstations are rare — primarily used by SCCM/Intune for endpoint management, and those are well-documented. A process spawned by WmiPrvSE.exe outside that context means a WMI event subscription triggered it — either because an attacker created a permanent subscription for persistence, or because an attacker used remote WMI invocation for lateral movement. The parent-child relationship (WmiPrvSE.exe → suspicious_process.exe) is visible in Sysmon Event 1 and Event 4688 with command line. Combined with 3am timing: strongly malicious. Query all __EventFilter, __EventConsumer, __FilterToConsumerBinding objects in root\subscription immediately.