Communitygithub.com

分析惡意軟體網路流量

分析沙箱執行期間惡意軟體所產生的網路流量,以識別 C2 通訊協定、偵測 Beacon 模式,並產生網路偵測特徵。

分析惡意軟體網路流量 是什麼?

此技能專注於分析沙箱環境執行惡意軟體後所擷取的 PCAP 檔案中的網路流量。它能引導使用者逐步檢視 DNS 活動(包括 DGA 與 DNS 隧道偵測)、分析 HTTP/HTTPS 的 C2 通訊(含 TLS 指紋辨識與憑證分析)、以及透過時間間隔分析來偵測 Beacon 模式。此技能也涵蓋如何根據觀察到的流量模式建立 Suricata/Snort 偵測特徵規則,以及從流量中還原檔案與工件。支援的平台包括 Wireshark、tshark、Zeek、Suricata、NetworkMiner 及 Python 的 Scapy/dpkt 程式庫。透過結構化的工作流程,它能幫助分析師快速從原始封包資料中提煉出可執行的威脅情資與偵測規則。

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

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

分析惡意軟體網路流量 是做什麼的?

使用時機

  • 沙箱執行已擷取 PCAP 檔案,需要對網路行為進行詳細分析時
  • 識別 C2 協定結構以撰寫網路偵測特徵
  • 判斷惡意軟體 exfiltrate 哪些資料以及連線至哪些外部基礎設施
  • 分析 DNS 隧道、網域生成演算法 (DGA) 或 fast-flux 行為
  • 根據觀察到的惡意軟體網路模式建立 Suricata/Snort 特徵

請勿使用於惡意軟體的基於主機的分析;請改用 Cuckoo 沙箱報告或 Volatility 記憶體分析來處理程序層級的活動。

先決條件

  • 安裝 Wireshark 4.x,用於互動式 PCAP 分析
  • tshark (Wireshark CLI),用於指令稿式封包提取
  • 安裝 Zeek,用於從 PCAP 自動產生中繼資料
  • 安裝 Suricata 並搭配 ET Open/ET Pro 規則集,用於特徵比對
  • NetworkMiner,用於從 PCAP 提取檔案與偵測憑證
  • Python 3.8+,並安裝 scapy 與 dpkt 程式庫,用於程式化封包分析

工作流程

步驟 1:初始 PCAP 概覽

取得網路流量的高層級理解:

# 擷取統計資料
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

步驟 2:分析 DNS 活動

檢查 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"

步驟 3:分析 HTTP/HTTPS C2 通訊

檢查基於網路的命令與控制流量:

# 提取 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 資料(潛在的 exfiltration)
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/

步驟 4:偵測 Beaconing 模式

識別表示 C2 beaconing 的規律性定期通訊:

# 從 PCAP 偵測 Beacon
from scapy.all import rdpcap, IP, TCP
from collections import defaultdict
import statistics

packets = rdpcap("malware.pcap")

# 依目的地 IP:port 分組連線
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))

# 分析時間間隔以檢測 beaconing
print("Beacon 分析:")
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"      模式: 可能為 BEACONING")

步驟 5:產生網路偵測特徵

根據觀察到的流量模式建立 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 beacon 偵測
alert http $HOME_NET any -> $EXTERNAL_NET any (
    msg:"惡意軟體 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:"惡意軟體 MalwareX C2 DNS 查詢";
    dns.query; content:"update.malicious.com";
    sid:9000002; rev:1;
)

# 針對惡意軟體 TLS 客戶端的 JA3 雜湊比對
alert tls $HOME_NET any -> $EXTERNAL_NET any (
    msg:"惡意軟體 MalwareX JA3 比對";
    ja3.hash; content:"a0e9f5d64349fb13191bc781f81f42e1";
    sid:9000003; rev:1;
)
EOF

步驟 6:從流量中提取檔案與工件

還原傳輸的檔案與內嵌資料:

