Penetration Basics - Usage of WMIC

Onedaysec
4 min read
1 views
docx image 1770019788722 0 cc9f37aa13

0x00 Preface

---

WMI (Windows Management Instrumentation) is a management feature that provides a unified environment for accessing Windows system components, supporting both local and remote access. Previous articles such as "WMI Attacks," "WMI Backdoor," "WMI Defense," and "Study Notes of WMI Persistence using wmic.exe" have covered related content. This article will analyze common methods of wmic from the perspectives of information gathering and lateral movement, combining exploitation ideas to provide defense recommendations.

0x01 Introduction

---

This article will cover the following topics:

  • Usage of wbemtest
  • Querying host information via wmic
  • Modifying the registry via wmic
  • Executing programs via wmic
  • Local and remote access to WMI services

0x02 Usage of wbemtest

---

Reference materials:

https://docs.microsoft.com/en-us/mem/configmgr/develop/core/understand/introduction-to-wbemtest

Installed by default on Windows systems, it can be used to connect to WMI namespaces and access WMI services.

With wbemtest, we can obtain complete functional details and usage methods of WMI.

The interface is shown in the figure below.

0x02 Usage of wbemtest — technical illustration 1

Click Connect..., enter the WMI namespace root\cimv2, and after connecting to root\cimv2, you can enter the main page, as shown below.

0x02 Usage of wbemtest — technical illustration 2

Common function examples are as follows:

(1) Enum Classes...

Enumerate classes, which can be used to enumerate all objects and query the definition of each class.

Here, taking the query of the Win32_Process object as an example:

Select Enum Classes... -> Recursive -> OK in sequence, select Win32_Process, double-click to enter the object editor, as shown below.

(1) Enum Classes... — technical illustration 3

The Properties bar can be used to view properties, for example, here is Handle, which can be queried via Query... mentioned later.

The Methods bar can be used to view methods, for example, here is Create, which can be invoked via Execute Method... mentioned later.

(2)Query...

Query attributes, requires input of WMI Query Language (WQL)

Reference:

https://docs.microsoft.com/en-us/windows/win32/wmisdk/wql-sql-for-wmi

Syntax example:

SELECT Handle FROM Win32_Process

Query result as shown in the figure below

(2)Query... — technical illustration 4

This query statement converted to wmic command is as follows:

wmic /namespace:"\\root\cimv2" PATH Win32_Process get Handle

(3)Execute Method...

Invoke method, here taking the Create method of the Win32_Process object as an example

Set Object Path to Win32_Process, click OK

In the pop-up interface, set Method to Create

Click Edit in Parameters..., in the pop-up interface, sequentially select CommandLine -> Edit Property

Set Valve to calc, as shown in the figure below

(3)Execute Method... — technical illustration 5

Click Save Object -> Execute! to pop up the calculator

The complete command replaced with wmic is as follows:

wmic /namespace:"\\root\cimv2" PATH Win32_Process call create "calc"

The abbreviated command is as follows:

wmic process call create "calc"

0x03 Local and Remote Access to WMI Services

---

1. Query Host Name

Local:

wmic /namespace:"\\root\cimv2" PATH Win32_ComputerSystem get Name

Remote:

wmic /node:192.168.1.1 /user:"administrator" /password:"123456" /namespace:"\\root\cimv2" PATH Win32_ComputerSystem get Name

2. Registry Operations

For specific details, please refer to "Study Notes of WMI Persistence using wmic.exe".

Here are several commonly used commands:

(1) Retrieve the remote desktop connection history of the current user

Enumerate the registry key value HKCU:\Software\Microsoft\Terminal Server Client\Servers, the command is as follows:

wmic /namespace:"\\root\cimv2" path stdregprov call EnumKey ^&h80000001,"Software\Microsoft\Terminal Server Client\Servers"

(2) Remotely query and modify Restricted Admin Mode

For content related to Restricted Admin Mode, please refer to "Penetration Techniques – Pass the Hash with Remote Desktop (Restricted Admin mode)".

For C Sharp implementation of remotely querying and modifying Restricted Admin Mode, please refer to:

https://github.com/GhostPack/RestrictedAdmin

https://github.com/airzero24/WMIReg

The wmic command for remotely querying Restricted Admin Mode is as follows:

wmic /node:192.168.1.1 /user:"administrator" /password:"123456" /namespace:"\\root\cimv2" path stdregprov call GetDWORDValue ^&H80000002,"System\CurrentControlSet\Control\Lsa","DisableRestrictedAdmin"

The wmic command for remotely enabling Restricted Admin Mode is as follows:

