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).
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
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}
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
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.
The change_user is required before the execution of any other commands in order to provide the correct credentials for remote connections.
It is also possible to execute small PowerShell scripts on the target.
Additionally like the WmiShell tool it has a shell functionality which can be triggered with the command_exec as below:
File operations can be also performed remotely.
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.
The calculator will start on the target host.
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:
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.
Great article! Just wanted to remember that the simple native “wimc” utilty is useful too.. especially for spawning remote processes and it’s even possible to authenticate via kerberos!