Analyzes malware PCAPs from sandbox or incident response using Wireshark, tshark, Zeek, Suricata to detect C2 protocols, data exfiltration, DNS tunneling, payload downloads, and lateral movement.
npx claudepluginhub killvxk/cybersecurity-skills-zhThis skill uses the workspace's default tool permissions.
- 沙箱执行已捕获 PCAP 文件,需要详细分析网络行为
Analyzes malware network traffic in PCAPs using Wireshark, Zeek, Suricata to detect C2 protocols, exfiltration channels, payload downloads, and lateral movement.
Analyzes malware PCAPs with tshark, Zeek, Suricata, and Python to detect C2 protocols, data exfiltration, DGA, and lateral movement patterns during sandbox or incident response.
Analyzes PCAPs, Zeek logs, and NetFlow data to detect C2 beacons, lateral movement, data exfiltration, and exploit attempts in security incidents using Wireshark and tcpdump.
Share bugs, ideas, or general feedback.
不适用于恶意软件行为的基于主机的分析;请使用 Cuckoo 沙箱报告或 Volatility 内存分析进行进程级活动分析。
scapy 和 dpkt 用于程序化数据包分析获取网络流量的高层次理解:
# 捕获统计
capinfos malware.pcap
# 协议层次
tshark -r malware.pcap -q -z io,phs
# 端点统计(主要通信方)
tshark -r malware.pcap -q -z endpoints,ip
# 会话统计
tshark -r malware.pcap -q -z conv,tcp
# DNS 查询摘要
tshark -r malware.pcap -q -z dns,tree
检查 DNS 查询中的 DGA、隧道或 C2 域名解析:
# 提取所有 DNS 查询
tshark -r malware.pcap -T fields -e frame.time -e dns.qry.name -e dns.a \
-Y "dns.flags.response == 1" | sort
# 检测 DGA 模式(高熵域名)
python3 << 'PYEOF'
import math
from collections import Counter
def entropy(s):
p = [n/len(s) for n in Counter(s).values()]
return -sum(pi * math.log2(pi) for pi in p if pi > 0)
# 从 tshark 输出解析 DNS 查询
import subprocess
result = subprocess.run(
["tshark", "-r", "malware.pcap", "-T", "fields", "-e", "dns.qry.name",
"-Y", "dns.flags.response == 0"],
capture_output=True, text=True
)
domains = set(result.stdout.strip().split('\n'))
print("可疑 DNS 查询(高熵):")
for domain in domains:
if domain:
subdomain = domain.split('.')[0]
ent = entropy(subdomain)
if ent > 3.5 and len(subdomain) > 10:
print(f" {domain}(熵值:{ent:.2f})")
PYEOF
# 检测 DNS 隧道(大型 TXT 响应)
tshark -r malware.pcap -T fields -e dns.qry.name -e dns.txt \
-Y "dns.resp.type == 16 and dns.resp.len > 100"
检查基于 Web 的命令与控制流量:
# 提取 HTTP 请求
tshark -r malware.pcap -T fields \
-e frame.time -e ip.src -e ip.dst -e http.host \
-e http.request.method -e http.request.uri -e http.user_agent \
-Y "http.request"
# 提取 HTTP 响应体(潜在的载荷下载)
tshark -r malware.pcap -T fields \
-e http.host -e http.request.uri -e http.content_type -e tcp.len \
-Y "http.response and tcp.len > 1000"
# 提取 POST 数据(潜在的数据泄露)
tshark -r malware.pcap -T fields \
-e http.host -e http.request.uri -e http.file_data \
-Y "http.request.method == POST"
# TLS 分析(SNI、JA3 指纹)
tshark -r malware.pcap -T fields \
-e tls.handshake.extensions_server_name \
-e tls.handshake.ja3 \
-Y "tls.handshake.type == 1"
# 提取 TLS 证书详情
tshark -r malware.pcap -T fields \
-e x509ce.dNSName -e x509af.serialNumber \
-e x509sat.utf8String \
-Y "tls.handshake.type == 11"
# 导出 HTTP 对象(下载的文件)
tshark -r malware.pcap --export-objects http,exported_files/
识别表明 C2 信标的规律周期性通信:
# 从 PCAP 进行信标检测
from scapy.all import rdpcap, IP, TCP
from collections import defaultdict
import statistics
packets = rdpcap("malware.pcap")
# 按目标 IP:端口分组连接
connections = defaultdict(list)
for pkt in packets:
if IP in pkt and TCP in pkt:
if pkt[TCP].flags & 0x02: # SYN 标志
dst = f"{pkt[IP].dst}:{pkt[TCP].dport}"
connections[dst].append(float(pkt.time))
# 分析时序间隔以检测信标
print("信标分析:")
for dst, times in connections.items():
if len(times) >= 5:
intervals = [times[i+1] - times[i] for i in range(len(times)-1)]
avg = statistics.mean(intervals)
stdev = statistics.stdev(intervals) if len(intervals) > 1 else 0
jitter = (stdev / avg * 100) if avg > 0 else 0
if 10 < avg < 3600 and jitter < 30: # 抖动 < 30% 的规律间隔
print(f" [!] {dst}:{len(times)} 次连接")
print(f" 间隔:{avg:.1f}s ± {stdev:.1f}s(抖动:{jitter:.1f}%)")
print(f" 模式:可能是信标")
根据观察到的流量模式创建 Suricata/Snort 规则:
# 对 PCAP 运行 Suricata 以匹配现有签名
suricata -r malware.pcap -l suricata_output/ -c /etc/suricata/suricata.yaml
# 查看告警
cat suricata_output/fast.log
# 根据观察到的模式创建自定义 Suricata 规则
cat << 'EOF' > custom_malware.rules
# 基于观察到的 URI 模式的 C2 信标检测
alert http $HOME_NET any -> $EXTERNAL_NET any (
msg:"MALWARE MalwareX C2 Beacon";
flow:established,to_server;
http.method; content:"POST";
http.uri; content:"/gate.php?id=";
http.user_agent; content:"Mozilla/5.0 (compatible; MSIE 10.0)";
sid:9000001; rev:1;
)
# 已知 C2 域名的 DNS 查询
alert dns $HOME_NET any -> any any (
msg:"MALWARE MalwareX C2 DNS Query";
dns.query; content:"update.malicious.com";
sid:9000002; rev:1;
)
# 恶意软件 TLS 客户端的 JA3 哈希匹配
alert tls $HOME_NET any -> $EXTERNAL_NET any (
msg:"MALWARE MalwareX JA3 Match";
ja3.hash; content:"a0e9f5d64349fb13191bc781f81f42e1";
sid:9000003; rev:1;
)
EOF
恢复传输的文件和嵌入数据:
# 使用 Zeek 提取文件
zeek -r malware.pcap /opt/zeek/share/zeek/policy/frameworks/files/extract-all-files.zeek
ls extract_files/
# 使用 NetworkMiner 提取文件(GUI)
# 或使用 tshark 导出特定协议
tshark -r malware.pcap --export-objects http,http_objects/
tshark -r malware.pcap --export-objects smb,smb_objects/
tshark -r malware.pcap --export-objects tftp,tftp_objects/
# 对所有提取的文件计算哈希值
sha256sum http_objects/* smb_objects/* 2>/dev/null
# 生成 Zeek 日志以获取全面的元数据
zeek -r malware.pcap
# 输出:conn.log, dns.log, http.log, ssl.log, files.log 等
| 术语 | 定义 |
|---|---|
| 信标(Beaconing) | 恶意软件到 C2 服务器的规律性周期连接,通过一致的时间间隔和数据包大小识别 |
| JA3/JA3S | TLS 指纹方法,通过 ClientHello/ServerHello 参数创建哈希值,唯一标识恶意软件 TLS 实现 |
| DGA(域名生成算法) | 生成恶意软件查询以定位 C2 服务器的伪随机域名的算法,规避静态域名黑名单 |
| DNS 隧道 | 将数据编码在 DNS 查询和响应中,通过 DNS 基础设施建立 C2 信道或泄露数据 |
| 快速通量(Fast Flux) | DNS 技术,快速轮换域名的 IP 地址以避免下线,并将 C2 分布到许多被攻陷的主机 |
| SNI(服务器名称指示) | TLS 扩展,显示客户端连接的主机名;即使在加密的 HTTPS 连接中也可见 |
| 网络签名 | Suricata/Snort 规则,匹配网络流量(头部、载荷、时序)中的特定模式以检测恶意通信 |
场景背景:恶意软件通过 TCP 端口 8443 使用自定义二进制协议与 C2 服务器通信。标准 HTTP 分析无结果。需要从 PCAP 逆向工程协议结构。
方法:
常见陷阱:
恶意软件网络流量分析
===================================
PCAP 文件: malware_sandbox.pcap
时长: 300 秒
总数据包: 12,847
总字节数: 4.2 MB
DNS 活动
总查询数: 47
检测到 DGA: 是(23 个高熵查询到 .com TLD)
隧道: 否
解析的 C2: update.malicious[.]com -> 185.220.101[.]42
C2 通信
协议: HTTPS(TLS 1.2)
服务器: 185.220.101[.]42:443
SNI: update.malicious[.]com
JA3 哈希: a0e9f5d64349fb13191bc781f81f42e1
信标间隔: 60.2s ± 6.8s(抖动 11.3%)
总会话数: 237
发送数据: 147 MB
接收数据: 2.3 MB
证书: CN=update.malicious[.]com(自签名,已过期)
载荷下载
GET /payload.dll from compromised-site[.]com
大小:98,304 字节
SHA-256:abc123def456...
Content-Type:application/octet-stream
数据泄露
方法: HTTPS POST 到 /gate.php
Content-Type: application/octet-stream
平均大小: 每次请求 15,432 字节
总量: 4 小时内 147 MB
SURICATA 告警
[1:2028401] ET MALWARE Generic C2 Beacon Pattern
[1:2028500] ET POLICY Self-Signed Certificate
生成的签名
SID 9000001:MalwareX HTTP 信标模式
SID 9000002:MalwareX DNS C2 域名
SID 9000003:MalwareX JA3 TLS 指纹