# 使用 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/JA3STLS 指紋辨識方法,從 ClientHello/ServerHello 參數建立雜湊,以唯一識別惡意軟體的 TLS 實作
DGA (網域生成演算法)一種演算法,會產生偽隨機的網域名稱,惡意軟體用於查詢 C2 伺服器位置,藉此規避靜態網域封鎖清單
DNS 隧道將資料編碼在 DNS 查詢與回應中,以建立 C2 通道或透過 DNS 基礎設施竊取資料
Fast FluxDNS 技術,快速輪換某個網域的 IP 位址,以避免被關閉並將 C2 分散到多個受感染的主機
SNI (伺服器名稱指示)TLS 擴充功能,會揭露客戶端正在連線的主機名稱;即使在加密的 HTTPS 連線中也可見
網路特徵Suricata/Snort 規則,比對網路流量中的特定模式(標頭、酬載、時間),以偵測惡意通訊

工具與系統

  • Wireshark:開放原始碼封包分析器,用於在協定層級對網路流量進行深入的互動式檢查
  • Zeek:網路分析框架,可從即時或擷取的流量中產生結構化的中繼資料日誌 (conn, dns, http, ssl)
  • Suricata:高效能網路 IDS/IPS,提供基於特徵的偵測,並可搭配 Lua 指令碼進行自訂偵測邏輯
  • NetworkMiner:網路取證分析工具,用於從 PCAP 檔案中提取檔案、圖片與憑證
  • Scapy:Python 封包操作程式庫,用於程式化封包分析、beacon 偵測與協定解碼

常見情境

情境:解碼自訂二進制 C2 協定

背景:惡意軟體使用自訂的二進制協定,透過 TCP 連接埠 8443 與其 C2 伺服器通訊。標準的 HTTP 分析無法得到任何結果。需要從 PCAP 中逆向工程出協定結構。

方法:

  1. 過濾 PCAP 中 TCP 連接埠 8443 的對話,並追蹤 TCP 串流
  2. 識別訊息框架(長度前綴、分隔符號、固定大小的標頭)
  3. 比較多個訊息以識別靜態標頭欄位與可變資料欄位
  4. 與逆向工程結果交叉比對(若有分析過二進制檔案,則使用 Ghidra)
  5. 為該自訂協定撰寫 Wireshark dissector 或 Scapy 解析器
  6. 建立 Suricata 規則,比對靜態標頭位元組以進行網路偵測
  7. 記錄完整的協定規格,以供威脅情資分享

常見陷阱:

  • 僅分析前幾個封包;某些 C2 協定在初始握手後會改變行為
  • 當沙箱具備 MITM 能力時,未解密 TLS 流量
  • 將合法的 CDN 或雲端流量誤認為 C2(請驗證目的地 IP)
  • 遺漏使用 DNS 或 ICMP 而非 TCP/UDP 的 C2 流量

輸出格式

惡意軟體網路流量分析
===================================
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
Beacon 間隔:      60.2s ± 6.8s (抖動 11.3%)
工作階段總數:     237
傳送資料量:       147 MB
接收資料量:       2.3 MB
憑證:             CN=update.malicious[.]com (自簽章,已過期)

酬載下載
從 compromised-site[.]com 下載 GET /payload.dll
  大小: 98,304 位元組
  SHA-256: abc123def456...
  Content-Type: application/octet-stream

資料外洩 (Exfiltration)
方法:             HTTPS POST 至 /gate.php
Content-Type:     application/octet-stream
平均大小:         每次請求 15,432 位元組
總量:             4 小時內共 147 MB

SURICATA 告警
[1:2028401] ET MALWARE 通用 C2 Beacon 模式
[1:2028500] ET POLICY 自簽章憑證

已產生的特徵
SID 9000001: MalwareX HTTP beacon 模式
SID 9000002: MalwareX DNS C2 網域
SID 9000003: MalwareX JA3 TLS 指紋

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,

相關技能