Communitygithub.com

協定逆向工程

用於對自訂二進位協定、Protobuf/gRPC、WebSocket 框架及 PCAP 驅動的協定恢復進行授權逆向工程。

協定逆向工程 是什麼?

這個技能專注於對自訂通訊協定進行授權逆向工程,涵蓋 TCP/UDP 二進位協定、Protobuf/gRPC、FlatBuffers、MessagePack、WebSocket、MQTT 和私有 RPC。它也支援從 PCAP/PCAPNG 檔案還原欄位和狀態機。此技能在 Claude Code、Cursor 等 AI 代理平台上執行,透過結構化工作流程引導使用者完成樣本採集、框架佈局還原、序列化/加密分析和最終產出。主要透過解析工具鏈(如 tshark、Wireshark、blackboxprotobuf)和客製化腳本實現,並明確區分授權逆向與其他領域(如純 JS 加密或韌體分析)。最終結果包括消息類型表、可重現的解碼命令和脫敏證據。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/zhaoxuya520/reverse-skill/tree/main/skills/protocol-reverse

在你喜歡的 AI 中提問

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

說明文件

協定逆向工程 是做什麼的?

立刻執行

  1. NOW: 讀取 ../field-journal/precedent-reverse.md — 確認授權與常規操作邊界
  2. NOW: 確認任務是否為協定/流量/序列化格式逆向(非純 Web 參數簽名 → 轉 js-reverse/)
  3. NOW: 若有目標網路交互 → ../scripts/case-init.ps1 完成 scope;auth 未 granted 禁止對目標 ACT
  4. NEXT: 讀取 ../tool-index.md;缺工具 bootstrap(tshark/wireshark 等可能需手動)
  5. ACT: 進入工作流 Phase 1,產出幀佈局或消息字典草稿

適用場景

  • 自訂 TCP/UDP 二進位協定
  • Protobuf / gRPC / FlatBuffers / MessagePack
  • WebSocket / MQTT / 私有 RPC
  • PCAP / PCAPNG 還原欄位與狀態機
  • 客戶端-服務端校驗、序號、加密幀頭

不走本技能

情況去哪
僅 HTTP 參數簽名 / JS 加密js-reverse/
僅 TLS 憑證問題pentest-tools/ 或瀏覽器代理
韌體內協定棧深挖 + 模擬firmware-pentest/ 後再回本技能

工作流

Phase 1 — 採集與分診

□ 拿到樣本:PCAP / 代理匯出 / 客戶端日誌 / 二進位
□ 標記方向:C→S / S→C;是否有握手、心跳、重連
□ 固定頭?魔數?長度欄位?TLV?定長?
□ 是否壓縮(zlib/gzip/lz4)或加密(AES/ChaCha 幀內)
□ tshark -r cap.pcap -T fields -e frame.number -e ip.src -e tcp.payload

Phase 2 — 幀佈局還原

□ 對齊多個同類訊息,找不變位元組 / 自增序號
□ 長度欄位:大端/小端、含頭/不含頭
□ 校驗:CRC16/32、checksum、HMAC 位置
□ 畫出狀態機:Connect → Auth → Ready → Request/Response → Close
□ 工具:Wireshark 自訂 dissector 草稿 / ImHex / 010 Editor 模板 / Kaitai Struct

Phase 3 — 序列化與加密

□ Protobuf:.proto 恢復(blackboxprotobuf / pbtk / protoc --decode_raw)
□ gRPC:HTTP/2 headers + protobuf body
□ 加密:找金鑰派生(客戶端 so/dll/JS)→ 聯合 ida-reverse / js-reverse / apk-reverse
□ 重放:僅在授權 scope 內;先無害欄位再敏感操作

Phase 4 — 產出

MUST 產出:
- 訊息類型表(name / opcode / fields)
- 至少 1 條可重現的解碼命令或腳本
- Evidence:原始 hex 摘錄 + 解碼結果(脫敏)

工具鏈

工具必需用途自舉
tshark / Wireshark強烈建議PCAP 解析手動 / winget
Python3是解碼腳本系統
blackboxprotobuf可選未知 protobufpip
ImHex / 010可選結構模板手動
IDA / r2 / Ghidra按需客戶端序列化函數見對應技能

參考

  • references/protocol-workflow.md — 幀佈局與 Protobuf 速查
  • 相關:../ida-reverse/ ../js-reverse/ ../firmware-pentest/ ../pentest-tools/

