iOS LLDB中反反调试分析与实现
ptrace
sysctl
syscall
SIGTOP
task_get_exception_ports
1、map new page for patch
// map new page for patch
void *new = mmap(0, 0x1000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
if (!new ){
NSLog(@"[-] mmap failed!");
return;
}
NSLog(@"[*] new map address:%p", new);
2、start patch
// start patch
kret = vm_copy(self_task, (unsigned long)page_start, 0x1000, (vm_address_t) new);
if (kret != KERN_SUCCESS){
NSLog(@"[-] kr: %d, errno: %d", kret, errno);
return;
}
char patch_ret_ins_data[4] = {0xc0, 0x03, 0x5f, 0xd6}; // ret
memcpy((void *)(new+patch_offset), patch_ret_ins_data, 4);
NSLog(@"[*] new map+offset address:%p", (void *)(new+patch_offset));
3、set new page back to r-x
// set back to r-x
int ret = mprotect(new, 0x1000, PROT_READ | PROT_EXEC);
NSLog(@"[*] ret: %d, errno: %d, addr: %p", ret, errno, new);
4、remap the target page
kret = mach_vm_remap(mach_task_self(), &target, 0x1000, 0,
VM_FLAGS_OVERWRITE, self_task,
(mach_vm_address_t) new, TRUE,
&c, &m, inherit);
if(kret != KERN_SUCCESS){
NSLog(@"[-] kr: %d, errno: %d", kret, errno);
return;
}
NSLog(@"[*] now ptrace_ptr address:%p", ptrace_ptr)
5、clear cache
sys_icache_invalidate (clear_start_, 4);
sys_dcache_flush (clear_start_, 4);
后台启动方式启动爱奇艺:
xia0 ~ $ issh debug -x backboard /var/containers/Bundle/Application/F9D8AACA-30F0-4F26-96CA-5B06782CC903/iQiYiPhoneVideo.app/iQiYiPhoneVideo
[I]:iproxy process for 2222 port alive, pid=16264
[I]:++++++++++++++++++ Nice to Work :) +++++++++++++++++++++
[I]:iOSRE dir exist
[I]:iproxy process for 1234 port alive, pid=16428
[I]:Run ps -e | grep debugserver | grep -v grep; [[ 0 == 0 ]] && (killall -9 debugserver 2> /dev/null)
[I]:/iOSRE/tools/debugserver file exist, Start debug...
[I]:Run /iOSRE/tools/debugserver 127.0.0.1:1234 -x backboard /var/containers/Bundle/Application/F9D8AACA-30F0-4F26-96CA-5B06782CC903/iQiYiPhoneVideo.app/iQiYiPhoneVideo
LLDB挂上以后在main函数下断点以后直接执行debugme命令
(lldb) debugme
Kill antiDebug by xia0:
[*] target address: 6501024128 and offset: 384
[*] mmap new page: 4572217344 success!
[+] vm_copy success!
[+] mach_vm_write success!
[*] set new page back to r-x success!
[*] vm_region_recurse_64 success!
[*] get page info success!
[+] remap success!
[*] clear cache success!
[+] all done! happy debug~
Patch之前:
(lldb) x/12i 0x00000001837dc180
0x1837dc180: 0xf00f26a9 adrp x9, 124119
0x1837dc184: 0x91034129 add x9, x9, #0xd0 ; =0xd0
0x1837dc188: 0xb900013f str wzr, [x9]
0x1837dc18c: 0xd2800350 mov x16, #0x1a
0x1837dc190: 0xd4001001 svc #0x80
0x1837dc194: 0x540000c3 b.lo 0x1837dc1ac ; <+44>
0x1837dc198: 0xa9bf7bfd stp x29, x30, [sp, #-0x10]!
0x1837dc19c: 0x910003fd mov x29, sp
0x1837dc1a0: 0x97ff9b08 bl 0x1837c2dc0 ; cerror
0x1837dc1a4: 0x910003bf mov sp, x29
0x1837dc1a8: 0xa8c17bfd ldp x29, x30, [sp], #0x10
0x1837dc1ac: 0xd65f03c0 ret
Patch之后:
(lldb) x/12i 0x1837dc180
0x1837dc180: 0xd65f03c0 ret
0x1837dc184: 0x91034129 add x9, x9, #0xd0 ; =0xd0
0x1837dc188: 0xb900013f str wzr, [x9]
0x1837dc18c: 0xd2800350 mov x16, #0x1a
0x1837dc190: 0xd4001001 svc #0x80
0x1837dc194: 0x540000c3 b.lo 0x1837dc1ac ; <+44>
0x1837dc198: 0xa9bf7bfd stp x29, x30, [sp, #-0x10]!
0x1837dc19c: 0x910003fd mov x29, sp
0x1837dc1a0: 0x97ff9b08 bl 0x1837c2dc0 ; cerror
0x1837dc1a4: 0x910003bf mov sp, x29
0x1837dc1a8: 0xa8c17bfd ldp x29, x30, [sp], #0x10
0x1837dc1ac: 0xd65f03c0 ret
Process 3176 resuming
2019-08-13 17:22:17.283 iQiYiPhoneVideo[3176:161840] [plcrash]: init ok
2019-08-13 17:22:17.790 iQiYiPhoneVideo[3176:161840] -[QYBaikePageDurationManager bk_appDidBecomeActive:]
2019-08-13 17:22:17.922 iQiYiPhoneVideo[3176:161840] CoreData: Failed to load optimized model at path '/var/containers/Bundle/Application/F9D8AACA-30F0-4F26-96CA-5B06782CC903/iQiYiPhoneVideo.app/QYPGCDataModel.momd/QYPGCDataModel_970.omo'
2019-08-13 17:22:20.477 iQiYiPhoneVideo[3176:161840] OSStatus error: [-34018] Security error has occurred.
2019-08-13 17:22:20.558 iQiYiPhoneVideo[3176:162000] OSStatus error: [-34018] Security error has occurred.
3176:161840] Incorrect NSStringEncoding value 0x8000100 detected. Assuming NSASCIIStringEncoding. Will stop this compatiblity mapping behavior in the near future.
ontainers/Data/Application/5C31FE18-9BA4-4B2D-80C6-68BF7F65855F/Library/Application Support/爱奇艺/0_im.sqlite
参考/致谢
- End -
看雪ID:xia0
https://bbs.pediy.com/user-766212.htm
*本文由看雪论坛 xia0 原创,转载请注明来自看雪社区
推荐文章++++
进阶安全圈,不得不读的一本书
﹀
﹀
﹀
↙点击下方“阅读原文”,查看原文