【问题标题】:Unable to find base address or exported function of dynamically loaded library找不到动态加载库的基地址或导出函数
【发布时间】: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


【解决方案1】:

这是因为当您发现 JNI_OnLoad 被 IDA 导出时,已经调用了 JNI_OnLoad。 你可以试试这个方法HOOKJNI_OnLoad来分析JNI_OnLoad的行为。
1.写一个执行dlopenlibrary_name.so获取库句柄
2.使用dlsym获取JNI_OnLoad符号地址
3.使用inlinehook钩子符号地址。
4.随心所欲。

【讨论】:

    猜你喜欢
    • 2020-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-20
    • 1970-01-01
    相关资源
    最近更新 更多