首页 > 其他分享 >学习笔记-linker框架层的Hook和利用

学习笔记-linker框架层的Hook和利用

时间:2022-11-11 09:37:36浏览次数:33  
标签:function args console addr linker 笔记 Hook call log

系统框架native hook

  • init_array原理so加载执行流程
  • hook_linker init_array自吐
  1. 应用以32位在64位终端运行

adb install --abi armeabi-v7a <path to apk>

  1. hook linker中的call_function函数,打印出函数的虚拟地址 ,进而把函数在so文件中的偏移打印出来,所以说我们要的信息实际上真正的是偏移,这样才可以从ida找到关键代码的地方,进一步分析。 还是老步骤,先看是否导出,不是导出就去遍历符号,找到符号真正的名字,ndk编译会将命名变换,注意下,然后就是我们运行一般就是32位,32位的linker是可以直接找出函数地址的,64位目前无法直接找到

function hook_pthread() {

var pthread_create_addr = Module.findExportByName("libc.so", "pthread_create");
var time_addr = Module.findExportByName("libc.so", "time");
console.log("pthread_create_addr=>", pthread_create_addr)

Interceptor.attach(pthread_create_addr, {
onEnter: function (args) {
console.log("args=>", args[0], args[1], args[2], args[4])
var libnativebaseaddress = Module.findBaseAddress("libnative-lib.so")
if (libnativebaseaddress != null) {
console.log("libnativebaseaddress=>", libnativebaseaddress);
//var detect_frida_loop_addr = args[2]-libnativebaseaddress;
//console.log("detect_frida_loop offset is =>",detect_frida_loop_addr)
if (args[2] - libnativebaseaddress == 0x95c9) {
console.log("found anti frida loop!,excute time_addr=>", time_addr);
args[2] = time_addr;
}
}
}, onLeave: function (retval) {
console.log("retval is =>", retval)
}
})
}
function EnumerateAllExports() {

var linker = Process.getModuleByName("linker")
//console.log("exports=>",JSON.stringify(linker.enumerateSymbols()))
var call_function_addr = null;
var exports = linker.enumerateSymbols();
//console.log("module_name=>",module_name," module.enumerateExports = > ",JSON.stringify(exports))
for (var m = 0; m < exports.length; m++) {
//console.log("m=>",m)
//writeSomething("/sdcard/"+packageName+"/"+module_name+".txt", "type:"+exports[m].type+ " name:"+ exports[m].name+" address:"+exports[m].address+"\n")
//writeSomething("/sdcard/settings/"+module_name+".txt", "type:"+exports[m].type+ " name:"+ exports[m].name+" address:"+exports[m].address+"\n")
if (exports[m].name == "__dl__ZL13call_functionPKcPFviPPcS2_ES0_") {
call_function_addr = exports[m].address;
console.log("found call_function_addr => ", call_function_addr)
hook_call_function(call_function_addr)
}
}
/*
__dl__ZL13call_functionPKcPFvvES0_
__dl_call_function(char const*, void (*)(), char const*)


__dl__ZL13call_functionPKcPFviPPcS2_ES0_
__dl_call_function(char const*, void (*)(int, char**, char**), char const*)
*/

}

function hook_call_function(_call_function_addr){
console.log("hook call function begin!hooking address :=>",_call_function_addr)
Interceptor.attach(_call_function_addr,{
onEnter:function(args){
if(args[2].readCString().indexOf("base.odex")<0){
console.log("function_name : agrs[0]=>",args[0].readCString())
console.log("so path : agrs[2]=>",args[2].readCString())
console.log("function offset : args[1]=>","0x"+(args[1]-Module.findBaseAddress("libnative-lib.so")).toString(16))

}
},onLeave:function(retval){

}
})
}

setImmediate(EnumerateAllExports)

 

 

 

点击关注,共同学习!
[安全狗的自我修养](https://mp.weixin.qq.com/s/E6Kp0fd7_I3VY5dOGtlD4w)


[github haidragon](https://github.com/haidragon)


https://github.com/haidragon

标签:function,args,console,addr,linker,笔记,Hook,call,log
From: https://www.cnblogs.com/haidragon/p/16879540.html

相关文章

  • 学习笔记-Objection环境,自动化分析和插件
    Frida简介objection与frida版本匹配安装objection连接非标准端口objection内存漫游,hook,traceobjection插件体系:Wallbreakerobjection+DEXDump脱壳0x01objec......
  • 学习笔记-Frida上手和逆向三段
    Frida上手和逆向三段FRIDA基本操作:参数,调用栈,返回值frida精髓2:方法重载,参数构造,动静态处理frida精髓3:主动调用,忽略内部细节,直接返回结果逆向三段:(hookinvoke)r......
  • 学习笔记-组件和事件hook核心原理和案例
    组件和事件的hook核心原理和案例0x01构造方法的hook的例子(java.lang.String这个随便哪个类都行)#构造方法的hookJava.use("java.lang.String").$init.implementation=........
  • 学习笔记-Frida反调试思路和hook native
    用户代码nativehookFrida反调试与反反调试基本思路(Java层API,Native层API,Syscall)六月题的Frida反调试的实现以及Native函数的Javahook以及主动调用静态注册函......
  • 学习笔记-hook和主动调用
    用户代码nativehook静态注册函数参数,返回值打印和替换调用栈主动调动符号hook==偏移hook枚举并保存结果0x01修改返回值以及参数和主动调用修改返回值修改......
  • 学习笔记-JNI框架层的Hook利用
    系统框架nativehookJNI函数符号hookJNI函数参数、返回值打印和替换动态注册JNI_OnloadhookRegisterNativesjnitrace引入一个例子,hookGetStringUTFChars这个jn......
  • 学习笔记-libc框架层的Hook利用
    系统框架层nativehooklibc函数符号hooklibc函数参数、返回值打印和替换主动调用libc读写文件hooklinkerdlopenfrida-trace引入例子,先hookpthread这个libc函......
  • Vue3学习笔记(五)——路由,Router
    一、前端路由的概念与原理1.1.什么是路由路由(英文:router)就是对应关系。1.2.SPA与前端路由SPA指的是一个web网站只有唯一的一个HTML页面,所有组件的展示与切换都......
  • 方滨兴院士讲座笔记
    安全和技术是伴生,没有技术,就没有安全问题人工智能在安全领域的四种表现形态深度伪造:利用人工智能仿生,通过像人脸识别那样的检测,或者AI换脸智能防御:人工智能预测攻击后......
  • Head First Java 读书笔记
    第11章:异常处理如果你把有风险的程序代码包含在try/catch块中,那么编译器会放心很多。try/catch块会告诉编译器你确实知道所调用的方法会有风险,并且也已经准备好要处理......