wmic /node:192.168.1.1 /user:"administrator" /password:"123456" /namespace:"\\root\cimv2" path stdregprov call SetDWORDValue ^&H80000002,"System\CurrentControlSet\Control\Lsa","DisableRestrictedAdmin","0"

The wmic command for remotely disabling Restricted Admin Mode is as follows:

wmic /node:192.168.1.1 /user:"administrator" /password:"123456" /namespace:"\\root\cimv2" path stdregprov call SetDWORDValue ^&H80000002,"System\CurrentControlSet\Control\Lsa","DisableRestrictedAdmin","1"

3. Execute Program

Local:

wmic process call create "calc"

Remote:

wmic /node:192.168.1.1 /user:"administrator" /password:"123456" process call create "calc"

4. Process Operations

Query all local processes:

wmic /namespace:"\\root\cimv2" PATH Win32_Process get name,processid,commandline /FORMAT:list

Query all remote host processes:

wmic /node:192.168.1.1 /user:"administrator" /password:"123456" /namespace:"\\root\cimv2" PATH Win32_Process get name,processid,commandline /FORMAT:list

Other usage can also refer to: https://docs.microsoft.com/en-us/archive/blogs/jhoward/wmic-samples

0x04 Defense Detection

---

It should be noted that WMI logging is minimal by default and cannot record command details of WMI.

WMI-Activity trace logs can record basic logs but cannot capture WMI command details. The enabling method is as follows:

Open Event Viewer, select View -> Show Analytic and Debug Logs

Navigate to Applications and Services Logs -> Microsoft -> Windows -> WMI-Activity -> Trace, then click Enable Log

When using the wmic command, the default process c:\windows\system32\wbem\wmic.exe is launched. Sysmon can be chosen here to record process creation details, allowing inspection of CommandLine to obtain WMI command specifics

For detailed log information, refer to: https://jpcertcc.github.io/ToolAnalysisResultSheet/details/wmic.htm

Alternatively, the open-source digital forensics tool Velociraptor can be used to record process creation details, including CommandLine

0x05 Summary

---

This article introduces fundamental knowledge of wmic, combines exploitation approaches, and provides defense recommendations.

Related Questions & Answers

What are the challenges in detecting WMI abuse, and what tools can help monitor wmic activity?

WMI logging is minimal by default; the WMI-Activity trace log records basic operations but not command details. To capture the actual WMI command line, you can use Sysmon to monitor process creation events, which include `CommandLine` for `wmic.exe`. Alternatively, the open‑source forensics tool Velociraptor can record process creation details. These methods help security teams identify malicious use of wmic, such as remote program execution or registry manipulation. For more defensive strategies, refer to the [Penetration Basics - Usage of WMIC](/news/penetration-basics-usage-of-wmic) article.

How does wmic enable remote command execution for lateral movement?

wmic can execute programs on remote systems using the `Win32_Process::Create` method. The syntax is: `wmic /node:<IP> /user:... /password:... process call create "command"`. For example, `wmic /node:192.168.1.1 /user:administrator /password:123456 process call create "calc"` launches Calculator on the remote host. This is a common technique for lateral movement, as it allows attackers to run arbitrary binaries without needing RDP or other services. The [Penetration Basics - Usage of WMIC](/news/penetration-basics-usage-of-wmic) article provides additional examples.

How can wmic be used to remotely query or modify the Restricted Admin Mode registry setting?

wmic can remotely access the registry via the `stdregprov` class. To query `DisableRestrictedAdmin`, use: `wmic /node:<IP> /user:... /password:... path stdregprov call GetDWORDValue ^&H80000002,"System\CurrentControlSet\Control\Lsa","DisableRestrictedAdmin"`. To enable Restricted Admin Mode, call `SetDWORDValue` with the value `"0"` (0 enables it). Disabling it uses `"1"`. This technique is often part of lateral movement, similar to concepts covered in [Penetration Techniques - Lateral Movement from VMware ESXI to Windows Virtual Machines](/news/penetration-techniques-lateral-movement-from-vmware-esxi-to-windows-virtual-machines).

What is wbemtest and how does it relate to wmic commands?

wbemtest is a GUI tool installed by default on Windows that allows you to connect to WMI namespaces and interact with WMI objects. It can enumerate classes, execute queries using WQL, and invoke methods. The operations performed in wbemtest can be directly translated into wmic commands; for example, invoking the `Create` method of `Win32_Process` in wbemtest corresponds to `wmic process call create "calc"`. For more details, see the [Penetration Basics - Usage of WMIC](/news/penetration-basics-usage-of-wmic) article.

Continue Reading