.NET / C# assembly reversing
When it applies
The binary is a managed .NET assembly — a thick client, a Sharp* red-team tool, or a captured
loader/stealer — and it is in scope (tradecraft-scope-roe, scope.txt). Pure-native PEs, IL2CPP
Unity builds, and NativeAOT output carry no CLR metadata: those go to reverse-eng-binary-triage.
dnSpyEx (the only GUI with an IL editor and debugger) is Windows-only; on Linux/macOS use
ilspycmd + dotnet de4dot.dll and accept that interactive patching/debugging needs Windows.
Why it works
Managed assemblies keep near-complete metadata — type, method, and field names survive
compilation, so decompilation recovers close-to-source C#. Obfuscators only scramble names,
strings, and control flow, and de4dot automates the unscrambling for the common families. The IL
instruction stream is the ground truth: the C# view loses or distorts compiler-generated code
(async state machines, closures, yield), so decisive reads and every patch happen at IL level.
Method
Obfuscator identification table, de4dot options, anti-tamper bypasses, and IL patch recipes:
see cheatsheet.md next to this file.
- Confirm managed, not native.
strings target.exe | grep -iE "mscoree|_CorExeMain|mscorlib|System\."
and diec target.exe (Detect It Easy reports .NET plus the obfuscator). Hard proof: PE data
directory 14 (CLR header) non-zero, _CorExeMain entry, #~/#Strings metadata streams.
- Detect and strip obfuscation.
de4dot --detect target.exe to identify the family, then
de4dot target.exe -o target-clean.exe. Keep the original untouched — all further analysis
runs on the clean copy.
- Static in dnSpyEx. C# view for fast browsing and string search (
password, verify,
encrypt, http, Config), IL view for anything decisive. Read order: <module> .cctor
(deobfuscator/anti-tamper init runs first) → Main → the method that uses your located string
(find via cross-references).
- Dynamic with the dnSpyEx debugger when strings or config decrypt only at runtime: break on
the decryptor's return and read the plaintext from Locals/Watch. Set exception breakpoints —
obfuscators hide real control flow in
try/catch dispatch, and breaking the thrown exception
type shows the actual path. .NET debugging exposes object values directly; prefer it over
grinding static IL.
- Patch via Edit IL, never Edit Method (C#). Flip
ldc.i4.0→ldc.i4.1, replace a check with
ldc.i4.1; ret, or nop out a validation block, then File → Save Module as a new file. C#
recompile fails constantly on state machines and lambdas; IL edits are instruction-exact.
Gotchas
- IL2CPP / NativeAOT look like .NET but are native —
System.Private.CoreLib strings, no CLR
header. Route to reverse-eng-binary-triage.
- New ConfuserEx anti-tamper / .NET Reactor necrobit defeat de4dot — patch the integrity check
to
ret first, or run the binary and dump the decrypted assembly from memory (MegaDumper /
ExtremeDumper), then clean the dump with de4dot. Themida .NET is a native virtualizing wrapper —
de4dot cannot touch it; dump and go native.
- Exception-driven control flow can't be
nop'd — trace the catch dispatch to find the real logic.
- Keep artifacts on disk: original,
*-clean.exe, patched copy, and the extracted
config/C2/keys — the findings folder needs reproducible evidence.
- Run unknown samples in an isolated VM — executing a managed binary runs its
.cctor.
Verify success
You can name the obfuscator (or confirm none), show decrypted strings/config/C2 or a patched
binary whose behavior provably changed, and the original sample is preserved for the diff.
References
dnSpyEx, de4dot, and dnlib documentation; Washi's "Misconceptions about .NET reversing" (IL over
C# decompiler output).
Portions adapted from reverse-skill by zhaoxuya520, MIT License.
1---2name: reverse-eng-dotnet3description: >4 Reverse a .NET / C# assembly — decompile, deobfuscate, debug, and IL-patch managed binaries.5 Load when the target is a managed PE (.exe/.dll with a CLR header), a Sharp* red-team tool6 (Rubeus, SharpHound, Seatbelt), a ConfuserEx/SmartAssembly/Babel/.NET-Reactor-obfuscated7 sample, or a .NET loader/stealer. Signals: "mscoree" / "_CorExeMain" / "mscorlib" strings,8 garbled Unicode class names in a decompiler, "deobfuscate this .NET", "patch/keygen a C# binary".9domain: reverse-engineering10type: technique11stability: learning12modes: [pentest, bugbounty]13severity: medium14mitre: [T1027]15tools: [dnspyex, de4dot, ilspycmd, die, dnlib]16schema_version: 117metadata:18 source: https://skillmd.com/skills/noorqureshi/reverse-eng-dotnet19---2021# .NET / C# assembly reversing2223## When it applies24The binary is a managed .NET assembly — a thick client, a Sharp* red-team tool, or a captured25loader/stealer — and it is in scope (`tradecraft-scope-roe`, `scope.txt`). Pure-native PEs, IL2CPP26Unity builds, and NativeAOT output carry no CLR metadata: those go to `reverse-eng-binary-triage`.27dnSpyEx (the only GUI with an IL editor and debugger) is Windows-only; on Linux/macOS use28`ilspycmd` + `dotnet de4dot.dll` and accept that interactive patching/debugging needs Windows.2930## Why it works31Managed assemblies keep near-complete metadata — type, method, and field names survive32compilation, so decompilation recovers close-to-source C#. Obfuscators only scramble names,33strings, and control flow, and de4dot automates the unscrambling for the common families. The IL34instruction stream is the ground truth: the C# view loses or distorts compiler-generated code35(async state machines, closures, `yield`), so decisive reads and every patch happen at IL level.3637## Method38> Obfuscator identification table, de4dot options, anti-tamper bypasses, and IL patch recipes:39> see [`cheatsheet.md`](cheatsheet.md) next to this file.40411. **Confirm managed, not native.** `strings target.exe | grep -iE "mscoree|_CorExeMain|mscorlib|System\."`42 and `diec target.exe` (Detect It Easy reports .NET plus the obfuscator). Hard proof: PE data43 directory 14 (CLR header) non-zero, `_CorExeMain` entry, `#~`/`#Strings` metadata streams.442. **Detect and strip obfuscation.** `de4dot --detect target.exe` to identify the family, then45 `de4dot target.exe -o target-clean.exe`. Keep the original untouched — all further analysis46 runs on the clean copy.473. **Static in dnSpyEx.** C# view for fast browsing and string search (`password`, `verify`,48 `encrypt`, `http`, `Config`), IL view for anything decisive. Read order: `<module>` `.cctor`49 (deobfuscator/anti-tamper init runs first) → `Main` → the method that uses your located string50 (find via cross-references).514. **Dynamic with the dnSpyEx debugger** when strings or config decrypt only at runtime: break on52 the decryptor's return and read the plaintext from Locals/Watch. Set exception breakpoints —53 obfuscators hide real control flow in `try`/`catch` dispatch, and breaking the thrown exception54 type shows the actual path. .NET debugging exposes object values directly; prefer it over55 grinding static IL.565. **Patch via Edit IL, never Edit Method (C#).** Flip `ldc.i4.0`→`ldc.i4.1`, replace a check with57 `ldc.i4.1; ret`, or `nop` out a validation block, then File → Save Module as a new file. C#58 recompile fails constantly on state machines and lambdas; IL edits are instruction-exact.5960## Gotchas61- **IL2CPP / NativeAOT look like .NET but are native** — `System.Private.CoreLib` strings, no CLR62 header. Route to `reverse-eng-binary-triage`.63- **New ConfuserEx anti-tamper / .NET Reactor necrobit defeat de4dot** — patch the integrity check64 to `ret` first, or run the binary and dump the decrypted assembly from memory (MegaDumper /65 ExtremeDumper), then clean the dump with de4dot. Themida .NET is a native virtualizing wrapper —66 de4dot cannot touch it; dump and go native.67- **Exception-driven control flow** can't be `nop`'d — trace the `catch` dispatch to find the real logic.68- **Keep artifacts on disk**: original, `*-clean.exe`, patched copy, and the extracted69 config/C2/keys — the findings folder needs reproducible evidence.70- **Run unknown samples in an isolated VM** — executing a managed binary runs its `.cctor`.7172## Verify success73You can name the obfuscator (or confirm none), show decrypted strings/config/C2 or a patched74binary whose behavior provably changed, and the original sample is preserved for the diff.7576## References77dnSpyEx, de4dot, and dnlib documentation; Washi's "Misconceptions about .NET reversing" (IL over78C# decompiler output).7980---81_Portions adapted from [reverse-skill](https://github.com/zhaoxuya520/reverse-skill) by zhaoxuya520, MIT License._