Communitygithub.com

使用Wireshark分析网络流量

使用Wireshark和tshark捕获并分析网络数据包。

使用Wireshark分析网络流量 是什么?

该技能专为安全分析师、网络工程师和取证调查人员设计,提供了一套利用Wireshark和tshark进行系统化网络数据包捕获与分析的工作流程。它覆盖了从配置捕获环境、应用显示过滤器进行针对性分析,到协议特定深度解析、提取文件、凭证和入侵指标(IOC),以及生成统计数据用于异常检测等完整环节。技能支持任意支持Wireshark的平台(Linux、Windows、macOS),详细演示了如何检测DNS隧道、数据泄露、横向移动、端口扫描和弱加密套件等安全威胁。通过结合命令行工具tshark与Wireshark GUI,用户既可以在无头服务器上执行自动化批量处理,也能通过图形界面进行交互式深度分析。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mukul975/Anthropic-Cybersecurity-Skills/tree/main/skills/analyzing-network-traffic-with-wireshark

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

使用Wireshark分析网络流量 是做什么的?

何时使用

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

不要在未经授权的情况下捕获网络流量,在没有法律授权的情况下拦截私人通信,或在生产监控中替代全功能SIEM平台。

前提条件

  • 已安装Wireshark 4.0+和tshark命令行工具
  • 具有root/sudo权限,或是wireshark组成员以进行实时数据包捕获
  • 能够访问目标监控网段的网络接口(物理NIC、端口镜像或网络测试接入点)
  • 有足够的磁盘空间存储数据包捕获文件(在繁忙的千兆链路上,估计每分钟约1 GB)
  • 熟悉TCP/IP协议、HTTP、DNS、TLS和SMB在数据包层面的细节

工作流程

步骤1:配置捕获环境

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

# 列出可用的接口
tshark -D

# 在eth0上启动捕获,使用捕获过滤器限定范围
tshark -i eth0 -f "host 10.10.5.23 and (port 80 or port 443 or port 445)" -w /tmp/capture.pcapng

# 使用环形缓冲区管理磁盘使用(10个文件,每个100MB)
tshark -i eth0 -b filesize:102400 -b files:10 -w /tmp/rolling_capture.pcapng

# 同时在多个接口上捕获
tshark -i eth0 -i eth1 -w /tmp/multi_interface.pcapng

对于Wireshark GUI,在开始之前在捕获选项对话框中设置捕获过滤器。

步骤2:应用显示过滤器进行针对性分析

# 过滤包含可疑用户代理的HTTP流量
tshark -r capture.pcapng -Y "http.user_agent contains \"curl\" or http.user_agent contains \"Wget\""

# 查找针对可疑TLD的DNS查询
tshark -r capture.pcapng -Y "dns.qry.name contains \".xyz\" or dns.qry.name contains \".top\" or dns.qry.name contains \".tk\""

# 识别指示网络问题的TCP重传
tshark -r capture.pcapng -Y "tcp.analysis.retransmission"

# 过滤SMB流量以检测横向移动
tshark -r capture.pcapng -Y "smb2.cmd == 5 or smb2.cmd == 3" -T fields -e ip.src -e ip.dst -e smb2.filename

# 查找明文凭证传输
tshark -r capture.pcapng -Y "ftp.request.command == \"PASS\" or http.authbasic"

# 检测信标模式(规律间隔的连接)
tshark -r capture.pcapng -Y "ip.dst == 203.0.113.50" -T fields -e frame.time_relative -e ip.src -e tcp.dstport

步骤3:协议特定深度分析

# 跟踪一个TCP流以重建对话
tshark -r capture.pcapng -q -z follow,tcp,ascii,0

# 分析HTTP请求/响应对
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

# 提取DNS查询/响应统计信息
tshark -r capture.pcapng -q -z dns,tree

# 分析TLS握手以查找弱加密套件
tshark -r capture.pcapng -Y "tls.handshake.type == 2" -T fields -e ip.src -e ip.dst -e tls.handshake.ciphersuite

