Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Active Directory and Windows attacks

Lab · Medium · 1.5 hoursFree account

WMI Tradecraft & Analysis

WMI for persistence, lateral movement, and stealthy code execution.

  • wmi
  • persistence
  • lateral-movement
  • detection
  • windows
On this page 8 sections
  1. ·Lab Setup
  2. 1Enumerate with WMI
  3. 2Execute a process remotely
  4. Locked: Build WMI event-based persistence
  5. Locked: Detect WMI persistence
  6. Locked: Remove the subscription and harden
  7. Locked: Defence and Detection
  8. Locked: Check Your Work

Before you start

Windows Management Instrumentation (WMI) is a built-in administration layer on every Windows host. Attackers reuse it for stealthy code execution, remote process creation, and event-driven persistence that survives a reboot without a service, a scheduled task, or a file on disk — tradecraft seen in APT29 campaigns and in ransomware families such as REvil. Build a WMI subscription that runs code on every logon, then find it in the WMI repository and the event log.

What You'll Learn

  • Query system information with WMI from PowerShell
  • Execute a process on a remote lab host using WMI
  • Build a WMI event subscription that persists across reboots
  • Detect WMI persistence in the event log and the WMI repository
  • Remove malicious subscriptions and harden the WMI surface

Lab Setup

KaliRange hosts no machines. You need two Windows machines on an isolated lab network, as virtual machines on your own computer. Both are yours. Use an evaluation copy of Windows Server from the Microsoft Evaluation Center (180 days) for the domain controller, and take a snapshot of each machine before Step 1. The names below are the example names of this lab.

MachineRoleDetails
WS-LAB01 (Windows 10/11)Attacker workstationDomain-joined. Local admin. PowerShell 5.1.
DC-LAB01 (Windows Server 2019/2022)TargetDomain controller or domain member. WinRM enabled. Sysmon installed with a public config.

Both machines share a domain account with local admin rights on the target. This simulates an operator who has already compromised credentials.

Confirm WMI connectivity from WS-LAB01:

Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName DC-LAB01 |
  Select-Object Caption, Version
Caption                          Version
-------                          -------
Microsoft Windows Server 2022    10.0.20348

If the query fails, check that the Windows Firewall allows WMI (DCOM, TCP 135 and dynamic RPC ports) on the target.

Authorised scope only. Isolated lab network. Never on production.

Step 1: Enumerate with WMI

1

Gather system data through WMI

WMI gives read access to almost everything on a Windows host. Attackers use it for silent reconnaissance because it leaves minimal footprint compared to running commands.

Query processes, services and installed software on the remote target:

# Running processes
Get-CimInstance -ClassName Win32_Process -ComputerName DC-LAB01 |
  Select-Object ProcessId, Name, CommandLine | Sort-Object Name | Select-Object -First 10

# Services set to auto-start
Get-CimInstance -ClassName Win32_Service -ComputerName DC-LAB01 |
  Where-Object StartMode -eq 'Auto' |
  Select-Object Name, State, StartName | Sort-Object Name | Select-Object -First 10

# Installed software
Get-CimInstance -ClassName Win32_Product -ComputerName DC-LAB01 |
  Select-Object Name, Version | Sort-Object Name | Select-Object -First 5
ProcessId Name                   CommandLine
--------- ----                   -----------
        4 System
      108 Registry
      632 csrss.exe              %SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows ...
      712 wininit.exe            wininit.exe
      808 services.exe           C:\Windows\system32\services.exe

Name                   State   StartName
----                   -----   ---------
BFE                    Running LocalService
CryptSvc               Running NetworkService
Dhcp                   Running LocalService

Name                           Version
----                           -------
Microsoft Visual C++ 2019 ...  14.28.29913

Every query ran without dropping a file or starting a process on the target. The only evidence is a DCOM connection in the network log. This is why WMI is a favourite for stealthy enumeration.

Step 2: Execute a process remotely

2

Run a command on the target via WMI

WMI can start a process on a remote host. The process runs as SYSTEM by default when the caller has admin rights. No file is dropped — only a command string is sent.

Invoke-CimMethod -ClassName Win32_Process -MethodName Create `
  -Arguments @{ CommandLine = 'cmd.exe /c hostname > C:\Users\Public\wmi-exec.txt' } `
  -ComputerName DC-LAB01
ProcessId ReturnValue PSComputerName
--------- ----------- --------------
     4820           0 DC-LAB01

ReturnValue 0 means the process was created. Confirm on the target:

Invoke-Command -ComputerName DC-LAB01 -ScriptBlock { Get-Content C:\Users\Public\wmi-exec.txt }
DC-LAB01

The command ran on the remote host. On DC-LAB01, check Sysmon event 1:

Invoke-Command -ComputerName DC-LAB01 -ScriptBlock {
  Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational'; Id=1} -MaxEvents 3 |
    Select-Object TimeCreated, @{Name='Cmd'; Expression={($_.Properties[10].Value)}}
}
TimeCreated          Cmd
-----------          ---
20/11/2026 10:30:12  cmd.exe /c hostname > C:\Users\Public\wmi-exec.txt

Sysmon recorded the full command line. The parent process is WmiPrvSE.exe, the WMI provider host. That parent is the detection signal: a command shell whose parent is WmiPrvSE.exe is almost always worth investigating.

Sign in to continue

5 more sections are for signed-in members. It is free: sign in with Google.

Related