Communitygithub.com

dotnet-reverse

.NET / C# 二進位逆向。用於分析 .NET 託管程式、C# 編譯產物、Sharp* 工具及混淆程式,優先使用 dnSpyEx 及 de4dot。

dotnet-reverse 是什麼?

此技能專注於 .NET / C# 二進位逆向工程,涵蓋從識別、脫殼、靜態分析、動態調試到修補的完整工作流程。其核心是確保僅對 .NET 託管程式(具有 CLR 標頭的 PE 檔)進行分析,並在必要時切換至其他 native 逆向技能(如 ida-reverse)。對於混淆的程式,強制要求先使用 de4dot 脫殼,再進行後續分析。靜態分析時強調使用 IL 視圖而非反編譯的 C# 程式碼,因為 IL 能保留更完整的資訊,特別是對於狀態機和異步模式。動態調試則用於在運行時解密字串和觀察物件值。此技能支援多種混淆器(ConfuserEx、SmartAssembly、Babel、Eazfuscator、.NET Reactor),並提供對應的脫殼策略。它也整合了 dnSpy MCP,允許 AI 直接操作反編譯工具,並透過參考文件提供深入的技術細節。使用者應在任務完成時提供清晰的下一步選單和報告。

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

在你喜歡的 AI 中提問

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

說明文件

.NET / C# 逆向作業規範

ACTION REQUIRED(讀完立刻執行)

  1. NOW: 用 DIE/file/CLR 頭確認目標是 .NET 託管(否則 SWITCH 到 ida-reverse/ / reverse-engineering/)
  2. NOW: 若疑似混淆 → 先 de4dot 脫殼,產出 *-clean.exe,保留原始樣本
  3. NEXT: dnSpyEx(或 dnSpy MCP / ilspycmd)靜態:C# 瀏覽 + IL 視圖看關鍵判斷
  4. ACT: 需要明文/C2 時動態除錯;需要改邏輯時 IL patch 優先於 C# 重編譯
  5. 階段結束給使用者 3–6 項下一步選單(含匯出報告)

適用範圍

當任務屬於以下場景時優先使用本 skill:

  • 辨識並逆向 .NET / C# 編譯產物(託管 PE / .exe / .dll)
  • 分析紅隊 Sharp* 工具鏈(Rubeus、SharpHound、SharpShell 等)
  • 脫混淆 ConfuserEx / SmartAssembly / Babel / Eazfuscator / .NET Reactor 等殼
  • 逆向 .NET loader / info-stealer / RAT 的解密與 C2 邏輯
  • 對 C# 程式做 patch(改判斷、改常數、keygen)
  • 分析 IL2CPP 之前的 Mono/Unity 託管層(注意:IL2CPP 編譯後是 native,走 reverse-engineering/ + seed-014)

如果目標是純 native 二進位(C/C++/Go/Rust 編譯、無 CLR),請改用 reverse-engineering/、ida-reverse/ 或 radare2/。

