> For the complete documentation index, see [llms.txt](https://www.redteamgarage.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.redteamgarage.com/offensive-wmi.md).

# Offensive WMI

**Windows Management Instrumentation (WMI)** is a powerful feature of the Windows operating system that provides a standardized interface for accessing and managing various components of a computer. It is extensively used for administrative purposes, but its capabilities can also be leveraged for offensive security purposes, making it a valuable tool for red teamers.

#### Why WMI is Useful for Red Teaming

**Remote Management**: WMI allows for the execution of commands and scripts on remote systems, facilitating lateral movement within a network without the need for additional tools.

**Stealth and Evasion**: WMI operates using legitimate Windows processes, making it less likely to trigger security alerts compared to traditional malware or hacking tools.

**Automation and Scripting**: WMI can be scripted using languages such as PowerShell or VBScript, enabling the automation of complex tasks and reducing manual intervention.

**Extensive Functionality**: WMI can interact with various system components, such as file systems, registry, processes, services, and network settings, providing comprehensive control over the target environment.

#### WMI Architecture

Below is an image depicting the WMI architecture:

Credit: Microsoft's Official Website

<figure><img src="https://1698500628-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FifilBLhnTZVjmLemJ6ni%2Fuploads%2FqrvNbC0jyb1vMS9X3i3T%2Fimage.png?alt=media&amp;token=9261fd82-51a9-4b62-ae3d-7cfe1c8359ae" alt=""><figcaption><p><em>WMI Architecture taken from Microsoft's Official Page</em></p></figcaption></figure>

### Examples and Usage

**Example 1: Querying System Information**

This script queries detailed information about the operating system on the target machine.

```powershell
Get-WmiObject -Class Win32_OperatingSystem
```

<figure><img src="https://1698500628-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FifilBLhnTZVjmLemJ6ni%2Fuploads%2FeKaQoVslULc7oJIDQchm%2Fimage.png?alt=media&amp;token=98156ccb-7422-4fa7-815b-391dcf222978" alt=""><figcaption><p><em>WMI command to check the OS details</em></p></figcaption></figure>

#### Example 2: Executing a Remote Command

This script creates a new process (Notepad) on the target machine using WMI.

```powershell
Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList "notepad.exe"
```

<figure><img src="https://1698500628-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FifilBLhnTZVjmLemJ6ni%2Fuploads%2FNPmRRLLCmc1H9P7jsf2J%2Fimage.png?alt=media&amp;token=fad56823-8e50-46ab-a81d-037203e408e0" alt=""><figcaption><p><em>notepad is opened using WMI command</em></p></figcaption></figure>

#### Example 4: Enumerating Running Processes

This script lists all running processes on the target machine.

{% code overflow="wrap" %}

```powershell
$targetMachine = "TARGET_MACHINE_NAME"  # Replace with the actual target machine name or IP address

# Get running processes information
Get-WmiObject -Class Win32_Process -ComputerName $targetMachine | Select-Object Name, ProcessId, CommandLine
```

{% endcode %}

This script uses WMI to query the `Win32_Process` class on the target machine and retrieves information about running processes, including the process name, process ID, and command line.

<figure><img src="https://1698500628-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FifilBLhnTZVjmLemJ6ni%2Fuploads%2F9tD3Qx8FPAH2FIyYhs5x%2Fimage.png?alt=media&amp;token=a23e42f0-71fc-45a3-a36e-a86eec720661" alt=""><figcaption><p><em>WMI using PowerShell</em></p></figcaption></figure>

#### Conclusion

Using WMI for offensive purposes allows red teamers to execute commands, create persistence mechanisms, and gather valuable information from target machines while maintaining a low profile. These examples demonstrate the versatility of WMI in red teaming scenarios, highlighting its potential for stealthy and efficient operations.
