5985,5986 - Pentesting WinRM
Last updated
Last updated
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Join HackenProof Discord server to communicate with experienced hackers and bug bounty hunters!
Hacking Insights Engage with content that delves into the thrill and challenges of hacking
Real-Time Hack News Keep up-to-date with fast-paced hacking world through real-time news and insights
Latest Announcements Stay informed with the newest bug bounties launching and crucial platform updates
Join us on Discord and start collaborating with top hackers today!
Windows Remote Management (WinRM) is highlighted as a protocol by Microsoft that enables the remote management of Windows systems through HTTP(S), leveraging SOAP in the process. It's fundamentally powered by WMI, presenting itself as an HTTP-based interface for WMI operations.
The presence of WinRM on a machine allows for straightforward remote administration via PowerShell, akin to how SSH works for other operating systems. To determine if WinRM is operational, checking for the opening of specific ports is recommended:
5985/tcp (HTTP)
5986/tcp (HTTPS)
An open port from the list above signifies that WinRM has been set up, thus permitting attempts to initiate a remote session.
To configure PowerShell for WinRM, Microsoft's Enable-PSRemoting
cmdlet comes into play, setting up the computer to accept remote PowerShell commands. With elevated PowerShell access, the following commands can be executed to enable this functionality and designate any host as trusted:
This approach involves adding a wildcard to the trustedhosts
configuration, a step that requires cautious consideration due to its implications. It's also noted that altering the network type from "Public" to "Work" might be necessary on the attacker's machine.
Moreover, WinRM can be activated remotely using the wmic
command, demonstrated as follows:
This method allows for the remote setup of WinRM, enhancing the flexibility in managing Windows machines from afar.
To verify the setup of your attack machine, the Test-WSMan
command is utilized to check if the target has WinRM configured properly. By executing this command, you should expect to receive details concerning the protocol version and wsmid, indicating successful configuration. Below are examples demonstrating the expected output for a configured target versus an unconfigured one:
For a target that is properly configured, the output will look similar to this:
The response should contain information about the protocol version and wsmid, signifying that WinRM is set up correctly.
Conversely, for a target not configured for WinRM, the would result in no such detailed information, highlighting the absence of a proper WinRM setup.
To execute ipconfig
remotely on a target machine and view its output do:
You can also execute a command of your current PS console via Invoke-Command. Suppose that you have locally a function called enumeration and you want to execute it in a remote computer, you can do:
To get an interactive PowerShell shell use Enter-PSSession
:
The session will run in a new process (wsmprovhost) inside the "victim"
To use PS Remoting and WinRM but the computer isn't configured, you could enable it with:
This won't work if the the language is constrained in the remote computer.
Inside this sessions you can load PS scripts using Invoke-Command
If you find the following error:
enter-pssession : Connecting to remote server 10.10.10.175 failed with the following error message : The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
The try on the client (info from here):
Join HackenProof Discord server to communicate with experienced hackers and bug bounty hunters!
Hacking Insights Engage with content that delves into the thrill and challenges of hacking
Real-Time Hack News Keep up-to-date with fast-paced hacking world through real-time news and insights
Latest Announcements Stay informed with the newest bug bounties launching and crucial platform updates
Join us on Discord and start collaborating with top hackers today!
Be careful, brute-forcing winrm could block users.
Read documentation on its github: https://github.com/Hackplayers/evil-winrm
To use evil-winrm to connect to an IPv6 address create an entry inside /etc/hosts setting a domain name to the IPv6 address and connect to that domain.
Code extracted from here: https://alamot.github.io/winrm_shell/
port:5985 Microsoft-HTTPAPI
Join HackenProof Discord server to communicate with experienced hackers and bug bounty hunters!
Hacking Insights Engage with content that delves into the thrill and challenges of hacking
Real-Time Hack News Keep up-to-date with fast-paced hacking world through real-time news and insights
Latest Announcements Stay informed with the newest bug bounties launching and crucial platform updates
Join us on Discord and start collaborating with top hackers today!
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)