Re dotnet

From dslsdzc/rev-skills · View interactive version

Re dotnet is an AI agent skill from the GitHub repository dslsdzc/rev-skills. .NET CIL 逆向:dnSpy/ILSpy 反编译、de4dot 去混淆、ConfuserEx。触发词:.NET、dnSpy、ILSpy、de4dot、CIL、ConfuserEx

How to use this skill

Skill file

.NET CIL 逆向(dnSpy / ILSpy / de4dot)

何时使用 / 何时不用

工具准备

参考 [[re-analyze/platform-tips]]——反编译/去混淆为静态步骤,免沙箱;动态验证按最高原则进沙箱。

dotnet SDK(跑 .NET 工具的前提)

ILSpy(跨平台,GUI + CLI)

dnSpy(Windows 专用,GitHub release)

de4dot(GitHub release,去混淆)

单文件 bundle 解包(sfextract / ILSpy 内置,可选但常用)

操作步骤

按顺序执行,每步记录证据(路径 + sha256,见 [[re-triage]])。

  1. 识别 .NET 程序集:

```sh

file sample.exe # 含 "Mono/.Net assembly" 即 .NET

strings sample.exe | grep -i mscoree # mscoree.dll 导入是经典标识

```

CLI header 确认(PE 数据目录第 15 项 = COM Descriptor):

```python

import pefile

pe = pefile.PE('sample.exe')

dd = pe.OPTIONAL_HEADER.DATA_DIRECTORY[14] # COM Descriptor (CLI header)

print(hex(dd.VirtualAddress), hex(dd.Size)) # 非 0 → 托管程序集

```

注意混合模式程序集(native + 托管都看得到)与自包含单文件(见坑 4)。

CLI header 结构速查(实测 .NET 10 产物):cb=0x48(72)、MajorRuntimeVersion=2、MinorRuntimeVersion=5、MetaData RVA、EntryPointToken(4 字节 union,ECMA-335 II.25.3.3:未置 COMIMAGE_FLAGS_NATIVE_ENTRYPOINT 时为 metadata token(MethodDef/File),置位时才是 native code RVA;0=无入口,即 DLL)、CorFlags(1=ILONLY、2=32BITREQUIRED、0x8=强名签名(COMIMAGE_FLAGS_STRONGNAMESIGNED)、0x20000=32BITPREFERRED)。

元数据根(MetaData RVA 处):签名 BSJB(0x424A5342) + 版本 1.1 + 保留 + 版本串长 + 版本串("v4.0.30319" 是 Roslyn/MetadataRootBuilder 的典型默认值,不是格式不变量——ECMA-335 允许 vendor 自定义串,以实际字节为准)+ flags(2) + 流数(2) + 流头(offset + size + 名字,4 字节对齐)。

流名即内容形态:#~(压缩表,Roslyn 默认)/#-(未压缩表)、#Strings(元数据字符串池)、#US(用户字符串:代码里的 C# 字面量)、#GUID、#Blob(签名/常量 blob)——字符串加密样本的明文不在 #US 就是运行时拼的;#~ 的表内容即 dnSpy/ILSpy 的类型/方法树。

  1. dnSpy/ILSpy 反编译浏览:
  1. 字符串/API 定位关键逻辑:

```sh

strings sample.exe | grep -iE 'http|https|api|key|secret|register'

strings -e l sample.exe | grep -iE 'http|key|secret' # UTF-16LE:#US 池里 C# 字面量是 UTF-16

grep -rn 'HttpClient\|WebRequest\|Regex\|Convert' decompiled/ # ilspycmd 产物

```

  1. de4dot 去混淆(ConfuserEx / SmartAssembly 等):

```sh

mono de4dot.exe sample.exe # 自动检测混淆器 → 输出 sample-cleaned.exe

mono de4dot.exe -p ce sample.exe # 显式指定 ConfuserEx (ce) / SmartAssembly (sa)

```

  1. 动态侧(可选;沙箱内执行 [[re-sandbox]]):

```sh

dotnet tool install -g dotnet-dump

dotnet-dump collect -p <pid> # 收集 dump

dotnet-dump analyze <dump> # clrstack / dumpheap -type System.String

```

跨域联合

常见坑与陷阱

(来源:LazyReverse(a0yami),MIT)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.