For the complete documentation index, see llms.txt. This page is also available as Markdown.

WinRM

MITRE ATT&CK™ Remote Services: Windows Remote Management - Technique T1021.006

Theory

Adversaries may use Valid Accounts to interact with remote systems using Windows Remote Management (WinRM). The adversary may then perform actions as the logged-on user.

WinRM is the name of both a Windows service and a protocol that allows a user to interact with a remote system (e.g., run an executable, modify the Registry, modify services). It may be called with the winrm command or by any number of programs such as PowerShell. WinRM can be used as a method of remotely interacting with Windows Management Instrumentation.

Practice

Execute Remote Commands

We can use netexec to remotely execute a command on the target over WinRM.

#Execute command
netexec winrm <IP> -u <user> -p <password> -x "whoami"

#Execute PowerShell command
netexec winrm <IP> -u <user> -p <password> -x "$(Get-WMIObject -class Win32_ComputerSystem | select username).username"

We can use the PowerShell Invoke-Command cmdlet to remotely execute a command on the target over WinRM.

#Create Powershell PSCredential object
$username = 'Administrator';
$password = 'Mypass123';
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force; 
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword;

#Invoke command remotly
Invoke-Command -Computername <TARGET> -Credential $credential -ScriptBlock {whoami}

#Invoke command remotly from functions of your current PS console (like imported modules)
Invoke-Command -ComputerName <TARGET> -Credential $credential -ScriptBLock ${function:enumeration} [-ArgumentList "arguments"]

You may also run scripts using WInRM

Invoke-Command -ComputerName <TARGET> -FilePath C:\path\to\script\file -credential $credential

Remote shell

Evil-winrm can be use to obtain a winrm powershell session

evil-winrm -u <user> -p <password> -i <IP>

We can use Powershell's Enter-PSSession cmdlet to start an interactive session with a remote computer.

#Create Powershell PSCredential object
$username = 'Administrator';
$password = 'Mypass123';
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force; 
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword;

# Start a remote powershell session
Enter-PSSession -ComputerName <TARGET> -Credential $credential

Resources

Last updated