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.
This method is much more discreet than the one used by psexec, smbexec and the other main tools in the impacket suite.
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-outputWe can spawn a process on a remote target using wmic.exe
Remote MSI Installation Using WMI
We can install a MSI package on a remote target using wmic.exe. Let's create a malicious MSI using msfvenom:
Execute following commands
Remote Scheduled Tasks Creation Using WMI
We can create scheduled tasks on a remote target using wmic.exe
In Windows 8 and higher, you can only create scheduled jobs with WMI if the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\Configuration has a value EnableAt=1 of type REG_DWORD. Therefore, this technique is unlikely to be found in the wild.
Remote Service Creation Using WMI
We can create a service on a remote target using wmic.exe.
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
Execution of the following commands using wmic.exe 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 implement the same technique with following C# code
Resources
Last updated
Was this helpful?
