mcpField
A
analyzing-network-traffic-with-wireshark

analyzing-network-traffic-with-wireshark

github.com/mukul975安全35.2k537 次安装8 周前更新
代码仓库

关于 analyzing-network-traffic-with-wireshark

面向安全分析人员的 Wireshark 流量分析技能,涵盖抓包、协议检查、异常排查和证据导出,使用 Wireshark 与 tshark 处理网络流量。

主要功能

  1. 01配置接口与抓包过滤器
  2. 02应用显示过滤器筛选流量
  3. 03分析协议与 TCP 会话
  4. 04导出文件及威胁指标
  5. 05生成统计数据与报告

适用场景

  1. 01调查入侵与数据外传
  2. 02排查重传或 DNS 故障
  3. 03检查恶意软件通信模式
  4. 04验证防火墙和 IDS 规则

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill analyzing-network-traffic-with-wireshark

安装后在 Claude Code 中输入/analyzing-network-traffic-with-wireshark确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
references/
api-reference.md
scripts/
agent.py

详细介绍

使用 Wireshark 分析网络流量

适用场景

  • 通过检查命令与控制流量、数据外泄或横向移动的数据包级证据,调查疑似网络入侵
  • 诊断网络性能问题,例如重传、分片或 DNS 解析失败
  • 通过捕获沙箱或隔离主机的流量,分析恶意软件通信模式
  • 验证防火墙和 IDS 规则,确认网络分段上实际传输的流量
  • 从捕获的网络会话中提取文件、凭据或入侵指标

请勿使用于未经授权捕获网络流量、在无法律授权的情况下拦截私人通信,或将其作为生产监控中全功能 SIEM 平台的替代品。

前提条件

  • 已安装 Wireshark 4.0+ 和 tshark 命令行实用工具
  • 具备 root/sudo 权限或属于 wireshark 组,以便进行实时数据包捕获
  • 可访问受监控网段的网络接口(物理网卡、span 端口或网络分流器)
  • 为数据包捕获文件预留足够的磁盘空间(在繁忙的千兆链路上,估计每分钟 1 GB)
  • 熟悉数据包级别的 TCP/IP 协议、HTTP、DNS、TLS 和 SMB

工作流

步骤 1:配置捕获环境

设置捕获接口和过滤器,以定位相关流量:

# List available interfaces
tshark -D

# Start capture on eth0 with a capture filter to limit scope
tshark -i eth0 -f "host 10.10.5.23 and (port 80 or port 443 or port 445)" -w /tmp/capture.pcapng

# Capture with ring buffer to manage disk usage (10 files, 100MB each)
tshark -i eth0 -b filesize:102400 -b files:10 -w /tmp/rolling_capture.pcapng

# Capture on multiple interfaces simultaneously
tshark -i eth0 -i eth1 -w /tmp/multi_interface.pcapng

对于 Wireshark GUI,请在开始前于“Capture Options”对话框中设置捕获过滤器。

步骤 2:应用显示过滤器进行针对性分析
# Filter HTTP traffic containing suspicious user agents
tshark -r capture.pcapng -Y "http.user_agent contains \"curl\" or http.user_agent contains \"Wget\""

# Find DNS queries to suspicious TLDs
tshark -r capture.pcapng -Y "dns.qry.name contains \".xyz\" or dns.qry.name contains \".top\" or dns.qry.name contains \".tk\""

# Identify TCP retransmissions indicating network issues
tshark -r capture.pcapng -Y "tcp.analysis.retransmission"

# Filter SMB traffic for lateral movement detection
tshark -r capture.pcapng -Y "smb2.cmd == 5 or smb2.cmd == 3" -T fields -e ip.src -e ip.dst -e smb2.filename

# Find cleartext credential transmission
tshark -r capture.pcapng -Y "ftp.request.command == \"PASS\" or http.authbasic"

# Detect beaconing patterns (regular interval connections)
tshark -r capture.pcapng -Y "ip.dst == 203.0.113.50" -T fields -e frame.time_relative -e ip.src -e tcp.dstport
步骤 3:协议特定的深度分析
# Follow a TCP stream to reconstruct a conversation
tshark -r capture.pcapng -q -z follow,tcp,ascii,0

# Analyze HTTP request/response pairs
tshark -r capture.pcapng -Y "http" -T fields -e frame.time -e ip.src -e ip.dst -e http.request.method -e http.request.uri -e http.response.code

# Extract DNS query/response statistics
tshark -r capture.pcapng -q -z dns,tree

# Analyze TLS handshakes for weak cipher suites
tshark -r capture.pcapng -Y "tls.handshake.type == 2" -T fields -e ip.src -e ip.dst -e tls.handshake.ciphersuite

# SMB file access enumeration
tshark -r capture.pcapng -Y "smb2" -T fields -e frame.time -e ip.src -e ip.dst -e smb2.filename -e smb2.cmd
步骤 4:提取产物和 IOC
# Export HTTP objects (files transferred over HTTP)
tshark -r capture.pcapng --export-objects http,/tmp/http_objects/

# Export SMB objects (files transferred over SMB)
tshark -r capture.pcapng --export-objects smb,/tmp/smb_objects/

# Extract all unique destination IPs for threat intelligence lookup
tshark -r capture.pcapng -T fields -e ip.dst | sort -u > unique_dest_ips.txt

# Extract SSL/TLS certificate information
tshark -r capture.pcapng -Y "tls.handshake.type == 11" -T fields -e x509sat.uTF8String -e x509ce.dNSName

# Extract all URLs accessed
tshark -r capture.pcapng -Y "http.request" -T fields -e http.host -e http.request.uri | sort -u > urls.txt

