atta1339/Splunk-Threat-Hunting-Analytics
GitHub: atta1339/Splunk-Threat-Hunting-Analytics
基于 Splunk SPL 的威胁狩猎分析项目,利用网络流量时间间隔方差统计来检测自动化 C2 信标通信。
Stars: 0 | Forks: 0
# Splunk-Threat-Hunting-Analytics
在 Splunk SPL 中利用时间间隔方差进行统计分析,以识别自动化 C2 beaconing 的检测工程分析。
威胁检测工程:基于时间间隔方差的自动化 C2 Beaconing 分析
作者:Atta
目标平台:Splunk Enterprise / Enterprise Security
类别:网络威胁狩猎与检测工程
MITRE ATT&CK 映射:Command and Control: Application Layer Protocol (T1071)
1. 执行摘要
传统的基于特征的安全控制往往无法检测到通过加密协议(例如 443 端口上的 HTTPS)运行的 Command and Control (C2) 通道。现代 C2 框架(如 Cobalt Strike、Covenant 或 Sliver)通过在固定或具有极小抖动的时间间隔内发送可预测的、自动化的 "beacon" 进行通信。
本项目在 Splunk (SPL) 中实现了一种统计检测分析,利用时间序列差值计算(streamstats variance)来识别非人类、固定间隔的网络连接,同时抑制良性的网络噪声(例如,NTP 流量、标准 OS 遥测数据)。
2. 检测逻辑与 SPL 架构
技术方法
差值计算:使用 streamstats 计算每个 (src_ip, dest_domain) 对之间连续出站网络请求的时间差 (Δt)。
统计方差:计算给定目标所有时间间隔的方差 (var(time_gap))。接近零的方差表示固定间隔的非人类流量。
上下文过滤:排除众所周知的协议端口(例如,NTP 的 UDP/123,DNS 的 UDP/53)和低频连接,以抑制误报。
生产环境 SPL 查询
Splunk SPL
index=network sourcetype=pan:traffic ACTION=allowed
| fields _time src_ip dest_domain dest_port
| sort 0 _time
| streamstats current=f last(_time) as next_time by src_ip, dest_domain
| eval time_gap = next_time - _time
| stats count, avg(time_gap) as avg_interval, var(time_gap) as gap_variance by src_ip, dest_domain, dest_port
| where dest_port!=123 AND dest_port!=53 AND count > 10 AND gap_variance < 1
3. 模拟与验证策略
为了在没有活动网络传感器的本地实验环境中验证检测逻辑,我们使用 Splunk 的 makeresults 命令构建了一个合成数据管道,以模拟三种不同的流量特征:
恶意 C2 通道 (evil-c2-server.com):443 端口上具有严格 5 秒间隔的 beaconing。
合法 NTP 同步 (time.windows.com):123 端口上的低方差。
标准用户网页浏览 (google.com):具有随机时间间隔 (random()%300) 的高方差。
实验室概念验证 SPL
Splunk SPL
| makeresults count=100
| streamstats count as id
| eval src_ip="192.168.1.50"
| eval dest_domain=case(
id%4==0, "evil-c2-server.com",
id%7==0, "time.windows.com",
1=1, "google.com")
| eval dest_port=case(
dest_domain=="time.windows.com", 123,
1=1, 443)
| eval _time=case(
dest_domain=="evil-c2-server.com", _time + (id * 5),
dest_domain=="time.windows.com", _time + (id * 10),
1=1, _time + (id * random()%300))
| sort 0 _time
| streamstats current=f last(_time) as next_time by src_ip, dest_domain
| eval time_gap = next_time - _time
| stats count, avg(time_gap) as avg_interval, var(time_gap) as gap_variance by src_ip, dest_domain, dest_port
| where dest_port!=123 AND dest_port!=53 AND count > 5 AND gap_variance < 1
验证结果
google.com:由于浏览间隔不规则,被 gap_variance < 1 阈值过滤掉。
time.windows.com:被协议抑制机制 (dest_port!=123) 过滤掉。
evil-c2-server.com:成功标记。在 443 端口上返回 25 个命中结果,方差准确为 0。
4. 误报调优与已知边缘情况
来源 / 模式 根本原因 缓解措施 / 调优规则
内部监控代理 Datadog / Splunk Universal Forwarders 定期 ping 端点。 维护域名/IP查找表 (inputlookup host_allowlist.csv) 以排除受管理的遥测服务器。
NTP 和网络时间服务 固定的 10 分钟 / 1 小时时间更新检查。 显式协议抑制 (dest_port NOT IN (123))。
高抖动 C2 框架 攻击者向 beacon 信号添加随机延迟(>30% 抖动)。 扩大可接受的 gap_variance 阈值,或者针对嘈杂的 C2 设置转向使用标准差 / 极差指标。
5. SOC 事件响应剧本
[ SIEM 警报触发 ]
│
▼
┌──────────────────────────────────┐
│ 阶段 1: 初步分诊 (0-15m) │
│ - 在威胁情报中验证域名 │
│ - 对照 IT 白名单进行检查 │
└────────────────┬─────────────────┘
│
▼
┌──────────────────────────────────┐
│ 阶段 2: 端点关联 │
│ - 查询 Sysmon EventCode 3 │
│ - 识别父进程 / ID │
└────────────────┬─────────────────┘
│
▼
┌──────────────────────────────────┐
│ 阶段 3: 遏制 │
│ - 通过 EDR / NAC 隔离主机 │
│ - 在防火墙上阻断 C2 域名 │
│ - 重置受感染用户的凭证 │
└──────────────────────────────────┘
分析师快速参考查询
24 小时流量扩展:
Splunk SPL
index=network src_ip="" dest_domain=""
| stats count, sum(bytes_out) as total_bytes_out by dest_port, ACTION
Sysmon 端点进程识别 (Event ID 3):
Splunk SPL
index=endpoint EventCode=3 SourceIp="" DestinationHostname=""
| table _time, Image, ProcessId, User, DestinationPort
您现在拥有了一个完整且经过测试、调优和充分文档记录的生产级检测 pipeline!您可以随时准备好使用优化后的查询来更新 Splunk 中现有的计划警报。
标签:AMSI绕过, IP 地址批量处理, 代码示例, 威胁检测, 安全运营, 扫描框架, 数据分析, 网络安全, 隐私保护