【发布时间】:2021-01-07 23:34:45
【问题描述】:
我能够检测到何时使用 System.loadLibrary 加载了库,但 Module.findBaseAddress 返回 null 并且 Module.enumerateExports 不返回任何内容。
这是我的代码:
function processJniOnLoad(libraryName) {
const funcSym = "JNI_OnLoad";
const funcPtr = Module.findExportByName(libraryName, funcSym);
const membase = Module.findBaseAddress(libraryName);
console.log("Base address is " + membase);
console.log("[+] Hooking " + funcSym + "() @ " + funcPtr + "...");
Module.enumerateExports(libraryName, { onMatch: function(e) { console.log("type " + e.type + " name of function = " + e.name + " " + e.address); }, onComplete: function() { } });
}
function waitForLibLoading(libraryName) {
var isLibLoaded = false;
Interceptor.attach(Module.findExportByName(null, "android_dlopen_ext"), {
onEnter: function (args) {
var libraryPath = Memory.readCString(args[0]);
if (libraryPath.includes(libraryName)) {
console.log("[+] Loading library " + libraryPath + "...");
isLibLoaded = true;
}
},
onLeave: function (args) {
if (isLibLoaded) {
processJniOnLoad(libraryName);
isLibLoaded = false;
}
}
});
}
waitForLibLoading("library_name.so");
输出示例:
C:\just_a_path>python peton3.py
[+] Loading library /data/app/com.app_name.app-<random string>==/base.apk!/lib/arm64-v8a/library_name.so...
Base address is null
[+] Hooking JNI_OnLoad() @ null...
查看 IDA 中的 Exports 选项卡,我可以看到 JNI_OnLoad 已导出。
【问题讨论】:
-
根据 Frida 文档
findExportByName需要一个 moduleName 作为第一个参数,而不是文件名。对于您的库,模块名称可能与文件名不同。我会通过Process.enumerateModules()检查加载的模块列表 -
你确定 Windows 中的 Python3 可以处理包含 Java 插件的 Unix 风格的共享对象吗?
标签: android reverse-engineering frida