# Hash extracted files for IOC matching
find /tmp/http_objects/ -type f -exec sha256sum {} \; > extracted_file_hashes.txt
步骤 5:统计分析与异常检测
# Protocol hierarchy statistics
tshark -r capture.pcapng -q -z io,phs

# Conversation statistics sorted by bytes
tshark -r capture.pcapng -q -z conv,tcp -z conv,udp

# Identify top talkers
tshark -r capture.pcapng -q -z endpoints,ip

# IO graph data (packets per second)
tshark -r capture.pcapng -q -z io,stat,1,"COUNT(frame) frame"

# Detect port scanning patterns
tshark -r capture.pcapng -Y "tcp.flags.syn == 1 and tcp.flags.ack == 0" -T fields -e ip.src -e tcp.dstport | sort | uniq -c | sort -rn | head -20
步骤 6:生成报告并导出证据
# Export filtered packets to a new PCAP for evidence preservation
tshark -r capture.pcapng -Y "ip.addr == 10.10.5.23 and tcp.port == 4444" -w evidence_c2_traffic.pcapng

# Generate packet summary in CSV format
tshark -r capture.pcapng -T fields -E header=y -E separator=, -e frame.number -e frame.time -e ip.src -e ip.dst -e ip.proto -e tcp.srcport -e tcp.dstport -e frame.len > traffic_summary.csv

# Create PDML (XML) output for programmatic analysis
tshark -r capture.pcapng -T pdml > capture_analysis.xml

# Calculate capture file hash for chain of custody
sha256sum capture.pcapng > capture_hash.txt

关键概念

术语定义
捕获过滤器 (BPF)在捕获时应用的 Berkeley Packet Filter 语法,用于限制记录哪些数据包,从而减小文件大小并提升性能
显示过滤器Wireshark 特有的过滤器语法,应用于已捕获的数据包,以便在不更改捕获文件的情况下进行聚焦分析
PCAPNG下一代数据包捕获格式,可在单个文件中支持多个接口、名称解析、注释和元数据
TCP 流表示两个端点之间完整双向对话的 TCP 段重组序列
协议解析器Wireshark 模块,用于解码特定协议的字段和结构,从而实现对数据包内容的深度检查
IO 图捕获期间数据包或字节速率的时间序列可视化,可用于识别流量峰值或信标行为

工具与系统

  • Wireshark 4.0+:基于 GUI 的数据包分析器,支持 3,000+ 种协议的协议解析器、流重组和导出功能
  • tshark:Wireshark 的命令行版本,用于无头捕获、批处理和脚本化分析流水线
  • tcpdump:轻量级数据包捕获工具,用于在没有 GUI 依赖的远程系统上快速捕获
  • mergecap:Wireshark 实用工具,用于将多个捕获文件合并为单个 PCAP,以便统一分析
  • editcap:Wireshark 实用工具,用于拆分、过滤捕获文件并在不同捕获文件格式之间转换

常见场景——待补充

场景:调查疑似通过 DNS 隧道进行的数据外泄

背景:SOC 团队检测到来自一台工作站(10.10.3.45)发往某个外部域的 DNS 查询量异常偏高。SIEM 告警将该 DNS 查询标记为平均每分钟 200 次,而基线为 15 次。已从该工作站所在 VLAN 的网络分路器(network tap)启动数据包捕获。

方法:

  1. 使用 tshark -i eth2 -f "host 10.10.3.45 and port 53" -w dns_exfil_investigation.pcapng 从该工作站所在子网捕获流量
  2. 分析 DNS 查询模式:tshark -r dns_exfil_investigation.pcapng -Y "dns.qry.name contains \"suspect-domain.xyz\"" -T fields -e frame.time -e dns.qry.name
  3. 检查子域标签中是否包含编码数据(类似 base64 的超长子域表明存在隧道):tshark -r dns_exfil_investigation.pcapng -Y "dns.qry.type == 16" -T fields -e dns.qry.name -e dns.txt
  4. 通过汇总查询名称长度来计算数据量,以估算外泄带宽
  5. 提取唯一查询名称并解码 base64 子域,以还原被外泄的内容
  6. 将证据数据包导出为单独的 PCAP 并生成 SHA-256 哈希,用于证据保管链

注意事项:

  • 在繁忙网络上捕获未经过滤的流量,导致在收集到相关数据之前磁盘空间就已耗尽
  • 使用显示过滤器而非捕获过滤器,导致文件巨大、处理缓慢
  • 忽视加密 DNS(DoH/DoT)流量,此类流量会绕过端口 53 上的传统 DNS 捕获
  • 未能为取证证据建立数据包捕获哈希和证据保管链文档

输出格式

## Traffic Analysis Report

**Case ID**: IR-2024-0847
**Capture File**: dns_exfil_investigation.pcapng
**SHA-256**: a3f2b8c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1
**Duration**: 2024-03-15 14:00:00 to 14:45:00 UTC
**Source Interface**: eth2 (VLAN 30 span port)

### Findings

**1. DNS Tunneling Confirmed**
- Source: 10.10.3.45
- Destination DNS: 8.8.8.8 (forwarded to ns1.suspect-domain.xyz)
- Query volume: 9,247 queries in 45 minutes (205/min vs 15/min baseline)
- Average subdomain label length: 63 characters (base64-encoded data)
- Estimated data exfiltrated: ~2.3 MB via TXT record responses

**2. Indicators of Compromise**
- Domain: suspect-domain.xyz (registered 3 days prior)
- Nameserver: ns1.suspect-domain.xyz (203.0.113.50)
- Query pattern: TXT record requests with base64-encoded subdomains
- Response pattern: TXT records containing base64-encoded payloads

评论

支持 Markdown