想做字符串解密,想着已加载后so应该是解密后的,那就把so导出会再用ida 打开,是否就是已解密后的so呢?我决定试试!
测试apk:
看雪3万班\01FRIDA高级逆向\3月-Frida高级逆向\课时4\hellojni_2.0.0.apk
function dumpso(){
let modu=Process.getModuleByName("libhello-jni.so")
console.log("name: " +modu.name);
console.log("base: " +modu.base);
// dump so
// var file_path = "/sdcard/" + modu.name + "_" + modu.base + ".so";
var file_path = "/data/data/com.example.hellojni_sign2/" + modu.name + "_" + modu.base + ".so";
var file_handle = new File(file_path, "wb");
if (file_handle && file_handle != null) {
Memory.protect(ptr(modu.base), modu.size, 'rwx');
var libso_buffer = ptr(modu.base).readByteArray(modu.size);
file_handle.write(libso_buffer);
file_handle.flush();
file_handle.close();
console.log("[dump]:", file_path);
}
}
function hook_dlopen() {
/* var dlopen = Module.findExportByName(null, "dlopen");
Interceptor.attach(dlopen, {
onEnter: function (args) {
this.call_hook = false;
var so_name = ptr(args[0]).readCString();
if (so_name.indexOf("libhello-jni.so") >= 0) {
console.log("dlopen:", ptr(args[0]).readCString());
this.call_hook = true;
}
}, onLeave: function (retval) {
if (this.call_hook) {
inline_hook();
}
}
});*/
// 高版本Android系统使用android_dlopen_ext
var android_dlopen_ext = Module.findExportByName(null, "android_dlopen_ext");
Interceptor.attach(android_dlopen_ext, {
onEnter: function (args) {
this.call_hook = false;
var so_name = ptr(args[0]).readCString();
if (so_name.indexOf("libhello-jni.so") >= 0) {
console.log("android_dlopen_ext:", ptr(args[0]).readCString());
this.call_hook = true;
}
}, onLeave: function (retval) {
if (this.call_hook) {
dumpso();
}
}
});
}
setImmediate(function (){
dumpso()
//hook_dlopen()
})
//frida -U -f "com.example.hellojni_sign2" -l dumpso.js
注意: 写so文件的时候,把文件写在 /data/data/包名 目录下,这个目录大概率下是可以读写的。之前写入路径/sdcard/提示失败,需要转到/data/local/tmp文件夹中再adb pull 中电脑中,或者chmod 添加权限。adb pull 如果不成功,就chmod 777 xxx.so之后再传。
如果没有pull /data/data/包名 这个目录的权限,那就先copy到 /data/local/tmp 目录下面。
拖到ida中分析,结果报错。提示“First section must be SHT_NULL. Continue?”
使用sofixer修复后即可。windows编译方式
mkdir build
# 参数 -DSO_64=ON 用于修复64位so文件,不添加则为修复32位so文件
cmake -G "MinGW Makefiles"-DSO_64=ON ..
cmake --build .
sofixer 使用:
sofixer -s soruce.so -o fix.so
ida 打开,view->open subview ->strings 可看到字符串解密后结果。
但使用过程中发现修复后的32位so有问题,64位so暂时没有发现。以xmly 9.0.76.3的libencrypt.so为例,修复后的so,在0x12bc1处代码无法按f5查看伪c代码,也无法按空格键切换到图形。阅读以下链接后,按操作点中函数的名称,右键 create function 后修复。
https://blog.csdn.net/chence19871/article/details/12709709
以下为参考链接
https://github.com/F8LEFT/SoFixer