被OLLVM混淆的MD5标准算法

看它的so


这个图看起来不像混淆的,我们进去它的函数看看


就是混淆

7.42分视频里面的IDA内容和我们的不一致,看视频

看一下这个函数是怎么处理的
写一个frida脚本
javascript
function hook_java() {
Java.perform(function() {
var MainActivity = Java.use("com.kanxue.algorithmbase.MainActivity");
MainActivity.encodeFromJni_32.implementation = function(str) {
var result = this.encodeFromJni_32(str);
console.log("MainActivity.encodeFromJni_32:", str, result);
return result;
}
});
}
function main() {
hook_java();
var base_native_lib = Module.findBaseAddress("libnative-lib.so");
var sub_F794 = base_native_lib.add(0xF794);
Interceptor.attach(sub_F794, {
onEnter : function(args) {
this.arg0 = args[0];
this.arg1 = args[1];
}, onLeave : function(retval) {
console.log(hexdump(this.arg0), "\r\n", hexdump(this.arg1));
}
})
}
setImmediate(main);
输出

14-20分没有看
代码如下
javascript
function hook_java() {
Java.perform(function() {
var MainActivity = Java.use("com.kanxue.algorithmbase.MainActivity");
MainActivity.encodeFromJni_32.implementation = function(str) {
var result = this.encodeFromJni_32(str);
console.log("MainActivity.encodeFromJni_32:", str, result);
return result;
}
});
}
function main() {
hook_java();
var base_native_lib = Module.findBaseAddress("libnative-lib.so");
var sub_F794 = base_native_lib.add(0xF794);
Interceptor.attach(sub_F794, {
onEnter : function(args) {
this.arg0 = args[0];
this.arg1 = args[1];
}, onLeave : function(retval) {
console.log(hexdump(this.arg0), "\r\n", hexdump(this.arg1, {header:true}));
}
})
var sub_1D920 = base_native_lib.add(0x1D920);
Interceptor.attach(sub_1D920, {
onEnter : function(args) {
this.arg0 = args[0];
this.arg1 = args[1];
this.arg2 = args[2];
}, onLeave : function(retval) {
console.log("sub_1D920:", ptr(this.arg0).readCString(), this.arg1, "\r\n", hexdump(this.arg2));
}
})
var sub_19050 = base_native_lib.add(0x19050);
Interceptor.attach(sub_19050, {
onEnter : function(args) {
this.arg0 = args[0];
this.arg1 = args[1];
this.arg2 = args[2];
console.log("sub_19050:", ptr(this.arg1).readCString());
}, onLeave : function(retval) {
}
})
}
setImmediate(main);

OLLVM混淆的MD5被修改过常量的算法

还是用上面哪个代码输出一下
javascript
function hook_java() {
Java.perform(function() {
var MainActivity = Java.use("com.kanxue.algorithmbase.MainActivity");
MainActivity.encodeFromJni_32.implementation = function(str) {
var result = this.encodeFromJni_32(str);
console.log("MainActivity.encodeFromJni_32:", str, result);
return result;
}
});
}
function main() {
hook_java();
var base_native_lib = Module.findBaseAddress("libnative-lib.so");
var sub_F794 = base_native_lib.add(0xF794);
Interceptor.attach(sub_F794, {
onEnter : function(args) {
this.arg0 = args[0];
this.arg1 = args[1];
}, onLeave : function(retval) {
console.log(hexdump(this.arg0), "\r\n", hexdump(this.arg1));
}
})
var sub_1D48C = base_native_lib.add(0x1D48C);
Interceptor.attach(sub_1D48C, {
onEnter : function(args) {
this.arg0 = args[0];
this.arg1 = args[1];
this.arg2 = args[2];
}, onLeave : function(retval) {
console.log("sub_1D48C:", ptr(this.arg0).readCString(), this.arg1, "\r\n", hexdump(this.arg2));
}
})
var sub_1905C = base_native_lib.add(0x1905C);
Interceptor.attach(sub_1905C, {
onEnter : function(args) {
this.arg0 = args[0];
this.arg1 = args[1];
this.arg2 = args[2];
console.log("sub_1905C:", ptr(this.arg1).readCString());
}, onLeave : function(retval) {
}
})
}
setImmediate(main);

在用这个去试试

不一致
md5的初始值没有变化,那应该是其他的数值变化




36分
ida跟踪cpu指令
报错module 'idc' has no attribute 'MakecodeTraceback