核心原則

  • 先辨識再下手:先確認是 .NET 託管程式(PE 頭 CLR + #~ / #Strings 流 + mscoree _CorExeMain),再決定走 dnSpy 而非 IDA
  • IL 優先於 C#:dnSpyEx 的 C# 反編譯器會丟失/扭曲資訊(編譯器生成的狀態機、async/await、yield),關鍵判斷與 patch 必須切到 IL 編輯器,C# 視圖只用於快速瀏覽
  • de4dot 先行:遇到混淆器先 de4dot 脫一輪再做靜態分析,否則字串/控制流全是亂的
  • MCP 聯動:環境裡若註冊了 dnSpy MCP(dnspy_* 工具),優先走 MCP 面做 decompile / IL inspection,避免來回切 GUI
  • 證據化輸出:脫混淆產物、提取的設定/C2/key、patch diff 都要落盤

工具鏈映射

能力首選備註
反編譯 + 除錯 + patchdnSpyEx王牌,唯一帶 IL 編輯器的 GUI;老 dnSpy 已停更,用 Ex 分支
輕量 CLI / headless 反編譯ILSpy (ilspycmd)適合批次、腳本化、Linux/macOS
脫混淆de4dotConfuserEx 全家桶、SmartAssembly 等主流殼的預設解
混淆器辨識Detect It Easy (DIE) / file先判斷殼類型再決定 de4dot 參數
程式化操作 ILdnlib寫 C# 腳本批次改 metadata / 字串解密器
AI 直接操作dnSpy MCPdnspy_decompile / dnspy_inspect_il 等工具面

前置:Windows 主機裝 dnSpyEx + de4dot(choco 或 release);Linux/macOS 用 ilspycmd + dotnet runtime。詳見 references/sharp-tools.md 的安裝矩陣。

六階段工作流

1. Identify(辨識 .NET)

確認目標是託管程式,別把 native PE 當 .NET 分析:

# Windows
file target.exe                       # "PE32 executable ... for MS Windows" 不夠
# 關鍵:看有沒有 CLR
powershell -c "[System.Reflection.AssemblyName]::GetAssemblyName('target.exe')"
# 或
dnSpyEx 直接拖進去 —— 能打開就是託管

# 通用
strings target.exe | grep -iE "mscoree|_CorExeMain|mscorlib|System\\."

.NET 辨識標誌:

  • PE 頭 Data Directory[14] (CLR Runtime Header) 非零
  • mscoree.dll 導入 / _CorExeMain 入口
  • #~、#Strings、#US、#GUID、#Blob metadata 流
  • mscorlib / System.Private.CoreLib 字串

NativeAOT 例外: 編譯成 native,沒有 CLR 頭,但有 System.Private.CoreLib 字串和重構過的類型元資料 —— 這類走 reverse-engineering/(IDA/r2),本 skill 僅做辨識提示。

2. Detect(檢測混淆器)

# DIE 快速辨識
diec target.exe                        # Detect It Easy CLI
# 或拖進 dnSpyEx,看是否大量亂碼類名 / 控制流變形

常見混淆器 → 脫殼策略(詳見 references/obfuscators.md):

混淆器特徵de4dot 處理
ConfuserEx (1.0.0 / 2.x)<module> anti-tamper、控制流變形、字串加密de4dot target.exe 通常自動辨識
SmartAssemblycircular/string encoding、資源壓縮de4dot target.exe
Babel.NET方法體加密、控制流de4dot target.exe
Eazfuscator.NET字串/資源加密de4dot,部分版本需手動
.NET Reactoranti-tamper + necrobitde4dot,新版可能失敗需手動

3. Deobfuscate(脫混淆)

# de4dot 預設自動辨識大多數殼
de4dot target.exe -o target-clean.exe

# 指定類型(自動辨識失敗時)
de4dot --type cfze target.exe          # ConfuserEx
de4dot --type sa target.exe            # SmartAssembly

# 多層混淆 / de4dot 報 unknown
de4dot --detect target.exe             # 看它辨識成什麼
# 可能要先 patch anti-tamper 再 de4dot(見 references/obfuscators.md)

產出:target-clean.exe,後續分析用它。保留原始樣本做對照。

4. Static Analyze(靜態分析)

dnSpyEx 載入脫殼後樣本:

  • C# 視圖:快速瀏覽類結構、方法簽章、字串(用於定位)
  • IL 視圖:關鍵判斷、加密邏輯、狀態機必須看 IL(右鍵 → Edit IL 或 IL 視圖)
  • 找入口:Main / Startup / 模組初始化器 (Module .cctor)
  • 找關鍵邏輯:搜 flag、password、verify、check、encrypt、http、Config
定位字串 → 反向參照 → 找到使用它的方法 → IL 視圖看判斷邏輯

5. Dynamic(動態除錯)

dnSpyEx 除錯器:附加處理序 / 啟動除錯,在關鍵方法下中斷點,觀察執行時期:

  • 解密後的明文字串(很多混淆器的字串在執行時期才解密)
  • C2 位址、設定解密結果
  • 異常驅動的控制流(anti-debug 常用 try/catch 隱藏真實路徑)

.NET 動態除錯比 native 友好得多 —— 能直接看到物件值、字串內容。優先動態而非死磕靜態。

6. Patch(按需修改)

dnSpyEx → 右鍵方法 → Edit Method (C#) 或 Edit IL
  - 改判斷:ldc.i4.0 → ldc.i4.1(false→true)
  - 改常數:直接編輯字串/數字
  - 刪除校驗:nop 掉整段
File → Save Module → 取代原檔案

IL patch 可靠性 > C# patch:C# 重編譯可能失敗(缺參照、語法不對),IL 編輯幾乎不會失真。詳見 references/common-workflow.md。

觸發場景路由

使用者說這些時進入本 skill:

  • ".NET / C# 二進位逆向" / "C# 程式反編譯"
  • "dnSpy 分析" / "dnSpyEx patch"
  • "ConfuserEx / SmartAssembly / Babel 脫混淆 / 脫殼"
  • "Sharp* 工具分析"(Rubeus / SharpHound / SharpShell)
  • ".NET malware / loader / info-stealer 逆向"
  • "C# 程式 patch / keygen / 修改判斷"

何時切出

  • IL2CPP 編譯的 Unity 遊戲 → reverse-engineering/ + seed-014_unity-il2cpp-reverse.md(IL2CPP 是 native,不走 dnSpy)
  • NativeAOT 產物 → reverse-engineering/(同上,native)
  • 純 native PE(無 CLR)→ reverse-engineering/ / ida-reverse/
  • 需要符號/函數批次遷移到別的版本 → binary-diff/
  • 需要畫攻擊路徑 / 呼叫鏈圖 → diagram-generator/

路由上下文

上游入口: skills/SKILL.md(總控)、routing.md 下游出口:

  • IL2CPP / NativeAOT(native)→ reverse-engineering/
  • 深度 native .so/.dll 段分析 → ida-reverse/ / radare2/
  • 需要 AI 直接操作 dnSpy → 註冊並聯動 dnSpy MCP(見 references/sharp-tools.md)

同級關聯模組:

  • reverse-engineering/languages-compiled.md(.NET 簡介指向本模組)
  • apk-reverse/(Xamarin/MAUI Android 逆向可切回本模組看 C# 層)

參考文件

任務完成自檢

  • 是否確認過 CLR / 託管身份(或已 SWITCH 出本 skill)?
  • 混淆樣本是否先 de4dot / 等價脫殼再深分析?
  • 關鍵邏輯是否用 IL 視圖驗證(而非只看 C# 偽程式碼)?
  • 產物(clean 樣本 / 設定 / patch diff)是否落盤且可複現?
  • 是否提供了下一步選單或報告出口?

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

|

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.

go-rust-reverse

Use for reverse engineering stripped Go and Rust binaries including runtime recognition, pclntab/moduel data recovery, panic strings, and idiomatic decompilation recovery.

相關技能