Windows Management Instrumentation (WMI) is a Microsoft technology that was designed to allow administrators to perform local and remote management operations across a network. Since WMI is part of the windows ecosystem which exist since Windows 98 it can be used in almost every network regardless if it is running Windows 10 or Windows XP. Some of the operations that can be performed via WMI are:

  • Command Execution
  • File Transfer
  • Read Files and Registry keys
  • File System Examination
  • Subscribe to Events

Red teams can exploit the functionality of WMI and the fact that it can be used against various Windows systems in order to perform host recon, execute commands, perform lateral movement and persistence.

The WMI service is using the DCOM (TCP port 135) or the WinRM protocol (SOAP – port 5985).

WMI Port - DCOM

WMI Ports – DCOM and WinRM

It runs as a SYSTEM and administrator credentials are needed. Since 2014 there are various tools that exist publicly that can be used as a command and control via WMI.

WmiShell

WmiShell is a PowerShell script which is part of the WmiSploit and it is based on the WMIShell which was developed in python by Andrei Dumitrescu. This script uses WMI namespaces to execute commands.

Enter-WmiShell -ComputerName desktop-1st179m -UserName netbiosX
WmiShell - Command Execution

WmiShell – Command Execution

WmiSploit contains also a script which can execute PowerShell commands and scripts on the remote target by using WMI as a communication channel.

Invoke-WmiCommand -ComputerName desktop-1st179m -ScriptBlock {tasklist}

WmiSploit - Executing PowerShell Commands
WmiSploit – Executing PowerShell Commands

 

WMImplant

Chris Truncer developed WMImplant which is a PowerShell tool that leverages WMI in order to perform offensive operations. It can be used as command and control tool with the benefit that it doesn’t require an agent to be dropped on the target. However administrator credentials are needed.

Import-Module .\WMImplant.ps1
Invoke-WMImplant
WMImplant - Execution

WMImplant – Execution

The capabilities of WMimplant can be found in the main menu once it is executed. It can perform file transfer operations, lateral movement and host recon.

WMImplant - Main Menu

WMImplant – Main Menu

The change_user is required before the execution of any other commands in order to provide the correct credentials for remote connections.

WMImplant - Authentication and Basic Recon

WMImplant – Authentication and Basic Recon

It is also possible to execute small PowerShell scripts on the target.

WMImplant - Execution of PowerShell Scripts

WMImplant – Execution of PowerShell Scripts

Additionally like the WmiShell tool it has a shell functionality which can be triggered with the command_exec as below:

WMImplant - Shell Commands

WMImplant – Shell Commands

File operations can be also performed remotely.

WMImplant - Directory Listing

WMImplant – Directory Listing

WMIOps

Prior to WMImplant Chris Truncer had developed WMIOps which can be used to perform various actions against targets during red team assessments. Some of these actions include:

  • Transferring files
  • Starting processes
  • Killing processes
  • Folder Sharing

Even though the functionality is limited to compare to WMImplant still it implements the idea of executing commands and receiving output via WMI. The Invoke-ExecCommandWMI has the ability to start a process remotely.

WMIOps - Start a Process

WMIOps – Start a Remote Process

The calculator will start on the target host.

WMIOps - Calculator

WMIOps – Calculator

Transferring files over WMI can be achieved with the following function. However it needs local administrator credentials for the remote and the local machine.

Invoke-FileTransferOverWMI -RemoteUser victimusername -RemotePass victimpassword -TARGETS 192.168.1.124 -File C:\Users\netbiosX\Desktop\WMImplant.ps1 -Download C:\Users\User\Downloads\WMI\WMImplant.ps1 -LocalUser Administrator -LocalPass pentestlab

Retrieving System Drive Information:

WMIOps - System Drive Information

WMIOps – System Drive Information

Conclusion

Utilizing WMI for recon hosts and for lateral movement can allow the red team to stay hidden and exfiltrate information. The fact that WMI doesn’t need a binary to be dropped in order to retrieve information and that the majority of blue teams don’t monitor WMI activities can eliminate the risk of being discovered. It is therefore necessary not completely disable WMI and to filter traffic to ports 135 and 5985 if it needed.

Resources

Advertisements