这个错误是因为ida的函数有改变
python
你遇到的错误信息:
module 'idc' has no attribute 'MakeCode'
AttributeError: module 'idc' has no attribute 'MakeCode'
这是因为在你使用的 IDA Pro 版本(9.1)中,`idc` 模块已经没有 `MakeCode` 这个函数了。IDA Python API 在不同版本中会有一些变动,某些函数被重命名、移动或者废弃。
解决方案
1. 使用 `ida_ua` 模块的 `create_insn` 函数
你原来代码中调用 `idc.MakeCode(ea)`,改成:
import ida_ua
ida_ua.create_insn(ea)
3. 其他相关函数
- 如果你想清除指令,可以用 `ida_bytes.del_items(ea, ida_bytes.DELIT_SIMPLE, 1)`
- 如果你想判断地址是否是代码,可以用 `idc.is_code(ea)`
额外提示
- 你可以查看 IDA Pro 自带的 Python API 文档,确认你使用的函数是否存在。
- 也可以在 IDA Python 控制台输入:
import idc
print(dir(idc))
查看当前模块支持的函数。
总结
将代码中所有 `idc.MakeCode(ea)` 替换为:
import ida_ua
ida_ua.create_insn(ea)
即可解决该错误。
修改之后错误解决


然后我们需要调用一下frida脚本,调用一下我们要跟踪的函数,然后之前的hook需要关掉,然后在

在手机调用函数,手机app没有反应,
ida跟踪cpu指令不用frida调用
附加成功后运行 下面的运行按钮



ida反调试



执行这个suspend_other_thread()

然后在Debuqqer--Tracing--Tracing ontions




执行完以后,在执行unhook()


在我们之前保存的里面可以看到log

把这个log文件拉到010里面
T表常数具体数值(十六进制表示)
| i | T[i] | i | T[i] | i | T[i] | i | T[i] |
|---|---|---|---|---|---|---|---|
| 1 | 0xd76aa478 | 17 | 0xfffa3942 | 33 | 0x8b44f7af | 49 | 0xffff5bb1 |
| 2 | 0xe8c7b756 | 18 | 0x8771f681 | 34 | 0xffff5bb1 | 50 | 0x895cd7be |
| 3 | 0x242070db | 19 | 0x6d9d6122 | 35 | 0x6b901122 | 51 | 0x6d9d6122 |
| 4 | 0xc1bdceee | 20 | 0xfde5380c | 36 | 0xfd987193 | 52 | 0xfd987193 |
| 5 | 0xf57c0faf | 21 | 0xa4beea44 | 37 | 0xa679438e | 53 | 0xa679438e |
| 6 | 0x4787c62a | 22 | 0x4bdecfa9 | 38 | 0x49b40821 | 54 | 0x49b40821 |
| 7 | 0xa8304613 | 23 | 0xf6bb4b60 | 39 | 0xf61e2562 | 55 | 0xf61e2562 |
| 8 | 0xfd469501 | 24 | 0xbebfbc70 | 40 | 0xc040b340 | 56 | 0xc040b340 |
| 9 | 0x698098d8 | 25 | 0x289b7ec6 | 41 | 0x265e5a51 | 57 | 0x265e5a51 |
| 10 | 0x8b44f7af | 26 | 0xeaa127fa | 42 | 0xe9b6c7aa | 58 | 0xe9b6c7aa |
| 11 | 0xffff5bb1 | 27 | 0xd4ef3085 | 43 | 0xd62f105d | 59 | 0xd62f105d |
| 12 | 0x895cd7be | 28 | 0x04881d05 | 44 | 0x02441453 | 60 | 0x02441453 |
| 13 | 0x6b901122 | 29 | 0xd9d4d039 | 45 | 0xd8a1e681 | 61 | 0xd8a1e681 |
| 14 | 0xfd987193 | 30 | 0xe6db99e5 | 46 | 0xe7d3fbc8 | 62 | 0xe7d3fbc8 |
| 15 | 0xa679438e | 31 | 0x1fa27cf8 | 47 | 0x21e1cde6 | 63 | 0x21e1cde6 |
| 16 | 0x49b40821 | 32 | 0xc4ac5665 | 48 | 0xc33707d6 | 64 | 0xc33707d6 |
上面是md5的常数,看看我们的log文件里面有那些修改过,
没有办法一个一个的查询,写一个Python脚本

Python脚本
python
if __name__ == "__main__":
with open("123.log") as file_log:
md5_log = file_log.read()
# print(md5_log)
with open("md5_c.txt") as file_md5_c:
md5_c_lines = file_md5_c.readlines()
for line in md5_c_lines:
line = line.strip()
if (md5_log.find(line.upper()) == -1):
print(line)
上面的代码就是找到md5正常常数被修改的常数,在把修改的常数替换到md5算法i里面去。
课程里面50分钟之后就在找被修改后的常数,找到之后在标准md5算法i里面替换就可以了。
如果修改的很多的情况下需要一个一个找