# SMB文件访问枚举
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

# 导出HTTP对象(通过HTTP传输的文件)
tshark -r capture.pcapng --export-objects http,/tmp/http_objects/

# 导出SMB对象(通过SMB传输的文件)
tshark -r capture.pcapng --export-objects smb,/tmp/smb_objects/

# 提取所有唯一目标IP以进行威胁情报查询
tshark -r capture.pcapng -T fields -e ip.dst | sort -u > unique_dest_ips.txt

# 提取SSL/TLS证书信息
tshark -r capture.pcapng -Y "tls.handshake.type == 11" -T fields -e x509sat.uTF8String -e x509ce.dNSName

# 提取所有访问过的URL
tshark -r capture.pcapng -Y "http.request" -T fields -e http.host -e http.request.uri | sort -u > urls.txt

# 对提取的文件进行哈希,用于IOC匹配
find /tmp/http_objects/ -type f -exec sha256sum {} \; > extracted_file_hashes.txt

步骤5:统计分析及异常检测

# 协议层级统计
tshark -r capture.pcapng -q -z io,phs

# 按字节排序的会话统计
tshark -r capture.pcapng -q -z conv,tcp -z conv,udp

# 识别最活跃的通信主机
tshark -r capture.pcapng -q -z endpoints,ip

# IO图表数据(每秒数据包数)
tshark -r capture.pcapng -q -z io,stat,1,"COUNT(frame) frame"

# 检测端口扫描模式
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:生成报告并导出证据

# 将过滤后的数据包导出到新的PCAP文件,用于证据保存
tshark -r capture.pcapng -Y "ip.addr == 10.10.5.23 and tcp.port == 4444" -w evidence_c2_traffic.pcapng

# 以CSV格式生成数据包摘要
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

# 创建PDML(XML)输出以进行程序化分析
tshark -r capture.pcapng -T pdml > capture_analysis.xml

# 计算捕获文件哈希以维护监管链
sha256sum capture.pcapng > capture_hash.txt

关键概念

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

工具与系统

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

常见场景

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

背景:SOC团队检测到一台工作站(10.10.3.45)向一个外部域发起的DNS查询量异常高。SIEM告警显示,DNS查询平均每分钟200次,而基线为15次。从工作站所在VLAN的网络测试接入点启动了数据包捕获。

方法:

  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哈希以维护监管链

注意事项:

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

输出格式

## 流量分析报告

**案例编号**: IR-2024-0847
**捕获文件**: dns_exfil_investigation.pcapng
**SHA-256**: a3f2b8c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1
**持续时间**: 2024-03-15 14:00:00 至 14:45:00 UTC
**源接口**: eth2(VLAN 30端口镜像)

### 发现

**1. DNS隧道确认**
- 源IP:10.10.3.45
- 目标DNS:8.8.8.8(转发至 ns1.suspect-domain.xyz)
- 查询量:45分钟内9,247次查询(205次/分钟,基线为15次/分钟)
- 平均子域标签长度:63字符(base64编码数据)
- 估计泄露数据量:约2.3 MB(通过TXT记录响应)

**2. 入侵指标**
- 域名:suspect-domain.xyz(3天前注册)
- 名称服务器:ns1.suspect-domain.xyz (203.0.113.50)
- 查询模式:带有base64编码子域的TXT记录请求
- 响应模式:包含base64编码载荷的TXT记录

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

abusing-dpapi-for-credential-access

Extract and decrypt Windows DPAPI-protected secrets (Credential Manager, browser logins/cookies, Wi-Fi credentials, KeePass keys) online or offline using SharpDPAPI, SharpChrome, Mimikatz, or Impacket

abusing-shadow-credentials-for-privesc

Take over Active Directory accounts by writing attacker-controlled public keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, or Certipy, then authenticate via PKINIT to recover the target

achieving-cmmc-level-2-compliance

>-

acquiring-disk-image-with-dd-and-dcfldd

