关于 detecting-lateral-movement-in-network
面向 SOC 分析师和网络防御团队的横向移动检测技能,指导关联 Windows 身份验证日志、网络流量与 SIEM 规则,以追踪内部主机间的攻击活动。
主要功能
- 01配置 Windows 安全日志采集
- 02编写 SIEM 与 Sigma 检测规则
- 03利用 Zeek 分析 SMB 等网络活动
- 04关联身份验证和连接异常
- 05构建调查时间线与监控仪表板
适用场景
- 01调查 PsExec 或哈希传递活动
- 02追踪异常的内部主机连接
- 03验证网络分段和访问控制
- 04梳理勒索软件横向移动链
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill detecting-lateral-movement-in-network安装后在 Claude Code 中输入/detecting-lateral-movement-in-network确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEreferences/api-reference.mdscripts/agent.py详细介绍
检测网络中的横向移动
适用场景
- 监控企业网络中入侵后横向移动的模式(哈希传递、RDP 跳转、PsExec)
- 为常见的 MITRE ATT&CK 横向移动技术(T1021、T1570)构建 SIEM 检测规则和警报
- 通过分析内部主机之间的身份验证模式和网络连接,调查疑似安全事件
- 搜寻表明攻击者正在网络中横向跳转的异常东西向流量模式
- 验证网络分段和访问控制是否能有效限制横向移动路径
请勿将其作为端点检测与响应(EDR)工具的替代品;请勿在忽略内部流量的情况下仅监控南北向流量;也请勿在不了解正常内部通信模式基线的情况下使用。
前提条件
- 在内部网络关键节点部署网络安全监控(Zeek、Suricata 或网络 TAP)
- 部署 SIEM 平台(Splunk、Elastic、Microsoft Sentinel),用于收集 Windows 安全事件日志、DNS 和流量数据
- 配置 Windows 安全事件日志转发(4624、4625、4648、4672、4768、4769)
- 建立正常内部身份验证和连接模式的基线
- 了解 MITRE ATT&CK 横向移动战术(TA0008)
工作流
步骤 1:配置用于检测横向移动的日志收集
# Windows Event Logs to collect (via WEF or agent):
# Security Log:
# 4624 - Successful logon (Type 3=Network, Type 10=RemoteInteractive)
# 4625 - Failed logon
# 4648 - Logon using explicit credentials (RunAs, PsExec)
# 4672 - Special privileges assigned (admin logon)
# 4768 - Kerberos TGT request
# 4769 - Kerberos service ticket request
# 4776 - NTLM authentication (credential validation)
# System Log:
# 7045 - New service installed (PsExec indicator)
# 7036 - Service started/stopped
# Configure Windows Event Forwarding (WEF) subscription
# On the collector server (PowerShell):
# wecutil cs lateral-movement-subscription.xml
# Filebeat configuration for Windows Event Log shipping
cat > /etc/filebeat/modules.d/security.yml << 'EOF'
- module: system
auth:
enabled: true
var.paths: ["/var/log/auth.log"]
syslog:
enabled: true
- module: zeek
connection:
enabled: true
var.paths: ["/opt/zeek/logs/current/conn.log"]
dns:
enabled: true
var.paths: ["/opt/zeek/logs/current/dns.log"]
smb_mapping:
enabled: true
var.paths: ["/opt/zeek/logs/current/smb_mapping.log"]
dce_rpc:
enabled: true
var.paths: ["/opt/zeek/logs/current/dce_rpc.log"]
EOF
# Zeek configuration for lateral movement detection
# Enable SMB, DCE-RPC, and Kerberos logging
cat >> /opt/zeek/share/zeek/site/local.zeek << 'EOF'
@load policy/protocols/smb
@load policy/protocols/conn/known-hosts
@load policy/protocols/conn/known-services
@load frameworks/intel/seen
EOF
sudo zeekctl deploy
步骤 2:为常见的横向移动技术构建检测规则
# Splunk SPL queries for lateral movement detection
# 1. Detect PsExec usage (new service creation on remote hosts)
# index=wineventlog EventCode=7045 ServiceName="PSEXESVC" OR ServiceName="*psexec*"
# | stats count by ComputerName, ServiceName, ImagePath
# | where count > 0
# 2. Detect Pass-the-Hash (Type 3 logon with NTLM)
# index=wineventlog EventCode=4624 LogonType=3 AuthenticationPackageName="NTLM"
# | where TargetUserName!="ANONYMOUS LOGON" AND TargetUserName!="$"
# | stats count dc(ComputerName) as unique_hosts by TargetUserName, IpAddress
# | where unique_hosts > 3
# 3. Detect RDP lateral movement (Type 10 logon from internal IPs)
# index=wineventlog EventCode=4624 LogonType=10
# | where cidrmatch("10.0.0.0/8", IpAddress) OR cidrmatch("192.168.0.0/16", IpAddress)
# | stats count dc(ComputerName) as rdp_hosts by TargetUserName, IpAddress
# | where rdp_hosts > 2
# Elastic SIEM detection rules (KQL)
# event.code: "4624" and winlog.event_data.LogonType: "3"
# and winlog.event_data.AuthenticationPackageName: "NTLM"
# and not winlog.event_data.TargetUserName: *$
# and source.ip: (10.0.0.0/8 or 172.16.0.0/12 or 192.168.0.0/16)
# Sigma rules for lateral movement detection
# Install sigma and convert to target SIEM format
pip3 install sigma-cli
cat > lateral_movement_pth.yml << 'EOF'
title: Pass-the-Hash Lateral Movement Detection
id: f8d98d6c-7a07-4d74-b064-dd4a3c244528
status: experimental
description: Detects network logon with NTLM authentication to multiple hosts
logsource:
product: windows
service: security
detection:
selection:
EventID: 4624
LogonType: 3
AuthenticationPackageName: NTLM
filter:
TargetUserName|endswith: '$'
condition: selection and not filter
timeframe: 15m
count:
field: ComputerName
min: 3
group-by: TargetUserName
level: high
tags:
- attack.lateral_movement
- attack.t1550.002
EOF
# Convert Sigma rule to Splunk SPL
sigma convert -t splunk lateral_movement_pth.yml
# Convert to Elastic query
sigma convert -t elasticsearch lateral_movement_pth.yml
步骤 3:使用 Zeek 进行网络层检测
# Detect SMB lateral movement (admin$ and c$ share access)
cat /opt/zeek/logs/current/smb_mapping.log | \
zeek-cut ts id.orig_h id.resp_h path | \
grep -iE "(admin\$|c\$|ipc\$)" | \
sort -t$'\t' -k2 | uniq -c | sort -rn
# Detect hosts connecting to many internal hosts on port 445 (SMB spreading)
cat /opt/zeek/logs/current/conn.log | \
zeek-cut ts id.orig_h id.resp_h id.resp_p | \
awk '$4 == 445' | \
awk '{print $2}' | sort | uniq -c | sort -rn | head -10
# Detect WMI lateral movement (DCE-RPC to IWbemServices)
cat /opt/zeek/logs/current/dce_rpc.log | \
zeek-cut ts id.orig_h id.resp_h operation | \
grep -i "wbem\|wmi" | sort | uniq -c | sort -rn
# Detect RDP connections between internal hosts
cat /opt/zeek/logs/current/conn.log | \
zeek-cut ts id.orig_h id.resp_h id.resp_p duration | \
awk '$4 == 3389 && $5 > 60' | \
sort -t$'\t' -k2 | head -20
# Detect Kerberos ticket-granting anomalies
cat /opt/zeek/logs/current/kerberos.log | \
zeek-cut ts id.orig_h id.resp_h client service success error_msg | \
grep -v "true" | head -20
# Custom Zeek script for lateral movement detection
sudo tee /opt/zeek/share/zeek/site/custom-detections/lateral-movement.zeek << 'ZEEKEOF'
@load base/frameworks/notice
@load base/frameworks/sumstats
module LateralMovement;
export {
redef enum Notice::Type += {
SMB_Lateral_Spread,
RDP_Lateral_Chain
};
const smb_host_threshold: count = 5 &redef;
const smb_time_window: interval = 15min &redef;
}
event zeek_init()
{
local r1 = SumStats::Reducer(
$stream="lateral.smb",
$apply=set(SumStats::UNIQUE)
);
SumStats::create([
$name="detect-smb-lateral",
$epoch=smb_time_window,
$reducers=set(r1),
$threshold_val(key: SumStats::Key, result: SumStats::Result) = {
return result["lateral.smb"]$unique + 0.0;
},
$threshold=smb_host_threshold + 0.0,
$threshold_crossed(key: SumStats::Key, result: SumStats::Result) = {
NOTICE([
$note=SMB_Lateral_Spread,
$msg=fmt("Host %s connected to %d SMB hosts in %s",
key$str, result["lateral.smb"]$unique, smb_time_window),
$identifier=key$str
]);
}
]);
}
event connection_state_remove(c: connection)
{
if ( c$id$resp_p == 445/tcp && c$id$resp_h in Site::local_nets )
{
SumStats::observe("lateral.smb",
[$str=cat(c$id$orig_h)],
[$str=cat(c$id$resp_h)]
);
}
}
ZEEKEOF
sudo zeekctl deploy
步骤 4:搜寻横向移动指标
# Hunt for authentication anomalies in Windows logs
# Splunk query: Users authenticating from unusual source hosts
# index=wineventlog EventCode=4624 LogonType=3
# | stats values(IpAddress) as source_ips dc(IpAddress) as source_count by TargetUserName
# | where source_count > 5
# | sort -source_count
# Hunt for service accounts used interactively
# index=wineventlog EventCode=4624 (LogonType=2 OR LogonType=10)
# | where match(TargetUserName, "^svc-.*")
# | table _time ComputerName TargetUserName IpAddress LogonType
# Network flow analysis for lateral movement patterns
# Look for hosts that suddenly start communicating with many internal hosts
cat /opt/zeek/logs/current/conn.log | \
zeek-cut ts id.orig_h id.resp_h | \
awk '{
key = $2
targets[key][$3] = 1
}
END {
for (src in targets) {
count = 0
for (dst in targets[src]) count++
if (count > 20) print src, count
}
}' | sort -k2 -rn
# Detect credential dumping artifacts (large LSASS reads)
# Look for connections from hosts that suddenly pivot
cat /opt/zeek/logs/current/conn.log | \
zeek-cut ts id.orig_h id.resp_h id.resp_p orig_bytes | \
awk '$4 == 445 && $5 > 10000000' | sort -t$'\t' -k5 -rn
# Timeline analysis: map the attack path
# index=wineventlog (EventCode=4624 OR EventCode=7045)
# | eval stage=case(
# EventCode=4624 AND LogonType=3, "Network Logon",
# EventCode=4624 AND LogonType=10, "RDP Logon",
# EventCode=7045, "Service Creation"
# )
# | timechart span=5m count by stage
步骤 5:自动响应和遏制
# SOAR playbook for lateral movement response (pseudocode)
# When lateral movement alert triggers:
# 1. Enrich the alert with context
# - Query AD for user group membership and role
# - Check if source IP is a known admin workstation
# - Look up recent vulnerability scan results for affected hosts
# 2. Automated containment actions
# Option A: Isolate the host via switch port shutdown
# ssh admin@switch "conf t; interface Gi1/0/5; shutdown"
# Option B: Quarantine via VLAN change (less disruptive)
# ssh admin@switch "conf t; interface Gi1/0/5; switchport access vlan 999"
# Option C: Block at firewall
sudo iptables -I FORWARD -s 10.10.5.23 -j DROP
# 3. Disable the compromised account
# PowerShell: Disable-ADAccount -Identity compromised_user
# 4. Force password reset
# PowerShell: Set-ADAccountPassword -Identity compromised_user -Reset
# 5. Collect forensic evidence before full containment
# velociraptor artifact collect Windows.KapeFiles.Targets --target BasicCollection
步骤 6:构建检测仪表板
# Elastic Kibana dashboard queries for lateral movement monitoring
# Panel 1: Authentication heatmap (source vs destination)
# Aggregation: Terms on source.ip (rows) and destination.ip (columns)
# Metric: Count of event.code:4624
# Panel 2: SMB connections between internal hosts
# Filter: destination.port:445 and source.ip:10.0.0.0/8
# Aggregation: Top 20 source IPs by unique destination count
# Panel 3: RDP sessions timeline
# Filter: destination.port:3389 and event.code:4624 and winlog.event_data.LogonType:10
# Visualization: Timeline by source.ip
# Panel 4: New service installations
# Filter: event.code:7045
# Aggregation: Terms on winlog.event_data.ServiceName
# Panel 5: Failed authentication spike detection
# Filter: event.code:4625
# Aggregation: Date histogram with anomaly detection
# Export Kibana dashboard
# curl -X GET "elastic-siem:5601/api/saved_objects/_export" \
# -H "kbn-xsrf: true" \
# -d '{"type":"dashboard","objects":[{"id":"lateral-movement-dashboard","type":"dashboard"}]}' \
# > lateral_movement_dashboard.ndjson
核心概念
| 术语 | 定义 |
|---|---|
| 横向移动 | MITRE ATT&CK 战术(TA0008),描述攻击者从一台已入侵系统移动到另一台系统时使用的技术 |
| 哈希传递(T1550.002) | 使用窃取的 NTLM 密码哈希向远程系统进行身份验证,而无需知道明文密码 |
| PsExec(T1569.002) | 一种远程服务执行工具,会在目标系统上创建临时服务,可通过事件 ID 7045 检测 |
| 东西向流量 | 内部系统之间的网络通信(与内部网络和外部网络之间的南北向流量相对) |
| 身份验证异常 | 偏离基线身份验证模式的情况,例如用户登录了以前从未访问过的系统 |
| Kerberoasting(T1558.003) | 请求服务帐户的 Kerberos 服务票证并离线破解;可通过事件 ID 4769 异常检测 |
工具与系统
- Zeek:网络安全监控器,可生成 SMB、Kerberos、DCE-RPC 和连接日志,用于分析横向移动
- Splunk/Elastic SIEM:日志聚合平台,用于关联整个企业中的身份验证事件、网络流量和服务创建记录
- Sigma:与供应商无关的检测规则格式,可编写适用于多种 SIEM 平台的通用横向移动检测规则
- Velociraptor:端点取证工具,用于从涉及横向移动链的主机收集证据
- BloodHound:Active Directory 攻击路径分析工具,可在攻击者利用潜在横向移动路径之前识别这些路径
常见场景
场景:检测勒索软件操作者的横向移动
背景:SOC 收到一条警报,指出文件服务器(10.10.20.15)于凌晨 2:00 创建了 PsExec 服务。该警报触发了一项横向移动调查。组织使用 Zeek 进行网络监控,并将 Windows 事件日志转发到 Splunk。
方法:
- 在 Splunk 中查询 10.10.20.15 上的事件 ID 7045(服务创建),确认 PsExec 已执行,并确定源 IP(10.10.5.23)
- 追踪 10.10.5.23 的身份验证历史:查找事件 ID 4624、类型 3 的登录记录,发现该主机在过去一小时内使用 NTLM 向 8 台服务器进行身份验证(传递哈希模式)
- 检查 Zeek 的 conn.log 中 10.10.5.23 的记录:识别出与 12 台内部主机的 SMB 连接(端口 445),以及向外部 IP 传输的大量文件
- 构建攻击时间线:凌晨 1:15 通过钓鱼邮件初始入侵,凌晨 1:25 转储凭据,凌晨 1:30 至 2:00 期间横向移动至 8 台服务器
- 通过追踪身份验证链识别所有失陷主机:10.10.5.23 -> 10.10.20.15 -> 10.10.20.16 -> 10.10.20.17
- 将所有已识别主机隔离到 VLAN 999、禁用失陷账户并阻止外部 C2 IP,以遏制攻击
- 报告完整攻击链,包括时间线、受影响主机和检测盲点
注意事项:
- 只调查单条警报,而未追踪所有主机上的完整横向移动链
- 宣布遏制完成前,未检查每台失陷主机上的持久化机制
- 仅依赖 Windows 事件日志而未关联网络流量数据,因而遗漏了使用不会生成 Windows 事件的工具进行的横向移动
- 未建立正常内部身份验证模式的基线,导致无法检测异常
输出格式
## Lateral Movement Investigation Report
**Case ID**: IR-2024-0312
**Initial Alert**: PsExec on 10.10.20.15 at 02:00 UTC
**Investigation Period**: 2024-03-15 01:00 to 03:00 UTC
### Attack Timeline
| Time (UTC) | Source | Destination | Technique | Evidence |
|------------|--------|-------------|-----------|----------|
| 01:15 | External | 10.10.5.23 | Initial Access (Phishing) | Email log + HTTP download |
| 01:25 | 10.10.5.23 | Local | Credential Dumping | LSASS access (Sysmon EID 10) |
| 01:32 | 10.10.5.23 | 10.10.20.15 | Pass-the-Hash (SMB) | EID 4624 Type 3 NTLM |
| 01:38 | 10.10.5.23 | 10.10.20.16 | PsExec | EID 7045 + Zeek SMB |
| 01:45 | 10.10.20.16 | 10.10.20.17 | RDP | EID 4624 Type 10 |
| 02:00 | 10.10.20.17 | 10.10.20.15 | PsExec (triggered alert) | EID 7045 |
| 02:10 | 10.10.5.23 | 203.0.113.50 | Data Exfiltration | Zeek conn.log 2.3 GB |
### Affected Systems
- 10.10.5.23 (workstation-045) - Initial compromise
- 10.10.20.15 (file-server-01) - Data accessed
- 10.10.20.16 (app-server-02) - Pivoted through
- 10.10.20.17 (db-server-01) - Final target
### Detection Gaps
1. Initial phishing email not blocked by email gateway
2. Credential dumping not detected (no LSASS monitoring)
3. 30-minute gap between first lateral movement and alert
评论
支持 Markdown