6767wow/DissorientZ

GitHub: 6767wow/DissorientZ

DissorientZ 是一款开源 .NET 代码混淆器,通过中文标识符重命名、IL 虚拟化、控制流平坦化、字符串加密、资源保护和 ECDSA 离线授权等多层手段提升 .NET 程序集的逆向工程门槛。

Stars: 0 | Forks: 0

# DissorientZ [![CI](https://static.pigsec.cn/wp-content/uploads/repos/cas/ad/ad5834178f7599af9fdda11629d49cae07f2997beec49821b2920eff5bfd50e7.svg)](https://github.com/6767wow/DissorientZ/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![.NET 8](https://img.shields.io/badge/.NET-8.0-512BD4)](https://dotnet.microsoft.com/) **DissorientZ 可将可读的 .NET 元数据转换为中文标识符,并在编译后的 assembly 上叠加多层 IL、runtime、打包和授权保护。** 它是一个跨平台的开源 C# 项目,包含 CLI、可复用的 engine、MSBuild 集成、测试以及确定性的 rename maps。 ``` // Before internal static int CalculateSecret(int left, int right) // Typical decompiler output after protection internal static int 法明雷桃耀远水远(int 参麟狼乾地珠近玉, int 参盈电白近鹰麟低) ``` DissorientZ 会重写编译后的 `.dll` 或受托管的 `.exe`;它不会损坏或 转换原始的源码树。请将生成的 `.dzmap.json` 保密,以便 恢复生产环境的 stack trace。 ## 包含功能 - 针对 namespace、type、method、field、property、 event、parameter 和 generic parameter 的中文 Unicode 重命名 - 保守的 public API、override、serialization、P/Invoke、WPF/BAML 和 reflection 排除规则 - 带有 per-site key 的加密 string literal - integer constant 变异 - 基于调度器的、针对 stack-safe method 的 control-flow flattening - 静态 method 调用代理 - 将选定的 method 虚拟化为加密的 DissorientZ VM bytecode - 直接的 embedded-resource 加密 - 对受托管的依赖 assembly 进行加密的内存加载 - 对受保护的资源和嵌入的依赖进行压缩打包 - 启动时的 anti-debug 检查、构建过期验证和完整性校验 - 采用 ECDSA P-256 签名的离线 license,支持过期验证、功能声明和可选的 机器绑定 - strong-name 重签名或显式移除签名 - 支持 JSON 项目、per-member 特性、CLI 自动化、MSBuild target 和 CI - 确定性构建、rename maps 以及 stack-trace 反混淆 该设计借鉴了以下项目所记录的广泛保护类别: [ConfuserEx 2](https://mkaring.github.io/ConfuserEx/)、 [Obfuscar](https://github.com/obfuscar/obfuscar)、 [.NET Reactor](https://www.eziriz.com/help/introduction/features/index.html)、 和 [ArmDot](https://www.softanics.com/armdot/docs/getting-started)。DissorientZ 是一个独立的实现,与这些项目或 厂商没有任何隶属关系。 ## 安装 要求:在 Linux、macOS 或 Windows 上安装 .NET 8 SDK。 ``` git clone https://github.com/6767wow/DissorientZ.git cd DissorientZ dotnet build DissorientZ.sln -c Release dotnet pack src/DissorientZ.Cli/DissorientZ.Cli.csproj -c Release dotnet tool install --global DissorientZ.Tool \ --add-source artifacts/packages --version 1.0.0 ``` 发布页面还包含工具包、SDK 包、便携版归档以及 SHA-256 校验和。 ## 保护应用程序 首先构建应用程序,然后将 DissorientZ 指向其入口 assembly: ``` dissorientz analyze bin/Release/net8.0/MyApp.dll dissorientz protect bin/Release/net8.0/MyApp.dll \ --preset balanced \ --seed "store-this-seed-in-your-CI-secret" \ --virtualize "MyCompany.SecretAlgorithms::*" dotnet bin/Release/net8.0/protected/MyApp.dll ``` 默认的输出目录是输入路径旁的 `protected/`。 Runtime 配置文件会被自动复制。原始 assembly 永远不会 被覆盖。 要进行强化构建: ``` dissorientz protect MyApp.dll \ --preset armored \ --virtualize "MyCompany.Licensing::*" \ --embed Plugin.dll \ --expires 2027-01-01 \ --deterministic \ --seed "$DISSORIENTZ_BUILD_SEED" ``` armored 预设会启用资源保护、debugger 检查以及 runtime 完整性附带检查。请在受保护的 assembly 旁边附带上 `MyApp.dll.sha256` 发布。 ## 项目文件 创建一个初始项目: ``` dissorientz init dissorientz protect --project dissorientz.json ``` ``` { "input": "bin/Release/net8.0/MyApp.dll", "output": "bin/Release/net8.0/protected/MyApp.dll", "mapFile": "bin/Release/net8.0/protected/MyApp.dzmap.json", "preset": "balanced", "protections": { "renameSymbols": true, "renamePublicSymbols": false, "hideStrings": true, "encodeIntegers": true, "controlFlow": true, "proxyCalls": true, "protectResources": false, "antiDebug": false, "integrityCheck": false, "deterministic": true, "seed": "use-a-private-CI-value", "keep": ["MyCompany.PublicApi::*"], "virtualize": ["MyCompany.SecretAlgorithms::*"], "embedFiles": [] } } ``` 项目文件中的相对路径会从该文件所在的目录开始解析。有关所有选项和兼容性 规则,请参阅 [configuration.md](docs/configuration.md)。 ## 声明式保护 从应用程序中引用 `DissorientZ.Abstractions`: ``` using DissorientZ; [DissorientZObfuscation( Rename = ProtectionSetting.Enabled, HideStrings = ProtectionSetting.Enabled)] internal static class Secrets { [DissorientZObfuscation(Virtualize = ProtectionSetting.Enabled)] internal static int Calculate(int x, int y) => (x * 31) ^ y; [DissorientZObfuscation(Exclude = true)] internal static object UsedByReflection() => new(); } ``` 默认情况下,特性会从受保护的输出中移除。虚拟化是 选择性的:不支持的方法将被保留为有效状态,并会输出每个跳过原因。 ## 授权 生成供应商密钥对: ``` dissorientz license keygen --private vendor.pem --public public.pem ``` 请将 `vendor.pem` 保存在离线环境中。签发并验证签名的 license: ``` dissorientz license issue \ --private vendor.pem \ --output customer.license.json \ --product MyApp \ --customer "Example Co" \ --expires 2027-01-01 \ --machine current \ --feature pro dissorientz license verify \ --license customer.license.json \ --public public.pem \ --product MyApp \ --machine current ``` 应用程序可以直接调用 `DissorientZ.Licensing.LicenseAuthority.Verify`。 发布的应用程序中只应包含 public key。 ## MSBuild 和 CI 打包并引用 `DissorientZ.MSBuild`,确保在构建环境中可用该工具, 然后选择启用: ``` true $(MSBuildProjectDirectory)/dissorientz.json ``` 除非显式启用,否则该 target 将被禁用,并且绝不在设计时 构建期间运行。`.github/workflows/ci.yml` 中包含了一个完整的 GitHub Actions 构建。 ## 恢复 stack trace ``` dissorientz stacktrace MyApp.dll.dzmap.json crash.txt # 或 cat crash.txt | dissorientz stacktrace MyApp.dll.dzmap.json - ``` 请像对待私有 symbol 一样对待这些 maps。不要将它们与受保护的二进制文件一起发布。 ## 预设 | 保护项 | Minimal | Balanced | Armored | |---|:---:|:---:|:---:| | 中文重命名 | ✓ | ✓ | ✓ | | String 加密 | ✓ | ✓ | ✓ | | Integer 变异 | | ✓ | ✓ | | Control-flow flattening | | ✓ | ✓ | | 静态调用代理 | | ✓ | ✓ | | Resource 加密 | | | ✓ | | Anti-debug | | | ✓ | | Runtime 完整性 | | | ✓ | | 选定的 VM method | explicit | explicit | explicit | 除非显式提供 `--rename-public`,否则每个预设都会保留 public symbol。 ## 真实的兼容性边界 DissorientZ 1.0 非常庞大,但它并不声称具备商业产品级别的 功能对等性: - VM 保护支持已记录的、stack-machine 安全的 IL 子集和静态 method。它跳过了 generic、by-ref 签名、exception handler 和 不支持的 opcode。 - 依赖嵌入支持受托管的 assembly。尚未实现针对非受托管 DLL 的内存 加载。 - `.resources`、WPF BAML、satellite resource 和由框架管理的 resource 会被保留,因为透明地替换 `ResourceManager` 是不安全的。 - 完整性模式是 runtime 的 SHA-256 附带检查。它能检测意外或 非复杂的修改,但不能替代代码签名。 - 没有原生的 PE 加载器、anti-dump 驱动程序、无效 metadata 模式或 GUI。 - 严重依赖 reflection、serializer、XAML、COM、remoting 或 插件发现的应用程序需要显式的 `keep` 规则以及针对特定应用程序的冒烟 测试。 混淆提高了逆向工程的成本;它无法在数学上使客户端的 密钥变得不可访问。尽可能将高价值的凭证和 权威的业务规则保留在服务器上。 ## 安全与支持 仅处理您拥有或被授权修改的 assembly。Cecil 和其他 低级 metadata 读取器只能接收受信任的输入。备份签名 密钥和私有构建种子,并在每个 目标平台上验证受保护的产物。 在生产环境部署之前,请阅读[威胁模型](docs/threat-model.md)、[架构](docs/architecture.md)、 和[安全策略](SECURITY.md)。 ## License MIT。参见 [LICENSE](LICENSE)。
标签:macOS, 代码混淆, 数字授权, 编译器, 软件加固