WMImplant - Out of the Box Detection Opportunities

WMImplant can be used to compromise Windows systems within a domain in an agent-less manner. However, every tool that exists also provides opportunities to detect their use. WMImplant is no different. There are other blog posts out there that talk about it, what it is and how it works. Our blog post doesn’t just stop there:  it’s an under-the-hood look at how WMImplant works and it also provides some opportunities for detection.

WMImplant Modes

WMImplant largely operates in two modes. If possible, it will directly interact with WMI on a remote system to pull information such as running processes, pulling active network cards, searching for files, etc. However, in it’s other “mode”, WMImplant will spawn a process (powershell.exe) and run various commands on the system pertaining to what you are trying to accomplish. When in this second mode, WMImplant does the following:

  1. It queries the targeted system to get the original value of the Win32_OSRecoveryConfiguration DebugFilePath property
  2. It then overwrites the value of the DebugFilePath property with the encoded command that will be executed on the targeted system
  3. It spawns powershell.exe on the targeted system, decodes the command stored in the DebugFilePath property, and runs the command
  4. After receiving the results, it encodes the results and writes back to the DebugFilePath property
  5. It queries the targeted system’s DebugFilePath property, decodes the results, and displays the results to the console
  6. It replaces the modified DebugFilePath property with its original value
C2 Process

WMImplant Detection

Immediately after WMImplant was released, Roberto Rodriguez wrote an excellent blog post about detecting it with Sysmon and Elk. Some of the (summarized) takeaways from Rodrigo’s post are:

  • 5 character environmental variables (only letters and/or numbers)
  • wmiprsve spawns powershell.exe
  • Obfuscated use of the following commands
  • Get-ChildItem
  • Get-Command
  • Invoke-Expression
  • Anonymous pipes

This is exactly spot-on with regards to how a non-modified instance of WMImplant works. Let’s take a look at the code below:

WMImplant Code

In the first red box, you can see that WMImplant is randomly generating 5 characters which is used for the environmental variable name. The second box is randomly selecting one of each of the pre-obfuscated commands that will be used by WMImplant to execute code on the targeted system. These pre-obfuscated commands are static, and not randomly generated on the fly. If you are detecting 5 character length environmental variables being created on systems and any of the above PowerShell, it may be indicative of WMImplant behavior.

WMImplant also includes a “debug” mode which displays the exact commands that it is running and the environmental variables that are being created (and deleted). To enable this mode, change the $ShowFunFactsForPOV variable to $True (shown in line 173 below).

Environmental Variable Code

Once you enable this mode, anytime you execute a command which spawns powershell.exe on the targeted system, you’ll get all of the debug details.

Command Line Execution

You can use the debug information from WMImplant to live test detections on test systems to ensure coverage for WMImplant. It contains the environmental variable name, commands embedded within it, and the PowerShell command line launcher.

Additionally, Matt Graeber tweeted a PowerShell one-liner that’s can be used to see WMImplant’s host artifacts.

Matt Graeber's Tweet on WMImplant

When you run this command, you can see the mappings between the different properties:

WMImplant Mapping

Any data that is saved to the DebugFilePath property is backed by the registry key located at HKLM\SYSTEM\CurrentControlSet\Control\CrashControl and the DumpFile.

Dump File Location

The information stored within this registry key should remain relatively static, therefore any modifications to this should be suspicious.

Hopefully this information can help provide opportunities to write detections for WMImplant. If you have any questions at all, please don’t hesitate to contact us at FortyNorth Security.