Create forensically sound bit-for-bit disk images with dd or dcfldd on a Linux forensic workstation, preserving evidence integrity through hash verification (MD5/SHA) during acquisition. Use when imaging a suspect drive, USB device, or memory card for investigation, preserving volatile disk evidence during incident response, or producing a verified copy for legal or law-enforcement proceedings before any destructive analysis.

analyzing-active-directory-acl-abuse

Detect dangerous ACL misconfigurations in Active Directory using ldap3

analyzing-android-malware-with-apktool

Perform static analysis of Android APK malware using apktool for resource decompilation, jadx for Java source recovery, and androguard for manifest inspection, dangerous permission-combination detection, and identification of obfuscated code, dynamic code loading, and reflection-based API calls. Use to statically triage a suspicious APK without executing it or to build mobile malware detection rules.

analyzing-api-gateway-access-logs

Parses API Gateway access logs (AWS API Gateway, Kong, Nginx) to detect

analyzing-apt-group-with-mitre-navigator

Query ATT&CK data with attackcti, mitreattack-python, and stix2, then build MITRE ATT&CK Navigator layers and multi-layer heatmap overlays mapping one or more APT groups

analyzing-azure-activity-logs-for-threats

Queries Azure Monitor activity logs and sign-in logs via azure-monitor-query

analyzing-bootkit-and-rootkit-samples

Analyzes bootkit and advanced rootkit malware infecting the Master

analyzing-browser-forensics-with-hindsight

Parse Chromium-based browser databases with Hindsight to extract and correlate browsing history, downloads, cookies, cached content, autofill data, saved passwords, and extensions from Chrome, Edge, Brave, Opera, and Vivaldi into a unified timeline (XLSX, JSON, or SQLite output). Use during incident response, insider-threat investigations, or criminal cases when you need to reconstruct a user

analyzing-campaign-attribution-evidence

Systematically evaluate cyber-campaign evidence to attribute an operation to a threat actor, using the Diamond Model and Analysis of Competing Hypotheses (ACH) to weigh infrastructure overlaps, TTP consistency, malware code similarity, and timing/language artifacts into confidence-weighted attribution assessments. Use when an incident investigation needs a defensible attribution confidence level.

analyzing-certificate-transparency-for-phishing

Monitor Certificate Transparency logs using crt.sh and Certstream to

analyzing-cloud-storage-access-patterns

Detect abnormal access in AWS S3, GCS, and Azure Blob Storage by analyzing CloudTrail Data Events, GCS audit logs, and Azure Storage Analytics for after-hours bulk downloads, new-IP access, and API-call spikes (e.g. GetObject) via statistical baselines and time-series anomaly detection. Use when investigating suspected cloud data exfiltration or building related detection rules.

analyzing-cobalt-strike-beacon-configuration

Extract and analyze Cobalt Strike beacon configuration from PE files

analyzing-cobaltstrike-malleable-c2-profiles

Parse and analyze Cobalt Strike Malleable C2 profiles with dissect.cobaltstrike (profiles and beacon-payload configs) and pyMalleableC2 (AST parsing) to extract HTTP/DNS transforms, URIs, headers, sleep/jitter, and injection behavior, then generate network detection signatures. Use when reverse-engineering a captured malleable profile or building detections against Cobalt Strike Beacon traffic.

analyzing-command-and-control-communication

Analyzes malware C2 communication over HTTP, HTTPS, DNS, and custom

analyzing-cyber-kill-chain

Analyzes intrusion activity against the Lockheed Martin Cyber Kill Chain

analyzing-disk-image-with-autopsy

Perform comprehensive forensic analysis of raw (dd), E01, or AFF disk images with Autopsy and The Sleuth Kit, recovering deleted files, examining metadata and embedded artifacts, keyword searching, and building investigation timelines with visual reports. Use for structured analysis of a forensic disk image or when stakeholders need visual reports from evidence.

analyzing-dns-logs-for-exfiltration

Analyzes DNS query logs to detect data exfiltration via DNS tunneling,

相关技能