代码编译安全之classfinal-maven-plugin插件
<groupId>net.roseboy</groupId><artifactId>classfinal-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<password>#</password><!--加密打包之后pom.xml会被删除,不用担心在jar包里找到此密码-->
<packages>com.yulang.proguard.demo.utils,com.yulang.proguard.demo.controller</packages>
<excludes>org.spring</excludes>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>classFinal</goal>
</goals>
</execution>
</executions>
</plugin>
## 实践
加密的效果,将所有的方法内容都清空了

**应用启动**方法:
java -javaagent:proguard-demo-1.0-SNAPSHOT-encrypted.jar -jar proguard-demo-1.0-SNAPSHOT-encrypted.jar
### 问题
启动报错
17:39:11.916 DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7b9a4292
17:39:11.923 DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean ‘org.springframework.context.annotation.internalConfigurationAnnotationProcessor’
17:39:11.949 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)
解决办法,注释掉application的加密和jar包加密就好了
## 测试
测试启动过程中,除了增加点启动日志,并无什么影响,对于业务日志也没有影响

可以看到日志的行号也不会做任何的变更 ,相比较商用Allatori混淆,默认会混淆行号,导致日志排查起来相当困难

## 缺点
通过dump仍然能看到源码,但是相对来说,增加了破解的难度
加密解密开销:每次加载类时都需要进行解密操作,这会增加额外的CPU计算时间。如果加密算法复杂度较高,解密过程可能会成为性能瓶颈。
内存消耗:加密后的类文件可能占用更多存储空间,并且在运行时需要更多的内存来存放解密后的字节码数据。
类加载时间:由于增加了解密环节,类加载的时间会有所增加,特别是在启动阶段或大量类需要加载的时候,可能会感受到明显的延迟。
JIT编译:Java虚拟机(JVM)通常会对热点代码进行即时(Just-In-Time,JIT)编译优化以提高执行效率。加密后,JVM可能无法直接识别并优化这些代码,从而影响执行速度。
目前已经暂停维护了,后期如果存在问题,需要自己修复
## 扩展
多模块项目,只需要在对应模块配置相应的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指定呆板码。呆板绑定可同时支持呆板码+暗码的方式加密。
https://img-blog.csdnimg.cn/direct/a87e4cd46e714e56b502b8484bf96929.png
如果拷贝到其他呆板上运行,则会报错
https://img-blog.csdnimg.cn/direct/839f632e78be44f9b479552d50c4b85d.png
启动加密后的jar
java -javaagent:yourpaoject-encrypted.jar='-pwd 0000000' -jar yourpaoject-encrypted.jar
//参数说明
// -pwd 加密项目的密码
// -pwdname环境变量中密码的名字
插件中配置的密码
<password>#</password><!--加密打包之后pom.xml会被删除,不用担心在jar包里找到此密码-->
## 最后
**自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。**
**深知大多数网络安全工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**
**因此收集整理了一份《2024年网络安全全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。**
!(https://img-blog.csdnimg.cn/img_convert/2308a0f09b97df22aa0785e23de33e6f.png)
!(https://img-blog.csdnimg.cn/img_convert/26394d26414d0999978c162b680c7840.png)
!(https://img-blog.csdnimg.cn/img_convert/779651f169e5806b2dcc322787ba77e2.png)
!(https://img-blog.csdnimg.cn/img_convert/df1d6b9c224708a772b1b59342216367.png)
!(https://img-blog.csdnimg.cn/img_convert/0cf732fc0b476af967494e57ad14d80e.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上网络安全知识点!真正的体系化!**
[**如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!**](https://bbs.csdn.net/topics/618653875)
**由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!**
伴深入学习提升的进阶课程,基本涵盖了95%以上网络安全知识点!真正的体系化!**
[**如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!**](https://bbs.csdn.net/topics/618653875)
**由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!**
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]