從Linux到Windows的PowerShell遠端處理
前提條件
1)後期利用期間可以通過目標NTLM身份驗證 2)重啟WinRM服務 3)使用此NTLM支援PowerShell Docker映象到Linux的PS-Remote,您可以從Linux到Windows進行PS遠端到Windows。
背景資料
偶然發現在我的測試中使用PowerShell遠端處理作為維護系統遠端程式碼執行的主要方法很有用。它是一個內建的Windows功能。不幸的是,由於PowerShell Core的Linux分支支援的身份驗證機制,從我的Kali Linux遠端連線到我的目標並不是一件容易的事。
PowerShell遠端處理需要對Kerberos身份驗證,這意味著客戶端計算機和目標計算機必須都連線到同一域。如果我們沒有可以連線的機器來執行遠端處理,那麼這對測試人員來說可能會造成問題。幸運的是,我們可以選擇將自己新增為目標配置中的 “TrustedHost”
,這將允許我們執行NTLM身份驗證而不是Kerberos,因此無需從域上的系統進行連線。
現在唯一的問題是,用於Linux的PowerShell核心(撰寫本文時為PowerShell 6.1.0)並未支援NTLM身份驗證。幸運的是, Redditors 找到了在Centos上使用PowerShell進行NTLM身份驗證的方法,因此我將他們的發現整合到一個簡單的PowerShell Docker映象 quickbreach / powershell-ntlm中 。
如何使用從Linux到Windows的PowerShell遠端處理
本節將逐步介紹如何從Linux客戶端到Windows目標建立遠端PowerShell會話。假設您對目標PC具有管理訪問許可權(RDP,payload等)。
1.在目標上啟用PowerShell遠端處理
Enable-PSRemoting –Force
2.獲取目標系統上當前 TrustedHost 的列表以供參考
Get-Item WSMan:\localhost\Client\TrustedHosts
3.將自己新增為目標上的 TrustedHost 。這是在Enter-PSSession設定階段使用NTLM身份驗證所必需的,這是唯一可用於通過PowerShell遠端連線從Linux連線到Windows的身份驗證機制。要完成此操作,請執行以下命令之一:使用萬用字元允許所有計算機在對此主機進行身份驗證時使用NTLM
Set-Item WSMan:\localhost\Client\TrustedHosts -Force -Value
或者只將您的IP新增到NTLM身份驗證允許列表中
Set-Item WSMan:\localhost\Client\TrustedHosts -Force -Concatenate -Value 192.168.10.100
4.設定並重新啟動WinRM服務
Set-Service WinRM -StartMode Automatic
Restart-Service -Force WinRM
5.放入PowerShell-NTLM Docker映象的例項。下面的示例命令還在docker映象內的 /mnt
路徑上安裝包含PowerShell指令碼
docker run -it -v /pathTo/PowerShellModules:/mnt quickbreach/powershell-ntlm
6.現在我們一直在等待:使用以下命令進入遠端PowerShell會話 – 請注意,您必須指定-Authentication型別:
# Grab the creds we will be logging in with $creds = Get-Credential # Launch the session # Important: you MUST state theauthentication type as Negotiate Enter-PSSession -ComputerName (Target-IP) -Authentication Negotiate -Credential $creds # i.e. 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}
清除痕跡
如果您的命令之前存在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,則可以刪除所有TrustedHosts
Clear-Item WSMan:\localhost\Client\TrustedHosts
重新啟動WinRM服務以完成更改(請注意,這將使您與Enter-PSSession斷開連線)
Restart-Service WinRM
*參考來源 quickbreach ,由周大濤編譯,轉載請註明來自FreeBuf.COM