07. Exploiting WinRM
Overview¶
Windows Remote Management (WinRM) is a Windows remote management protocol that allows administrators to remotely access and manage Windows systems over HTTP or HTTPS.
WinRM is commonly used for:
-
Remotely accessing Windows hosts
-
Executing commands on Windows systems
-
Managing and configuring Windows systems remotely
WinRM commonly uses:
Because WinRM provides remote command execution, valid credentials can provide significant access to a Windows system.
Identifying WinRM¶
The first step is to perform service enumeration against the target.
Example:
Example output:
PORT STATE SERVICE
135/tcp open msrpc
139/tcp open netbios-ssn
445/tcp open microsoft-ds
3389/tcp open ms-wbt-server
To specifically check WinRM:
Example:
The open 5985/tcp port indicates that WinRM is available on the target.
CrackMapExec¶
CrackMapExec can be used to interact with Windows services and test authentication against WinRM.
Start CrackMapExec:
It supports several protocols, including:
The WinRM protocol can be selected when working with a target exposing port 5985 or 5986.
Testing Credentials Against WinRM¶
In the lab, a username and password can be tested against the WinRM service.
Example:
A successful authentication is indicated by output similar to:
The successful authentication means that the supplied credentials can be used to authenticate to WinRM.
Executing Commands Through WinRM¶
After obtaining valid credentials, CrackMapExec can execute commands remotely.
For example:
Example result:
Another useful command is:
This can provide information about the Windows system.
The lab output identifies the target as:
Evil-WinRM¶
Evil-WinRM is a tool designed to provide an interactive WinRM shell.
Example:
A successful connection provides an interactive PowerShell session:
This allows commands to be executed directly on the Windows target through WinRM.
Metasploit WinRM Module¶
Metasploit contains a WinRM script execution module.
Start Metasploit:
Search for WinRM modules:
The relevant module shown in the lab is:
Select the module:
Display the available options:
Important options include:
The target host and authentication information must be configured for the lab target.
Example configuration:
set RHOSTS 10.2.18.45
set RPORT 5985
set USERNAME administrator
set PASSWORD <PASSWORD>
set FORCE_VBS true
The payload used in the demonstration is:
The listener configuration shown in the lab uses:
The exploit can then be started with:
Meterpreter Session¶
After successful execution, Metasploit establishes a Meterpreter session with the target.
The demonstration shows:
The session initially runs with the Administrator account:
The demonstration then attempts to migrate the Meterpreter process to a process running with higher privileges.
The successful migration results in:
This indicates that the Meterpreter session has reached the Windows SYSTEM security context.
Attack Flow¶
The WinRM exploitation process demonstrated in the lab can be summarized as:
Target Windows Server
|
v
Scan WinRM
|
v
TCP/5985 Open
|
v
Test WinRM Credentials
|
v
Successful Authentication
|
+----------------------+
| |
v v
CrackMapExec Evil-WinRM
| |
v v
Remote Commands Interactive Shell
|
v
Metasploit WinRM Module
|
v
Meterpreter Session
|
v
SYSTEM Context
Key Takeaways¶
WinRM provides legitimate remote administration capabilities on Windows systems, but exposed WinRM services combined with compromised credentials can allow remote command execution.
The lab demonstrates how to:
Identify WinRM
|
v
Check TCP/5985
|
v
Authenticate with valid credentials
|
v
Execute commands remotely
|
v
Obtain an interactive WinRM shell
|
v
Use a Metasploit WinRM module
|
v
Establish a Meterpreter session
These techniques should only be performed against systems where you have explicit authorization, such as a personal lab or dedicated training environment.