Finalshell 3.9.2.2 逆向破解

admin 2021年10月9日11:29:59Finalshell 3.9.2.2 逆向破解已关闭评论958 views字数 4042阅读13分28秒阅读模式

前言

去年破解过3.0.10版本,相较现在的版本,混淆加密仍然是Allatori旧版,不知作者是因为调试的需要还是其他的原因仍然保留着源文件名称

但这一个版本的验证系统大改,主要的改动内容是功能性改动(比如离线激活),安全性改动很少,所以花了一点时间来分析它。

反混淆

由于使用的是 Allatori 混淆器,所以直接使用公开反混淆器threadtear对其进行反混淆。

threadtear settings

在最终反混淆的结果发现,只有少数字符串被加密,大部分字符串都是明文。

找到关键类

通过对字符串的搜索,无法找到类似于 “激活” 这样的字眼,目前有两种猜测,一是它的本地化所致,二是有其他对字符串的保护。

但通过命令行运行程序之后发现,它会打印类似于状态指示的一些信息。
命令行

在点击登录或者离线激活时,也会打印这样的状态指示信息。
通过对状态指示信息字符串的搜索,就可以成功找到这样的关键类了。
ControlClient.class

可以发现,这里作者使用了自己的加解密函数对字符串进行加密,所以我们在前面无法搜到相关的重要字符串。

解密字符串

通过对字符串的追踪,最终可以发现是一个基于DES的加解密。
最终对解密方法的实现是这样的:

 复制代码 隐藏代码
    /**      * a method to decrypt final shell encrypted string.      */     private static String decrypt(String str) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, InvalidKeySpecException, BadPaddingException, InvalidKeyException {         if (str == null || str.isEmpty()) {             return "";         }         byte[] rawData = Base64.getDecoder().decode(str);         byte[] arr = new byte[8];         System.arraycopy(rawData, 0, arr, 0, arr.length);         byte[] data = new byte[rawData.length - arr.length];         System.arraycopy(rawData, arr.length, data, 0, data.length);         return new String(decryptDES(data, generateRandomKey(arr)), StandardCharsets.UTF_8);     }     private static byte[] decryptDES(byte[] data, byte[] key) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {         DESKeySpec desKeySpec       = new DESKeySpec(key);         SecretKey  secretKey = SecretKeyFactory.getInstance("DES").generateSecret(desKeySpec);         Cipher cipher = Cipher.getInstance("DES");         cipher.init(2, secretKey, new SecureRandom());         return cipher.doFinal(data);     }     private static byte[] generateRandomKey(byte[] head) {         long ks = 3680984568597093857L / (long)(new Random((long)head[5])).nextInt(127);         Random random = new Random(ks);         int t = head[0];         for(int i = 0; i < t; ++i) {             random.nextLong();         }         long n = random.nextLong();         Random r2 = new Random(n);         long[]                ld  = new long[]{(long)head[4], r2.nextLong(), (long)head[7], (long)head[3], r2.nextLong(), (long)head[1], random.nextLong(), (long)head[2]};         ByteArrayOutputStream bos   = new ByteArrayOutputStream();         DataOutputStream      dos   = new DataOutputStream(bos);         long[]                var15 = ld;         int var14 = ld.length;         for(int var13 = 0; var13 < var14; ++var13) {             long l = var15[var13];             try {                 dos.writeLong(l);             } catch (IOException var18) {                 var18.printStackTrace();             }         }         try {             dos.close();         } catch (IOException var17) {             var17.printStackTrace();         }         byte[] keyData = bos.toByteArray();         keyData = hashMD5(keyData);         return keyData;     }     public static byte[] hashMD5(byte[] data) {         byte[] res=null;         try {             MessageDigest m;             m = MessageDigest.getInstance("MD5");             m.update(data, 0, data.length);             res=m.digest();         } catch (NoSuchAlgorithmException e) {             e.printStackTrace();         }         return res;     }

关键接口

通过对字符串的解密,可以初步对流程进行分析。
ControlClient.class (deobfuscated)

可以发现,最终的几个关键的变量都被传入了一个接口实现之中,我们进入这个接口。

SetProI.class

结合前面ControlClient.class的分析,接口的唯一方法的参数基本可以确定。
由此,我们只需要自行构造接口实现的参数之后调用实现即可。

在线激活与离线激活

ControlClient.class 中,可以发现有两个函数十分相似,但第二个函数缺少了几个参数构造行为(HTTP参数),所以基本可以断定是离线激活的实现。

但最终其实都调用了那一个接口的实现,所以我们只需要先分析第一个在线激活,然后将同样的代码复制到第二个函数中即可。

Patch!

bytecodes

直接对实现进行调用,破解完成。
succ

离线激活算法

 复制代码 隐藏代码
    public static void generateKey(){         String proKey = transform(61305 + hardwareId + 8552);         String pfKey = transform(2356 + hardwareId + 13593);     }     public static String transform(String str) throws NoSuchAlgorithmException {         return Main.hashMD5(str).substring(8, 24);     }     public static String hashMD5(String str) throws NoSuchAlgorithmException {         MessageDigest digest = MessageDigest.getInstance("MD5");         byte[] hashed = digest.digest(str.getBytes());         StringBuilder sb = new StringBuilder();         for (byte b : hashed) {             int len = b & 0xFF;             if (len < 16) {                 sb.append("0");             }             sb.append(Integer.toHexString(len));         }         return sb.toString();     }

引用

反混淆器 threadtear
反汇编器 recaf
部分字符串解密算法

一起来找不同,你最想要的。

我的原文章

相关推荐: 某APP逆向分析与通讯解密

0x01 初始化年轻人,你是否因看到这样的逆向结果而感到无力?你是否为抓不到包而感觉渗透失去了意义?回归正题,拿到app后初步了解后有下面几个问题:无法抓包做了加固通讯加密也是常见APP反篡改的手段了,简单记录一下自己是如何解决这些问题的。0x02 加载中无法…

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年10月9日11:29:59
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Finalshell 3.9.2.2 逆向破解https://cn-sec.com/archives/571388.html