CSDN博客

img yuanqingfei

Java程序的加密和反加密

发表于2004/7/10 17:17:00  800人阅读

分类: 〖Java〗

发信人: ttlink (Anakin Skywalker), 信区: Java                                                                          
标  题: Java程序的加密和反加密                                                                                         
发信站: 日月光华 (2003年03月21日00:11:28 星期五), 站内信件                                                             

http://www.csdn.net/develop/article/17/17525.shtm                                                                      

neek2000@SMTH                                                                                                          
neek@sina.com                                                                                                          
========================================================================                                               
=                                                                                                                      

写在前面的话:写这篇文档的目的是让大家能更深入的了解Java技术,而不是教你                                               
怎么去破解Java程序;武器没有罪过,要看是好人用它还是坏人用它。                                                         

    首先我们来看看Java程序的反加密,也就是通常所说的Crack过程,只有明白                                                
了这个过程,我们才能有效的对我们的程序进行加密。                                                                       

    通常我们得到的Java程序的Crack包有两种,一种属于KeyGen(注册码生成器                                                
)、一种属于替换修改;                                                                                                 

    我们先看第一种,当我们找到一个应用程序的KeyGen的时候我们总是很佩服那                                               
个做出KeyGen的人,觉得他很厉害,但是你仔细分析一下,为什么他能做出                                                     
KeyGen呢?只有                                                                                                         
他对这个Java程序的加密算法了解的非常清楚;这种人有哪些呢?一个是那个公司                                               
里面的人,那不可能,除非内讧,还又呢,就是猜想,反推,这个可能吗?呵呵,                                               
更不可能,那这个算法从哪里来呢?呵呵,往往泄漏秘密的就是秘密本身……回过                                               
头来想想,Java应用程序怎么知道你输入的注册码是否正确呢?呵呵,那你就该从                                               
应用程序入手……                                                                                                       
得到的它的加密算法,自然KeyGen就不在话下了……(但是这也有列外,如果它是                                               
用的公钥秘钥对加密的,就没有办法喽,只能用第二种方法。)                                                               
                                                                                                                       
    这种办法只适合对付只要一个注册号,别的什么都不要的情况,经典代表                                                   
Borland JBuilder & Optimizeit Suite                                                                                    
                                                                                                                       
    再看第二种,为什么要用替换修改?我们是修改了那部分呢?不用想,肯定是                                               
License验证的部分,为什么我们不像上面的方法那样找加密算法呢?原因有两种                                                
:(1)使用上面的办法搞不定;(2)Java程序不仅要Key,还有其他的License配                                               
置;遇到这种情况,我们只要找到用于License验证的类,进行修改替换就行了。                                                
                                                                                                                       
                                                                                                                       
    这种办法使用于任何情况,经典代表BEA WebLogic                                                                       
                                                                                                                       
    经过上面的分析,我们的问题就集中了,关键就是怎么找到用于License验证                                                
的部分或加密算法的部分,我们需要3个工具:一个是Sun公司提供的标准JVM:)                                                
,一个是你                                                                                                             
的耐心和细心:),一个是Jad(经典Java反编译工具)。                                                                    
                                                                                                                       
    第一步是定位,这也是最关键的一步,我们这里以Together For JBuilder                                                  
Edition为例,启动Together,先看看长什么样子?喔,上来就问我要License;                                                 
Ok,                                                                                                                   
每关系,退出;找到Together的启动Bat文件,找到它的启动命令:java .....,                                                
OK,在Java启动的时候给一个参数:“ -Xrunhprof:cpu=times”,保存,在启动                                                
,还是要                                                                                                               
License,退出,这个时候,我们可以发现,在这个目录下多了一个“java.                                                     
hprof.txt”文件,打开一看,就是我要的JVM的Dump文件,好多内容啊,没关系,                                               
慢慢看来。                                                                                                             
                                                                                                                       
    我们可以看见这个文件里面有好多熟悉的东西啊:java.*/com.sun.*/javax.                                                
*等等,但这个不是我们关心的,我们要的是com.togethersoft.*或者是一些没有                                                
包名的zd.d等等。(这里插一句,几乎所有的Java应用程序都会混淆的,其实混淆                                               
的原理也很简单,我们后面再说。)先找找有没有License有关的,Serach一下,                                                
嘿嘿,果然,474行:com.togethersoft.together.impl.ide.license.                                                         
LicenseSetup.execute([DashoPro-V2-050200]:Unknown line),Ok上那堆                                                      
classpath中的Jar包里面找一下吧(推荐用WinRAR),找到了之后用Jad反编译,                                                
一看,这个没有混淆,但是用了一个zae的类,这个看名字就知道混淆过了,先不                                                
理它,再看看下面一句IdeLicenseAccess.setLicense(zae1),Ok接着找到                                                      
IdeLicenseAccess,哈哈,就这点名堂,所有的License验证都是走的这个类,面                                                
向对象的思想不错,呵呵:)                                                                                             
                                                                                                                       
    定位定完了,接下来的事情就是按猜想的方法修改这两个类,屏蔽掉                                                       
LicenseSetup里面execute方法的实际内容,修改IdeLicenseAccess,让多有的验                                                
证都返回true,然后编译,替换;不要高兴太早,这还没有完呢,要有责任心!!                                               
启动Together,果然,这下不要License了,有启动画面,进去了,但是一片灰色                                                
,怎么回事,一看控制台,一堆错,没关系,就怕不出错,查找根源,还有一个                                                 
IdeLicenseUtil类出了问题,再反编译,修改,替换;这下搞定了。再启动,测试                                               
一下,OK。                                                                                                             
                                                                                                                       
    就这样,一个Java应用程序搞定了。看看其实也很简单。                                                                 
                                                                                                                       
    再来说说混淆,大家可能都知道没有经过混淆的Java的Class反编译回来连方                                                
法和变量的名字都不会变,这是什么原因呢?这就要追述到Class文件的结构了,                                                
简单来说,Class文件种包含又一个常数池(constant pool)这个里面就存放了变                                               
量和方法的名称等一下和Class相关的东西,我们通常所说的混淆就是用一种工具                                                
把这个常数池里面的东东弄的胡涂一点,这样就能骗过反编译器和你,呵呵:)这                                               
就是为什么有时候反编译回来的东西编译不过去的原因。                                                                     
                                                                                                                       
    再回过头来说说Java程序的加密;从上面的两种方法来看,Java程序似乎是没                                               
有什么完美的办法进行加密的,其实不然,我们必须遵循一些原则,才能有效的保                                               
护你的产品。                                                                                                           

0 0

相关博文

我的热门文章

img
取 消
img