一个简单的so dump脚本

``Java.perform(function () {
const TARGET_SO = "libmxxx.so"; //此处是你要dump的so文件名-------------------------------记得替换哦
const DUMP_PATH = "/sdcard/" + TARGET_SO;
let dumped = false;

// Hook JNI_OnLoad 确保解密完成
const jniOnLoad = Module.findExportByName(TARGET_SO, "JNI_OnLoad");
if (jniOnLoad) {
Interceptor.attach(jniOnLoad, {
onLeave: function() {
if (!dumped) safeDump();
}
});
}

// 监控 SO 加载
const dlopen = Module.findExportByName(null, "dlopen");
Interceptor.attach(dlopen, {
onLeave: function(retval) {
if (!dumped) safeDump();
}
});

// 安全 Dump(分页+权限绕过)
function safeDump() {
const module = Process.findModuleByName(TARGET_SO);
if (!module || dumped) return;
console.log(\n[+] start Dump ${TARGET_SO});
const pageSize = Process.pageSize;
const base = module.base;
const size = module.size;
const file = new File(DUMP_PATH, "wb");
for (let offset = 0; offset < size; offset += pageSize) {
const currentAddr = base.add(offset);
try {
// 尝试修改内存权限(需 Root)
Memory.protect(currentAddr, pageSize, 'r--');
const data = Memory.readByteArray(currentAddr, Math.min(pageSize, size - offset));
file.write(data);
} catch (e) {
console.log([!] 地址 ${currentAddr} 不可读,跳过);
}
}
file.flush();
file.close();
dumped = true;
console.log([√] Dump 完成,文件已保存);
}
// 初始检查
safeDump();
});``

命令:frida -U -l dump.js -n 包名

例如:frida -U -l dump.js -n Gmail

碰到有检测frida的机制,可能会有失败的情况,如果有隐藏frida的好办法,欢迎留言分享,谢谢!

posted @ 2025-03-23 13:34  移动安全老小兵  阅读(90)  评论(0)    收藏  举报