代码编译安全之classfinal-maven-plugin插件

打印 上一主题 下一主题

主题 858|帖子 858|积分 2574

  1.             <groupId>net.roseboy</groupId>
  2.             <artifactId>classfinal-maven-plugin</artifactId>
  3.             <version>1.2.1</version>
  4.             <configuration>
  5.                 <password>#</password><!--加密打包之后pom.xml会被删除,不用担心在jar包里找到此密码-->
复制代码
  1.          <packages>com.yulang.proguard.demo.utils,com.yulang.proguard.demo.controller</packages>
复制代码
  1.                 <excludes>org.spring</excludes>
复制代码
  1.             </configuration>
  2.             <executions>
  3.                 <execution>
  4.                     <phase>package</phase>
  5.                     <goals>
  6.                         <goal>classFinal</goal>
  7.                     </goals>
  8.                 </execution>
  9.             </executions>
  10.         </plugin>
复制代码
  1. ## 实践
  2. 加密的效果,将所有的方法内容都清空了
  3. ![](https://img-blog.csdnimg.cn/direct/3c4560e71a564680ab59dc138cfc2488.png)![](https://img-blog.csdnimg.cn/direct/9bf88a4646bb4257adafaeb826b07363.png)
  4. **应用启动**方法:
复制代码
java -javaagent:proguard-demo-1.0-SNAPSHOT-encrypted.jar -jar proguard-demo-1.0-SNAPSHOT-encrypted.jar
  1. ### 问题
  2. 启动报错
复制代码
17:39:11.916 [main] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7b9a4292
17:39:11.923 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean ‘org.springframework.context.annotation.internalConfigurationAnnotationProcessor’
17:39:11.949 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
at org.springframework.util.Assert.notEmpty(Assert.java:470)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:180)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationEntry(AutoConfigurationImportSelector.java:123)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector                                   A                         u                         t                         o                         C                         o                         n                         f                         i                         g                         u                         r                         a                         t                         i                         o                         n                         G                         r                         o                         u                         p                         .                         p                         r                         o                         c                         e                         s                         s                         (                         A                         u                         t                         o                         C                         o                         n                         f                         i                         g                         u                         r                         a                         t                         i                         o                         n                         I                         m                         p                         o                         r                         t                         S                         e                         l                         e                         c                         t                         o                         r                         .                         j                         a                         v                         a                         :                         434                         )                         a                         t                         o                         r                         g                         .                         s                         p                         r                         i                         n                         g                         f                         r                         a                         m                         e                         w                         o                         r                         k                         .                         c                         o                         n                         t                         e                         x                         t                         .                         a                         n                         n                         o                         t                         a                         t                         i                         o                         n                         .                         C                         o                         n                         f                         i                         g                         u                         r                         a                         t                         i                         o                         n                         C                         l                         a                         s                         s                         P                         a                         r                         s                         e                         r                              AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:434) at org.springframework.context.annotation.ConfigurationClassParser                  AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:434)atorg.springframework.context.annotation.ConfigurationClassParserDeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:879)
at org.springframework.context.annotation.ConfigurationClassParser                                   D                         e                         f                         e                         r                         r                         e                         d                         I                         m                         p                         o                         r                         t                         S                         e                         l                         e                         c                         t                         o                         r                         G                         r                         o                         u                         p                         i                         n                         g                         H                         a                         n                         d                         l                         e                         r                         .                         p                         r                         o                         c                         e                         s                         s                         G                         r                         o                         u                         p                         I                         m                         p                         o                         r                         t                         s                         (                         C                         o                         n                         f                         i                         g                         u                         r                         a                         t                         i                         o                         n                         C                         l                         a                         s                         s                         P                         a                         r                         s                         e                         r                         .                         j                         a                         v                         a                         :                         809                         )                         a                         t                         o                         r                         g                         .                         s                         p                         r                         i                         n                         g                         f                         r                         a                         m                         e                         w                         o                         r                         k                         .                         c                         o                         n                         t                         e                         x                         t                         .                         a                         n                         n                         o                         t                         a                         t                         i                         o                         n                         .                         C                         o                         n                         f                         i                         g                         u                         r                         a                         t                         i                         o                         n                         C                         l                         a                         s                         s                         P                         a                         r                         s                         e                         r                              DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:809) at org.springframework.context.annotation.ConfigurationClassParser                  DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:809)atorg.springframework.context.annotation.ConfigurationClassParserDeferredImportSelectorHandler.process(ConfigurationClassParser.java:780)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:192)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:420)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at com.yulang.proguard.demo.ProguardApp.main(ProguardApp.java:19)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
  1. 解决办法,注释掉application的加密和jar包加密就好了
  2. ## 测试
  3. 测试启动过程中,除了增加点启动日志,并无什么影响,对于业务日志也没有影响
  4. ![](https://img-blog.csdnimg.cn/direct/feab030e911d43e58c96a615e40c4571.png)
  5. 可以看到日志的行号也不会做任何的变更 ,相比较商用Allatori混淆,默认会混淆行号,导致日志排查起来相当困难
  6. ![](https://img-blog.csdnimg.cn/direct/b202579b9d1c478abcf18378d233dc21.png)
  7. ## 缺点
  8. 通过dump仍然能看到源码,但是相对来说,增加了破解的难度
  9. 加密解密开销:每次加载类时都需要进行解密操作,这会增加额外的CPU计算时间。如果加密算法复杂度较高,解密过程可能会成为性能瓶颈。
  10. 内存消耗:加密后的类文件可能占用更多存储空间,并且在运行时需要更多的内存来存放解密后的字节码数据。
  11. 类加载时间:由于增加了解密环节,类加载的时间会有所增加,特别是在启动阶段或大量类需要加载的时候,可能会感受到明显的延迟。
  12. JIT编译:Java虚拟机(JVM)通常会对热点代码进行即时(Just-In-Time,JIT)编译优化以提高执行效率。加密后,JVM可能无法直接识别并优化这些代码,从而影响执行速度。
  13. 目前已经暂停维护了,后期如果存在问题,需要自己修复
  14. ## 扩展
  15. 多模块项目,只需要在对应模块配置相应的jar包即可
复制代码
``` 呆板绑定

获取呆板码jar包:classfinal-fatjar-1.2.1.jar
下载地址:https://repo1.maven.org/maven2/net/roseboy/classfinal-fatjar/1.2.1/classfinal-fatjar-1.2.1.jar
呆板绑定只允许加密的项目在特定的呆板上运行;
在需要绑定的呆板上实行以下命令,生成呆板码
java -jar classfinal-fatjar-1.2.1.jar -C
加密时用-code指定呆板码。呆板绑定可同时支持呆板码+暗码的方式加密。

如果拷贝到其他呆板上运行,则会报错

启动加密后的jar

  1. java -javaagent:yourpaoject-encrypted.jar='-pwd 0000000' -jar yourpaoject-encrypted.jar
  2. //参数说明
  3. // -pwd      加密项目的密码  
  4. // -pwdname  环境变量中密码的名字
  5. 插件中配置的密码
  6. <password>#</password><!--加密打包之后pom.xml会被删除,不用担心在jar包里找到此密码-->
  7. ## 最后
  8. **自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。**
  9. **深知大多数网络安全工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**
  10. **因此收集整理了一份《2024年网络安全全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。**
  11. ![img](https://img-blog.csdnimg.cn/img_convert/2308a0f09b97df22aa0785e23de33e6f.png)
  12. ![img](https://img-blog.csdnimg.cn/img_convert/26394d26414d0999978c162b680c7840.png)
  13. ![img](https://img-blog.csdnimg.cn/img_convert/779651f169e5806b2dcc322787ba77e2.png)
  14. ![img](https://img-blog.csdnimg.cn/img_convert/df1d6b9c224708a772b1b59342216367.png)
  15. ![img](https://img-blog.csdnimg.cn/img_convert/0cf732fc0b476af967494e57ad14d80e.png)
  16. **既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上网络安全知识点!真正的体系化!**
  17. [**如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!**](https://bbs.csdn.net/topics/618653875)
  18. **由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!**
  19. 伴深入学习提升的进阶课程,基本涵盖了95%以上网络安全知识点!真正的体系化!**
  20. [**如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!**](https://bbs.csdn.net/topics/618653875)
  21. **由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!**
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

罪恶克星

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表