您好
- 透過GPO啟用PowerShell遠端管理(PSRemoting)
1.1 啟用PSRemoting服務
設定路徑:
Computer Configuration → Policies → Administrative Templates → Windows Components → Windows Remote Management (WinRM) → WinRM Service
啟用服務:
啟用 Allow remote server management through WinRM,並設定 IPv4 filter 為 *(或指定IP範圍)。
設定監聽埠:
在 Specify listening ports... 中設定 5985(HTTP)或 5986(HTTPS)。
1.2 自動啟動WinRM服務
設定路徑:
Computer Configuration → Preferences → Control Panel Settings → Services
新增服務:
服務名稱:WinRM
啟動模式:Automatic
操作:Start service
1.3 啟用PowerShell執行原則
設定路徑:
Computer Configuration → Policies → Administrative Templates → Windows Components → Windows PowerShell
啟用指令:
啟用 Turn on Script Execution,設定執行原則為 RemoteSigned 或 Unrestricted。
- 防火牆規則設定(限制來源IP與使用者)
2.1 允許WinRM流量(5985/5986)
設定路徑:
Computer Configuration → Policies → Windows Settings → Security Settings → Windows Defender Firewall with Advanced Security → Inbound Rules
新增規則:
規則類型:Predefined → Windows Remote Management
允許協議:TCP,端口 5985(HTTP)或 5986(HTTPS)。
作用域(Scope):
遠端IP:僅允許AD伺服器IP或特定網段(例如 10.0.0.0/24)。
使用者與權限(Advanced):
僅允許來自 Domain Admins 或自定義安全群組(例如 PSRemote-Admins)。
2.2 禁止其他遠端管理協定(選配)
關閉RDP/Telnet:
在防火牆中禁用 3389(RDP)、23(Telnet)等非必要協定。
- 權限控管(限制僅特定使用者可執行)
3.1 設定WinRM ACL(安全描述符)
透過GPO執行PowerShell指令:
Computer Configuration → Policies → Windows Settings → Scripts (Startup/Shutdown)
新增啟動腳本(PowerShell):
powershell
限制僅允許「Domain Admins」或自定義群組訪問WinRM
$SDDL = "O:NSG:BAD:P(A;;GA;;;BA)(A;;GA;;;DA)S:P(AU;FA;GA;;;WD)(AU;SA;GWGX;;;WD)"
Set-PSSessionConfiguration -Name Microsoft.PowerShell -SecurityDescriptorSddl $SDDL -Force
說明:
BA:Built-in Administrators(本地管理員)
DA:Domain Admins(網域管理員)
移除 WD(Everyone)以禁止非授權使用者。
3.2 限制PowerShell遠端命令執行
設定JEA(Just Enough Administration)(進階選配):
建立JEA角色,限制管理員僅能執行特定指令(如 Logoff)。
透過GPO部署JEA組態檔至目標電腦。
- 部署與驗證
4.1 強制更新GPO
在目標電腦上執行:
powershell
gpupdate /force
4.2 驗證遠端管理功能
測試WinRM連線:
powershell
從AD伺服器測試連線到目標電腦
Test-WsMan -ComputerName <目標電腦名稱>
遠端登出使用者:
powershell
使用Invoke-Command遠端執行登出指令
Invoke-Command -ComputerName <目標電腦名稱> -ScriptBlock { logoff.exe $args[0] } -ArgumentList <SessionID> -Credential (Get-Credential)
4.3 檢查權限是否生效
模擬未授權使用者測試:
使用非管理員帳戶嘗試遠端連接,應返回 Access Denied
Best regards
Runjie Zhai