|
[原创]Android inline hook之实现原理
有没有考虑arm和thumb指令区别对待的问题啊? |
|
[讨论]明明是讨论android安全技术的栏目,为什么到处都充斥着破解的帖子!
言之有理,就像netsniffer说的,程序猿混口饭吃不容易啊~ |
|
[讨论]明明是讨论android安全技术的栏目,为什么到处都充斥着破解的帖子!
连版主大大都来了,希望出台规定,发帖子时不能附上已破解的apk,留给那些苦逼的程序猿一条活路吧~ |
|
|
|
[讨论]明明是讨论android安全技术的栏目,为什么到处都充斥着破解的帖子!
我觉得你可以分享你破解的方法,但不应该把破解后重新打包的apk文件也放出来,至少这样不会很简单的流向某些android论坛上。 |
|
[讨论]明明是讨论android安全技术的栏目,为什么到处都充斥着破解的帖子!
查个id,改个几行smali代码,重新打包下,这也叫辛苦? |
|
[求助]古河大哥,能否帮忙实现android inline hook呢?
谢谢哦,已经发现是由于被HOOK函数采用了thumb指令的缘故,如果被强制替换成arm指令,会出现 (ILL_ILLOPC 非法指令)的错误! |
|
[求助]古河大哥,能否帮忙实现android inline hook呢?
现在发现hook有些函数倒是无所谓,但对于某些函数还是会出现crash,错误信息如下: 09-01 13:54:04.871: A/libc(6744): Fatal signal 4 (SIGILL) at 0x2ac0f754 (code=1) 09-01 13:54:05.282: I/DEBUG(21431): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 09-01 13:54:05.282: I/DEBUG(21431): Build fingerprint: 'SEMC/MT15i_1247-4369/MT15i:4.0.4/4.1.B.0.587/tL1_3w:user/release-keys' 09-01 13:54:05.282: I/DEBUG(21431): pid: 6744, tid: 6744 >>> com.test<<< 09-01 13:54:05.282: I/DEBUG(21431): signal 4 (SIGILL), code 1 (ILL_ILLOPC), fault addr 2ac0f754 09-01 13:54:05.282: I/DEBUG(21431): r0 00010810 r1 2b558d20 r2 001d2008 r3 2bfed118 09-01 13:54:05.282: I/DEBUG(21431): r4 3653e980 r5 00012b68 r6 00000000 r7 364e2b88 09-01 13:54:05.282: I/DEBUG(21431): r8 7ed0c6b0 r9 364e2b68 10 37897cd4 fp 7ed0c6c4 09-01 13:54:05.282: I/DEBUG(21431): ip 2ac0f755 sp 7ed0c698 lr 2b2bdc34 pc 2ac0f754 cpsr 80000030 09-01 13:54:05.282: I/DEBUG(21431): d0 6472656767756265 d1 432d000000000028 09-01 13:54:05.282: I/DEBUG(21431): d2 4200000000000063 d3 000000000000006f 09-01 13:54:05.282: I/DEBUG(21431): d4 3f80000045655000 d5 0000000000000000 09-01 13:54:05.282: I/DEBUG(21431): d6 432d000000000000 d7 4200000000000000 09-01 13:54:05.282: I/DEBUG(21431): d8 3f8000003f800000 d9 43f0000043ce0000 09-01 13:54:05.282: I/DEBUG(21431): d10 0000000000000000 d11 0000000000000000 09-01 13:54:05.282: I/DEBUG(21431): d12 0000000000000000 d13 0000000000000000 09-01 13:54:05.282: I/DEBUG(21431): d14 0000000000000000 d15 0000000000000000 09-01 13:54:05.282: I/DEBUG(21431): d16 0035d6380035d638 d17 bff0000000000000 09-01 13:54:05.282: I/DEBUG(21431): d18 3ff0000000000000 d19 0000000000000000 09-01 13:54:05.282: I/DEBUG(21431): d20 0000000000000000 d21 0000000000000000 09-01 13:54:05.282: I/DEBUG(21431): d22 3ff0000000000000 d23 0000000000000000 09-01 13:54:05.282: I/DEBUG(21431): d24 3ff0000000000000 d25 0000000000000000 09-01 13:54:05.282: I/DEBUG(21431): d26 0000000000000000 d27 0000000000000000 09-01 13:54:05.282: I/DEBUG(21431): d28 001e001d001c001b d29 0020001f001e001c 09-01 13:54:05.282: I/DEBUG(21431): d30 000a000a000a000a d31 0000000000000000 09-01 13:54:05.282: I/DEBUG(21431): scr 60000013 09-01 13:54:05.661: I/DEBUG(21431): #00 pc 00000754 /system/lib/libandroid_runtime.so 09-01 13:54:05.661: I/DEBUG(21431): #01 pc 0001ec30 /system/lib/libdvm.so (dvmPlatformInvoke) 09-01 13:54:05.661: I/DEBUG(21431): #02 pc 00058c70 /system/lib/libdvm.so (_Z16dvmCallJNIMethodPKjP6JValuePK6MethodP6Thread) 09-01 13:54:05.661: I/DEBUG(21431): code around pc: 09-01 13:54:05.661: I/DEBUG(21431): 2ac0f734 a905b110 eee0f7dc ecbdb006 e8bd8b02 ................ 09-01 13:54:05.661: I/DEBUG(21431): 2ac0f744 bf0087f0 fffff987 00030098 000300a5 ................ 09-01 13:54:05.661: I/DEBUG(21431): 2ac0f754 e59ff000 e1a08008 39b71030 f8d1461e ........0..9.F.. 09-01 13:54:05.661: I/DEBUG(21431): 2ac0f764 46195294 8020f8dd 9b0d47a8 0a0aed9d .R.F.. ..G...... 09-01 13:54:05.661: I/DEBUG(21431): 2ac0f774 eddd9a09 ebc80a0b 93000202 eb009b0c ................ 09-01 13:54:05.661: I/DEBUG(21431): code around lr: 09-01 13:54:05.661: I/DEBUG(21431): 2b2bdc14 3497c004 3488c004 3afffff9 e2888004 ...4...4...:.... 09-01 13:54:05.661: I/DEBUG(21431): 2b2bdc24 eafffff9 e899000c e59bc00c e12fff3c ............<./. 09-01 13:54:05.661: I/DEBUG(21431): 2b2bdc34 e3560000 159bc010 e24bd014 188c0003 ..V.......K..... 09-01 13:54:05.661: I/DEBUG(21431): 2b2bdc44 e8bd8bc0 e1a0ce22 e59b6008 e2866001 ...."....`...`.. 09-01 13:54:05.661: I/DEBUG(21431): 2b2bdc54 e3a02000 e4d6c001 e35c0000 0a000007 . ........\..... 09-01 13:54:05.661: I/DEBUG(21431): memory map around addr 2ac0f754: 09-01 13:54:05.661: I/DEBUG(21431): 2abb7000-2ac0f000 /system/lib/libandroid_runtime.so 09-01 13:54:05.661: I/DEBUG(21431): 2ac0f000-2ac11000 /system/lib/libandroid_runtime.so 09-01 13:54:05.661: I/DEBUG(21431): 2ac11000-2ac1f000 /system/lib/libandroid_runtime.so 09-01 13:54:05.661: I/DEBUG(21431): stack: 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c658 432d0000 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c65c 00000000 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c660 00000000 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c664 2b4ce18b /system/lib/libhwui.so 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c668 42000000 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c66c 00000001 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c670 3f800000 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c674 3f800000 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c678 2b4ce139 /system/lib/libhwui.so 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c67c 00012b68 [heap] 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c680 00000007 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c684 364e2bf4 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c688 7ed0c6b0 [stack] 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c68c 2ac0edbd /system/lib/libandroid_runtime.so 09-01 13:54:05.661: I/DEBUG(21431): 7ed0c690 df0027ad 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c694 00000000 09-01 13:54:05.671: I/DEBUG(21431): #01 7ed0c698 00000000 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c69c 0000000a 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c6a0 00000000 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c6a4 41c80000 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c6a8 00000002 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c6ac 0035b238 [heap] 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c6b0 364e2b68 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c6b4 00000001 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c6b8 2b558d20 /dev/ashmem/dalvik-heap (deleted) 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c6bc 00012b78 [heap] 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c6c0 0000005c 09-01 13:54:05.671: I/DEBUG(21431): 7ed0c6c4 2b2f7c73 /system/lib/libdvm.so 09-01 13:54:08.101: I/BootReceiver(306): Copying /data/tombstones/tombstone_05 to DropBox (SYSTEM_TOMBSTONE) |
|
[求助]古河大哥,能否帮忙实现android inline hook呢?
我了解android的源码,并且我发现很多库,不仅在不同android版本会有很大差异,而且一些厂商会去修改某些库,比如为了加速libjpeg,libpng的解码速度,会对其进行一些修改,不仅如此,还会对另一个库做些适应性修改(如依赖libjpeg,libpng的libskia),所以直接暴力替换某些库的方法很不可取的。 所以才会想用inline hook,因为相比起替换库的方式,它的代价最小,风险也是最小的。 |
|
[求助]古河大哥,能否帮忙实现android inline hook呢?
谢谢回复: 1.相对寻址指令、thumb1 和 ARM指令切换、arm v6 v7 thumb1 thumb2 确实都是问题,不过还好,我需要HOOK函数的貌似都没有 2.对于cache刷新,从现在执行结果上看,貌似是正常的,哈哈! 你说的iphone substrate这个,能不能提供下链接阿,谢谢! |
|
[求助]古河大哥,能否帮忙实现android inline hook呢?
求人不如求己阿,已经解决啦!现在放出被注入的SO源码(至于如何注入并查找目标函数,自己去看看古河大哥的libinject); 源码主要分为两块: 1.用于初始化trampoline和实现自己函数的libservice.cpp 2.用于实现trampoline的shellcode.s /* libservice.cpp */ #include <sys/ptrace.h> #include <asm/user.h> #include <sys/wait.h> #include <sys/mman.h> #include <dlfcn.h> #include <dirent.h> #include <unistd.h> #include <string.h> #include <elf.h> #include <sys/types.h> #include <fcntl.h> #include <errno.h> #include <netdb.h> #include <arpa/inet.h> #include <sys/stat.h> #include <pthread.h> #include <unistd.h> #include <stdbool.h> #include <string.h> #include <android/log.h> #include <stdio.h> #include <stdlib.h> #include <semaphore.h> #include <elf.h> #include <errno.h> #include <sys/ioctl.h> #include <fcntl.h> #include <linux/input.h> #include "../common/Log.h" #define LOG_TAG "Service" typedef void (*fun_XXXX)(void); extern uint32_t _hijack, _o_code_0, _o_code_1, _addr_o_code_2, _addr_hook_proc, _n_code_0, _n_code_1; extern "C" void XXXX_stub() { LOGI("[+] XXXX() is called"); } /* 根据古河大哥的libject,init函数将会在inject的时候被调到,这里我们传入被hook函数的地址 */ extern "C" int init(void *arg) { unsigned int original_XXXX_addr = (unsigned int)arg; void* page_start = (void *)(((long)&_hijack / PAGE_SIZE) * PAGE_SIZE); if(-1 == mprotect((void *)page_start, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC) { LOGE("mprotect failed(%d)", errno ); return -1; } page_start = (void *)(((long)g_original_XXXX / PAGE_SIZE) * PAGE_SIZE); if(-1 == mprotect((void *)page_start, PAGE_SIZE * 2, PROT_READ | PROT_WRITE | PROT_EXEC)) { LOGE("mprotect failed(%d)", errno ); return -1; } _o_code_0 = *((unsigned int*)g_original_XXXX); //从被hook函数处读取第一条原始指令 _o_code_1 = *((unsigned int*)g_original_XXXX + 1); //从被hook函数处读取第二条原始指令 _addr_o_code_2 = (unsigned int)((unsigned int*)g_original_XXXX + 2); //hook函数第三条指令地址 _addr_hook_proc = (unsigned int)XXXX_stub; //设置自己函数的地址 _n_code_1 = (unsigned int)&_hijack; memcpy((void *)g_original_XXXX, (void *)&_n_code_0, 2 * sizeof(unsigned int)); //将新的两条指令写入到被hook函数的头两条指令处 return 0; } /* shellcode.s */ .global _hijack .global _o_code_0 .global _o_code_1 .global _addr_o_code_2 .global _addr_hook_proc .global _n_code_0 .global _n_code_1 .data _hijack: stmdb sp!, {r0-r11,lr} @将需要保护的寄存器(r0-r11,lr)压栈 ldr r3, _addr_hook_proc @将自己的函数地址装载到寄存器r3 blx r3 @调用自己的函数 ldmia sp!, {r0-r11, lr} @恢复寄存器(r0-r11,lr) _o_code_0: .word 0x11111111 @执行被hook函数的第一条原始指令(需要在程序中初始化) _o_code_1: .word 0x11111111 @执行被hook函数的第二条原始指令(需要在程序中初始化) ldr pc, _addr_o_code_2 @跳转到被hook函数的第三条原始指令处继续执行 _addr_o_code_2: .word 0x11111111 @用于保存被hook函数的第三条原始指令的地址(需要在程序中初始化) _addr_hook_proc: .word 0x11111111 @用于保存自己函数的地址(需要在程序中初始化) _n_code_0: ldr pc, _n_code_1 @该指令需要被写入被hook函数的第一条指令处,这条指令后就会立即跳转到_hijack处了 _n_code_1: .word 0x11111111 @用于保存trampoline的起始地址,需要被写入被hook函数的第二条指令处(需要在程序中初始化) .space 0x900, 0 .end 已知问题: 如果被HOOK函数的头两条指令存在相对寻址指令的话,就会有问题。 参考文献: 1.http://bbs.pediy.com/showthread.php?t=72728 2.http://bbs.routerclub.com/blog-681-7706.html 3.http://blog.dbgtech.net/blog/?p=51 |
|
[求助]古河大哥,能否帮忙实现android inline hook呢?
我觉得这样是不行的,对于有些库,很多厂商为了加入它们自己的feature会做些修改的,如果暴力的替换掉,很可能导致系统无法启动,用户会骂死你的哦! |
|
[求助]古河大哥,能否帮忙实现android inline hook呢?
是啊,上海苦逼程序猿一个 |
|
[原创]发个Android平台上的注入代码
确实是这样的~~ |
|
[求助]请问一下 安卓有没有类似windows ReadProcessMemory 用于读目标进程内存的函数?
ptrace() 需要root权限 八门神器也就基于这个的,很简单的! |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值