# WinRM

WinRM，即 Windows 远程管理，是微软对 **WS-MAN** 协议的实现，提供了对远程主机的 PowerShell 访问。远程 PowerShell 正是建立在 WinRM 协议之上，使用户可以对远程主机运行 PowerShell 命令。而对于攻击者而言，这也是远程的对远程主机实现代码执行以及横向移动的途径。WinRM 默认端口为 5985，但因为是较高端口号，因此可以进行更改。

默认情况下，只有**本地管理员**权限的用户可以使用 Powershell 远程登陆，但对于 **Remote Management Users** 组中的非本地管理员成员，依旧可以使用 PowerShell 远程登陆。例如，prod\\john 用户虽然不是本地管理员，却可以使用 WinRM 访问 Srv01。

### **PowerShell**

在 Powershell 会话中，如果当前用户对特定主机具备本地管理员或者 WinRM 的权限，可以通过命令 **Enter-PSSession -ComputerName &lt;主机名&gt;** 进入远程主机的交互式 PowerShell 会话。当然，我们也可以提供其他用户的凭证之后进入会话。

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-06/scaled-1680-/SHSQJc342aYKvSsI-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-06/SHSQJc342aYKvSsI-image.png)

我们还可以通过下述命令对远程主机执行代码。

```powershell
Invoke-Command -ComputerName <主机名> -ScriptBlock {<命令>} 
```

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-06/scaled-1680-/2fWWLbfPXyxUi3hc-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-06/2fWWLbfPXyxUi3hc-image.png)

### **C2** 

##### **jump winrm**

在 CS 中, **jump winrm** 可用于通过 WinRM 进行横向移动，之后团队服务器会得到新的高完整度的 Beacon。

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-06/scaled-1680-/b4ol89dz0ZIEd795-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-06/b4ol89dz0ZIEd795-image.png)

### **第三方工具**

##### **Evil-WinRM**

我们还可以通过外部工具来实现 WinRM 的远程访问以及横向移动。例如 Evil-WinRM。Evil-WinRM 支持 **Kerberos** 认证，以及**NTLM** 认证。

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-06/scaled-1680-/qbyGkFatWYjPAKpu-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-06/qbyGkFatWYjPAKpu-image.png)

Evil-WinRM 还带有一些内置的后利用命令，例如文件传输、服务枚举、反射式加载等。

[![image.png](https://raven-medicine.com/uploads/images/gallery/2023-06/scaled-1680-/LU4xJpeClhmKQDjb-image.png)](https://raven-medicine.com/uploads/images/gallery/2023-06/LU4xJpeClhmKQDjb-image.png)