Communitygithub.com

使用 Wireshark 分析網路流量

使用 Wireshark 和 tshark 擷取並分析網路封包資料,適用於資安事件調查、效能診斷與惡意程式分析。

使用 Wireshark 分析網路流量 是什麼?

這項技能指導如何利用 Wireshark 與 tshark 進行網路封包擷取與深入分析,涵蓋從環境配置、顯示過濾、協定特定分析到產出證據的完整工作流程。支援 Wireshark 4.0+ 與 tshark 命令列工具,可在 Linux 系統上執行。其核心優勢在於提供了一個有系統的方法來調查可疑網路活動,例如命令與控制 (C2) 流量、DNS 隧道資料竊取、橫向移動與弱點掃描。透過結合擷取過濾器 (BPF) 與顯示過濾器,使用者能有效縮小分析範圍;技能中亦包含了檔案萃取、統計分析與證據封存等實用步驟,並以一個實際的 DNS 隧道案例演練整個調查流程。該技能強調合法授權的重要性,並提供產出結構化流量分析報告的模板。

相容平台~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) 規則,確認實際通過網路區段的流量
  • 從擷取的網路會話中提取檔案、憑證或入侵指標 (IOC)

請勿在未經授權的網路上擷取流量、在無合法授權下攔截私人通訊,或將其作為生產環境監控中全功能 SIEM 平台的替代方案。

先決條件

  • 已安裝 Wireshark 4.0+ 與 tshark 命令列工具
  • 具有 root/sudo 權限或隸屬於 wireshark 群組,以進行即時封包擷取
  • 能夠存取受監控區段的網路介面(實體網卡、SPAN 埠或網路分流器 (network tap))
  • 足夠的磁碟空間存放封包擷取檔案(在忙碌的千兆網路上,每分鐘約需 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:套用顯示過濾器進行目標分析

# 過濾含有可疑使用者代理程式 (User-Agent) 的 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

# 找出流量最大的主機 (Top Talkers)
tshark -r capture.pcapng -q -z endpoints,ip

# I/O 圖表資料(每秒封包數)
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 Packet Filter 語法,用以限制記錄哪些封包,減少檔案大小並提升效能
顯示過濾器套用於已擷取封包的 Wireshark 專用過濾語法,用於聚焦分析,不修改原始擷取檔案
PCAPNG次世代封包擷取格式,支援在單一檔案中記錄多個介面、名稱解析、註解與中繼資料
TCP 串流重組後的 TCP 區段序列,代表兩個端點間的完整雙向對話
協定解析器Wireshark 模組,用於解碼特定協定的欄位與結構,實現對封包內容的深入檢視
I/O 圖表以時間序列視覺化呈現擷取期間的封包或位元組速率,有助於識別流量尖峰或信標行為

工具與系統

  • Wireshark 4.0+:基於 GUI 的封包分析器,內建超過 3,000 種協定的解析器,支援串流重組與匯出功能
  • tshark:Wireshark 的命令列版本,適用於無頭模式 (headless) 擷取、批次處理與腳本化分析流程
  • 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 擷取
  • 未能建立封包擷取雜湊值與證據鏈文件,以作為數位鑑識證據

輸出格式

## 流量分析報告

**案件 ID**: IR-2024-0847
**擷取檔案**: dns_exfil_investigation.pcapng
**SHA-256**: a3f2b8c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1
**持續時間**: 2024-03-15 14:00:00 至 14:45:00 UTC
**來源介面**: eth2 (VLAN 30 SPAN 埠)

### 調查發現

**1. DNS 隧道已確認**
- 來源: 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. 入侵指標 (IOC)**
- 網域: 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,

相關技能