PowerShell Remoting:从Linux到Windows
字数 1048 2025-08-27 12:33:31
PowerShell Remoting: 从Linux到Windows 详细教学文档
1. 概述
本教程详细讲解如何从Linux系统通过PowerShell Remoting远程连接到Windows系统,特别适用于渗透测试场景。该方法主要利用NTLM身份验证机制,绕过Kerberos相互身份验证的限制。
2. 前提条件
- 对目标Windows系统具有管理员级别访问权限
- Linux系统上安装Docker
- 目标Windows系统已启用PowerShell Remoting功能
3. 核心原理
传统PowerShell远程操作需要Kerberos相互身份验证,要求客户端和目标都处于域环境中。本方法通过以下方式绕过限制:
- 将Linux客户端添加为Windows系统的TrustedHost
- 使用支持NTLM的PowerShell Core Linux版本
- 通过NTLM进行身份验证而非Kerberos
4. 详细操作步骤
4.1 在目标Windows系统上的配置
-
启用PowerShell远程功能:
Enable-PSRemoting -Force -
查看当前TrustedHosts列表(可选,供参考):
Get-Item WSMan:\localhost\Client\TrustedHosts -
添加Linux客户端为TrustedHost:
- 方法一:允许所有计算机使用NTLM
Set-Item WSMan:\localhost\Client\TrustedHosts -Force -Value * - 方法二:仅添加特定IP
Set-Item WSMan:\localhost\Client\TrustedHosts -Force -Concatenate -Value 192.168.10.100
- 方法一:允许所有计算机使用NTLM
-
配置并重启WinRM服务:
Set-Service WinRM -StartMode Automatic Restart-Service -Force WinRM
4.2 在Linux客户端上的操作
-
运行支持NTLM的PowerShell Docker镜像:
docker run -it -v /pathTo/PowerShellModules:/mnt quickbreach/powershell-ntlm(可选:将本地目录挂载到容器中以便访问脚本)
-
建立远程PowerShell会话:
# 获取凭据 $creds = Get-Credential # 建立会话(必须指定Authentication类型为Negotiate) Enter-PSSession -ComputerName (Target-IP) -Authentication Negotiate -Credential $creds示例:
Enter-PSSession -ComputerName 10.20.30.190 -Authentication Negotiate -Credential $creds -
使用Invoke-Command执行远程命令:
Invoke-Command -ComputerName 10.20.30.190 -Authentication Negotiate -Credential $creds -ScriptBlock { Get-HotFix }
5. 清理与恢复
-
从TrustedHosts中移除特定IP:
$newvalue = ((Get-ChildItem WSMan:\localhost\Client\TrustedHosts).Value).Replace(",192.168.10.100","") Set-Item WSMan:\localhost\Client\TrustedHosts -Force -Value $newvalue -
清除所有TrustedHosts:
Clear-Item WSMan:\localhost\Client\TrustedHosts -
重启WinRM服务应用更改:
Restart-Service WinRM
6. 注意事项
- 必须使用
-Authentication Negotiate参数 - 该方法仅适用于PowerShell Core 6.1.0及以上版本
- 在渗透测试中,此方法可作为远程代码执行的主要手段
- 修改TrustedHosts配置需要管理员权限
7. 参考资源
- 使用的Docker镜像:
quickbreach/powershell-ntlm - 原文参考:https://blog.quickbreach.io/ps-remote-from-linux-to-windows/
通过以上步骤,您可以成功地从Linux系统通过PowerShell Remoting连接到Windows系统,执行各种管理任务或渗透测试操作。