3

探究——C# .net 代码混淆/加壳 - MaQaQ

 7 months ago
source link: https://www.cnblogs.com/magicMaQaQ/p/17702951.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

探究——C# .net 代码混淆/加壳

  先查询一下常见的加壳工具:

  • DotFuscator,官方自带,据说免费版混淆程度不高
  • Virbox Protector,很好很优秀,但是收费
  • NET Reactor,可能会被识别为病毒
  • Obfuscar,开源,可以用dotnet tool或项目构建的方式进行使用

  那就先用Obfuscar试试水。

方式一:nuget安装(推荐,这种方式可以针对性下载各.net版本对应工具包)

  1、在项目中使用nuget安装obfuscar

2447777-20231016113738187-872151799.png

   2、在项目根目录下找到packages\Obfuscar.2.2.38\tools,将Obfuscar.Console.exe拷到要加密文件的文件夹中

2447777-20231016113944302-843489834.png

   3、新建一个Obfuscar.xml 文件放到相同目录下,内容如下:

ContractedBlock.gifExpandedBlockStart.gif

View Code

  下图中,Logic.dll是要加密的类库:

2447777-20231016114313907-1018535474.png

   4、用命令提示符cmd进入到目录下(可以在cmd里用cd指令跳转,也可以直接打开目标文件夹,然后在上方的文件路径那里直接替换成cmd后enter)

2447777-20231017114515321-1358746736.png

   5、执行>Obfuscar.Console.exe Obfuscar.xml

2447777-20231016114736300-1727163028.png

   6、在生成的Obfuscar文件夹中可以找到被加壳后的同名Logic.dll

2447777-20231016114854556-1486211117.png

  上述得到的Logic.dll即可被其他项目直接引用,加密后类似:

2447777-20231017115315740-1383473254.png

  方式二:dotnet tool(.net 6)

  1、新建一个Obfuscar.xml 文件放到类库所在目录,内容如下:

ContractedBlock.gifExpandedBlockStart.gif

View Code

  其中,Module对应填入想要加壳的类库,可以添加多行,AssemblySearchPath根据自己.net的路径进行配置。

  2、在cmd中进入到上述目录中,执行命令:dotnet tool install --global Obfuscar.GlobalTool

  3、在cmd中执行命令:obfuscar.console Obfuscar.xml

  4、在上述目录中找到自动生成的Obfuscar文件夹,加壳后的类库就存放在里面,拷贝出来即可使用。

PS:.net6的带WebAPI的exe好像加壳失败,待测试。

方式三:项目构建

  1、在csproj 项目文件中添加安装Obfuscar的代码:

ContractedBlock.gifExpandedBlockStart.gif

View Code

  2、在项目中添加一个Obfuscar.xml 文件,内容跟方式一的类似,再在csproj 项目文件中设置更新

ContractedBlock.gifExpandedBlockStart.gif

View Code

  3、在csproj 项目文件中设置自动构建

ContractedBlock.gifExpandedBlockStart.gif

View Code

 PS:这种方式还没测试过,待测试


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK