使用 vlx-vmengine 进行反混淆。

vlx-vmengine-jvm 是一个用Java实现的Java字节码执行引擎。请参阅https://github.com/vlinx-io/vlx-vmengine-jvm 其用途。

有一个简单的片段Java代码如下:

class HelloWorld {

    private String name = "";

    public HelloWorld(String name){
        this.name = name;
    }

    public void sayHi(){
        System.out.println("Hi, " + name);
    }

    public static void main(String[] args){
        
        String name = "George";
        HelloWorld hello = new HelloWorld(name);

        hello.sayHi();

    }

}

在编译成类文件并使用某个混淆引擎混淆后,得到以下文件:

一类

在使用jadx打开后,发现除了main 函数,所有其他信息都无法识别,并且字符串已被加密。

image-20230521195209691

不过,即使混淆了,类的基本结构和字节码信息仍然存在。使用类查看器打开a.class,可以看到类的方法和字节码信息。 image-20230521200149593

无论如何混淆,都只能在静态层面上混淆代码,增加分析的复杂度。在动态执行时,仍然需要恢复程序原有的运行逻辑。使用vlx-vmengine-jvm运行混淆后的代码main通过这种方法,我们得到以下输出

2023-05-21 18:19:05 [DEBUG] LocalVars: [kotlin.Unit, kotlin.Unit, kotlin.Unit]
2023-05-21 18:19:05 [DEBUG] "L0: SIPUSH"
2023-05-21 18:19:05 [DEBUG] "push" 7144
2023-05-21 18:19:05 [DEBUG] "L3: SIPUSH"
2023-05-21 18:19:05 [DEBUG] "push" -13249
2023-05-21 18:19:05 [DEBUG] "L6: INVOKESTATIC"
2023-05-21 18:19:05 [DEBUG] "#20"
2023-05-21 18:19:05 [DEBUG] "class a, NameAndType(name='a', type='(II)Ljava/lang/String;')"
2023-05-21 18:19:05 [DEBUG] private static java.lang.String a.a(int,int)
2023-05-21 18:19:05 [DEBUG] "pop" -13249
2023-05-21 18:19:05 [DEBUG] "pop" 7144
2023-05-21 18:19:05 [DEBUG] 	Execute method: private static java.lang.String a.a(int,int)
2023-05-21 18:19:05 [DEBUG] 	Args: [7144, -13249]
2023-05-21 18:19:05 [DEBUG] "push" "George"
2023-05-21 18:19:05 [DEBUG] "L9: ASTORE_1"
2023-05-21 18:19:05 [DEBUG] "pop" "George"
2023-05-21 18:19:05 [DEBUG] "localVars[1] = George"
2023-05-21 18:19:05 [DEBUG] "L10: NEW"
2023-05-21 18:19:05 [DEBUG] class a
2023-05-21 18:19:05 [DEBUG] "push" InstanceToCreate(clazz=class a)
2023-05-21 18:19:05 [DEBUG] "L13: DUP"
2023-05-21 18:19:05 [DEBUG] "pop" InstanceToCreate(clazz=class a)
2023-05-21 18:19:05 [DEBUG] "push" InstanceToCreate(clazz=class a)
2023-05-21 18:19:05 [DEBUG] "push" InstanceToCreate(clazz=class a)
2023-05-21 18:19:05 [DEBUG] "L14: ALOAD_1"
2023-05-21 18:19:05 [DEBUG] "#1"
2023-05-21 18:19:05 [DEBUG] "push" "George"
2023-05-21 18:19:05 [DEBUG] "L15: INVOKESPECIAL"
2023-05-21 18:19:05 [DEBUG] "#47"
2023-05-21 18:19:05 [DEBUG] "class a, NameAndType(name='<init>', type='(Ljava/lang/String;)V')"
2023-05-21 18:19:05 [DEBUG] public a(java.lang.String)
2023-05-21 18:19:05 [DEBUG] "pop" "George"
2023-05-21 18:19:05 [DEBUG] "Execute new instance: public a(java.lang.String)"
2023-05-21 18:19:05 [DEBUG] "Args: [George]"
2023-05-21 18:19:05 [DEBUG] "pop" InstanceToCreate(clazz=class a)
2023-05-21 18:19:05 [DEBUG] "L18: ASTORE_2"
2023-05-21 18:19:05 [DEBUG] "pop" a@4612b856
2023-05-21 18:19:05 [DEBUG] "localVars[2] = a@4612b856"
2023-05-21 18:19:05 [DEBUG] "L19: ALOAD_2"
2023-05-21 18:19:05 [DEBUG] "#2"
2023-05-21 18:19:05 [DEBUG] "push" a@4612b856
2023-05-21 18:19:05 [DEBUG] "L20: INVOKEVIRTUAL"
2023-05-21 18:19:05 [DEBUG] "#54"
2023-05-21 18:19:05 [DEBUG] "class a, NameAndType(name='a', type='()V')"
2023-05-21 18:19:05 [DEBUG] public void a.a()
2023-05-21 18:19:05 [DEBUG] "pop" a@4612b856
2023-05-21 18:19:05 [DEBUG] 	Execute method: public void a.a()
2023-05-21 18:19:05 [DEBUG] 	Receiver: a@4612b856
2023-05-21 18:19:05 [DEBUG] 	Args: [a@4612b856]
Hi, George
2023-05-21 18:19:05 [DEBUG] "L23: RETURN"

从控制台输出中,我们可以看到程序已恢复其原始行为,即打印Hi, George。同时,从输出中我们也可以判断出字符串的解密函数在private static java.lang.String a.a(int,int)带参数7144-13249。如果我们继续使用vmengine来调试a.a(int,int) 方法,我们可以发现该混淆引擎使用的字符串加密方法。