Remote WMI

MITRE ATT&CK™ Windows Management Instrumentation - Technique T1047

Theory

Windows Management Instrumentation (WMI) provides a standardized way for querying and managing various elements of a Windows operating system. It allow administrators to perform standard management tasks that attackers can abuse to perform lateral movements.

When using WMI remotely, the client application establishes a connection to the WMI service on the remote Windows machine. This connection is made using DCOM (Distributed Component Object Model) as the underlying transport protocol. The client initiates an RPC (Remote Procedure Call) connection to communicate with the WMI DCOM infrastructure on the remote system.

Once the DCOM connection is established, the MS-WMI protocols (Microsoft WMI Extensions to DCOM) comes into play. MS-WMI protocols provides additional functionality that is specific to WMI operations over the DCOM protocol. These extensions enhance DCOM to handle WMI-specific tasks such as executing WMI queries, invoking methods, and retrieving system information.

Practice

Remote Process Creation Using WMI

Impacket

The Impacket's wmiexec script give you a semi-interactive shell by leveraging DCOM and the MS-WMI protocol.

#Execute commands over MS-WMI
wmiexec.py <domain>/<username>:<password>@<target>

#SilentCommand, mor likely to bypass security solutions
wmiexec.py -silentcommand <domain>/<username>:<password>@<target> <COMMAND>

NetExec

We may use netexec to remotely execute commands on a remote target using WMI.

## Check if you can remote WMI
# With SMB port open
nxc wmi <target> -u <username> -p <password>
# With SMB port close, add the flag -d DOMAIN
nxc wmi <target> -u <username> -p <password> -d <domain>

## Execute commands
# wmiexec
nxc wmi <target> -u <username> -p <password> -x whoami
# wmiexec-event
nxc wmi <target> -u <username> -p <password> -x whoami --exec-method wmiexec-event
# wmiexec-event + SilentCommand, mor likely to bypass security solutions
nxc wmi <target> -u <username> -p <password> -x whoami --exec-method wmiexec-event --no-output

Remote MSI Installation Using WMI

We can install a MSI package on a remote target using wmi and powershell cmdlets. Let's create a malicious MSI using msfvenom and upload it to a share :

Powershell v1+ (2006)

Powershell v3+ (2012)

Remote Scheduled Tasks Creation Using WMI

We can create scheduled tasks on a remote target using wmi and powershell cmdlets.

Powershell v3+ (2012)

Remote Service Creation Using WMI

We can create a service on a remote target using wmi and powershell cmdlets.

Powershell v1+ (2012)

Powershell v3+ (2012)

Lateral Movement via WMI Event Subscription

Using WMI on a remote endpoint, we can perform lateral movements based on WMI Event Subscription Persitence.

Typically, WMI event subscription requires creation of the following three classes which are used to store the payload or the arbitrary command, to specify the event that will trigger the payload and to relate the two classes (__EventConsumer &__EventFilter) so execution and trigger to bind together.

  • __EventFilter // Trigger (new process, failed logon etc.)

  • EventConsumer // Perform Action (execute payload etc.)

  • __FilterToConsumerBinding // Binds Filter and Consumer Classes

Implementation of this technique doesn’t require any toolkit since Windows has a utility that can interact with WMI (wmic) and PowerShell can be leveraged as well.

Execution of the following commands using powershell will create in the name space of root\subscription three events on the target hosts. You can set the arbitrary payload to execute within 5 seconds on every new logon session creation or within 60 seconds every time Windows starts.

We can cleanup using following commands

Resources

Last updated

Was this helpful?