路由上下文

上游: MASTER-ROUTING R21 · routing.md
下游: 需客戶端演算法 → ida-reverse/js-reverse;需利用重放 → pentest-tools/api-security
同級: malware-analysis(C2 協定)、digital-forensics(流量取證)

任務完成自檢

  • 是否還原了訊息佈局或狀態機(而非只貼 hex)?
  • 是否有可重現解碼命令?
  • 是否遵守 scope / 脫敏?
  • 是否回寫 field-journal / 報告 Checklist?

Individual skills in this repo

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

api-security

Use for authorized security assessment of REST, GraphQL, WebSocket, or SOAP APIs, including discovery, authentication, authorization, rate-limit, and CI/CD testing.

apk-reverse

在 CLI 环境下做 Android APK 逆向时使用。适用于 APK 解包、Java 反编译、smali 修改、重打包、Frida 动态 Hook,以及按需切换到 so/native 分析。优先使用本机已安装的 jadx、apktool、frida、adb、ida-reverse、radare2。

attack-chain

Use for authorized multi-stage attack-path planning and orchestration when a task spans reconnaissance, initial access, privilege escalation, lateral movement, or impact assessment. Route single-stage tasks directly to their specialist skill.

binary-diff

|

binary-ninja-reverse

Use for authorized binary analysis in Binary Ninja, including HLIL/MLIL/LLIL inspection, strings/imports/exports, cross-references, types, patch review, Python API automation, and optional Binary Ninja MCP or localhost HTTP integration.

browser-automation

|

browser-extension-reverse

Use for authorized reverse engineering of browser extensions (Chrome/Firefox) including manifest analysis, background workers, and extension-based credential or traffic logic recovery.

case-review

Reviews a reverse-skill case package for scope readiness, Evidence to Finding to Path traceability, work item coverage, timeline references, and optional artifact hash integrity before report handoff.

cloud-k8s

Use for authorized cloud, container, and Kubernetes security assessment including metadata SSRF, IAM misconfig, container escape paths, and cluster RBAC review.

code-audit

Use for authorized source-code security review and SAST workflows including Semgrep, CodeQL patterns, dangerous API hunting, and fix verification.

ctf-sandbox

Thin PRIMARY for CTF / AWD / 靶场 multi-type orchestration. Hands off to the sidecar CTF-Sandbox-Orchestrator. Use when the user says CTF, AWD, 靶场, or 比赛题 and no more specific pwn/APK/IDA route already won.

database-security

Use for authorized database security assessment covering PostgreSQL/MySQL/MSSQL/Mongo/Redis exposure, authz, UDF/command paths, and misconfiguration review.

diagram-generator

generate, refine, validate, and render diagrams from natural language, notes, code snippets, schemas, tables, or existing diagram source. use for flowcharts, swimlanes, sequence diagrams, state diagrams, er diagrams, class diagrams, architecture/c4-style diagrams, dependency graphs, gantt charts, mind maps, user journeys, sankey-style flows, org charts, network graphs, and other visual models. supports mermaid by default, graphviz dot for complex graph layout, plantuml for uml-heavy engineering diagrams, and svg output when direct markup is more reliable.

digital-forensics

Use for authorized digital forensics including memory dumps, disk timelines, PCAP investigation, artifact triage, and IR evidence preservation.

docs-generator

|

dotnet-reverse

.NET / C# 二进制逆向。当目标是 .NET assembly(PE 头含 CLR、.exe/.dll 托管程序)、C# 编译产物(含 NativeAOT)、红队 Sharp* 工具(Rubeus / SharpHound / SharpHound 等)、.NET 混淆程序(ConfuserEx / SmartAssembly / Babel / Eazfuscator)、.NET loader / info-stealer / 套壳 malware 时使用。优先用 dnSpyEx + de4dot,需要 AI 直接操作时联动 dnSpy MCP。不用于纯 native 二进制(走 reverse-engineering / ida-reverse)。

edr-bypass-re

|

email-security

Use for authorized email security review including phishing analysis, header authentication (SPF/DKIM/DMARC), BEC patterns, and mailbox token abuse research.

firmware-pentest

|

ghidra-reverse

Use for free/open reverse engineering with Ghidra (headless or GUI), including decompile, cross-refs, and optional Ghidra MCP workflows when IDA is unavailable.

相關技能