一、环境准备
1、vmware中安装osx系统,参照链接:http://jingyan.baidu.com/article/ff411625b9011212e48237b4.html
2、osx上安装lldb命令行版(安装xcode6.4后lldb版本太低,会造成调试时指令解析错误)
$xcode-select --install
;打印命令行工具路径
$xcode-select -p
/Library/Developer/CommandLineTools
$cd /Library/Developer/CommandLineTools/usr/bin
$./lldb -v
;查找文件目录
;/var/mobile/Containers/Bundle/Application/
;/var/mobile/Containers/Data/Application/
$find . -name "appname" -print
;导出头文件
class-dump -S -s -H ./WeChat -o ./headers/
;砸壳
Clutch -b com.tencent.xin
https://github.com/KJCracks/Clutch/releases/latest
3、ios设备上安装debugserver,参考:http://bbs.iosre.com/t/debugserver-lldb-gdb/65
4、安装facebook的chisel.py插件,支持更多高级命令
;安装brew
$/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
;更新
$brew update
;安装chisel
$brew install chisel
二、开始调试
1、附加进程调试
(1)附加进程
;*.1234 端口号 -a 附加(appname/进程id)
$debugserver *:1234 -a "SpringBoard"
$debugserver *:1234 -a procID
(2)osx使用lldb连接
$lldb
lldb)platform select remote-ios ;没有sdk效果不好
lldb)po [[UIApp keyWindow] recursiveDescription] ;all view
lldb)hide/show 0xffffffff ;show/hide view
lldb)presponder 0x13fae98a0 ;找到button响应链
lldb)command script import /usr/local/opt/chisel/libexec/fblldb.py ;加载chisel脚本支持bmessage命令
lldb)bmessage -[MyViewController viewDidAppear:]
lldb)process connect connect://(iosip):1234
lldb)image list -o -f ;列出所有加载的模块基地址
lldb)di -s addr; ;-f 反汇编整个函数块 -A thumb/arm模式切换
lldb)b -[T1CommerceOfferHowWorksView setHiddenObserver:] ;下函数名断点
lldb)process continue ;进程继续执行,类似c
lldb)br s -a base+offset ;直接根据IDA中获取的函数偏移下函数断点
lldb)br mod -c '*(int*) ($esp+4) == 10'
lldb)br command add 1 ;给断点1增加命令
command>p i
command>bt
command>DONE
lldb)po $r0 ;ios中特别支持的打印对象数据,特别好用
lldb)x/10xw addr ;查看内存,类型gdb length 10 x hex w word
lldb)process interrupt ;强制进程中断
lldb)register read all ;读取所有的寄存器
lldb)exit ;退出
lldb)memory read --force --outfile ~/data.dump 0x000d6000 0x000d2000+0x00000000000d6000 ;dump内存
lldb)watchpoint set expression -w read -s 1 -- 0xbfffcbd8 ;地址执行断点
lldb)watchpoint set variable -w read myvar ;地址执行断点
lldb)memory find addr addrend -s 'xx' ;内存查找
lldb)memory write -s 4 'addr+4' 'abcdef15' ;内存修改
lldb) im loo -n puts
1 match found in /usr/lib/system/libsystem_c.dylib:
Address: libsystem_c.dylib[0x0000000000011d9a] (libsystem_c.dylib.__TEXT.__text + 69850)
Summary: libsystem_c.dylib`puts
lldb)(lldb) settings set target.run-args 1 2 3
(lldb) run
or:
(lldb) process launch -- <args>
(lldb) process launch --stop-at-entry -- -program_arg value
2、启动进程调试,断在函数入口
(1) ios上使用debugserver启动可执行程序
$debugserver -x backboard *:1234 /var/mobile/Containers/Bundle/Application/3F55C4D3-FC36-4A08-85D4-287BED0D0B06/APP.app/APP
/private/var/mobile/Containers/Data/Application/306D682A-0A72-4765-AA4B-1881001FE306
(2)osx上lldb连接调试
$lldb
lldb)process connect connect://192.168.1.104:1234
lldb)ni ;ni多次直到出现下面
invalid thread
lldb)process interrupt ;此时将进程中断,稍等片刻即可中断
lldb)image list -o -f ;模块都已经加载,此时是进程最开始时候,可以随便下断点
3、有符号支持的调试(因没有sdk有条件的同学可以一试)
;将ios设备上的可执行程序下载到osx可以使用scp吧
$target create -arch armv7 ~/APP
$b -[T1CommerceOfferHowWorksView setHiddenObserver:]
$image lookup --address 0x100123aa3 --verbose
三、问题与总结
1、lldb版本太低造成指令解析与ida中不对称
>卸载xcode,使用xcode-select --install直接安装最新的命令行工具,我安装后的版本是340,之前的330会有这个问题
2、脱壳app
>在终端执行下面这条命令,前提是下载好dumpdecrypted.dylib文件即可
;cycsrit附加要调试的进程
$cycsrit -p pid
;获取进程的临时目录
cy# [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask][0]
#"file:///var/mobile/Containers/Data/Application/D41C4343-63AA-4BFF-904B-2146128611EE/Documents/"
;将dumpdecrypted.dylib拷贝到进程的目录下
$cd /var/mobile/Containers/Data/Application/D41C4343-63AA-4BFF-904B-2146128611EE/Documents/
$cp /var/root/dumpdecrypted.dylib dumpdecrypted.dylib
$DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib /private/var/mobile/Containers/Bundle/Application/1E821425-7743-4D5A-B704-6515694D420A/APP.app/APP
;执行完成后会在目录下生成APP_decrypted
3、怎么知道app的架构?
>
查看架构
otool -f app
查看架构
lipo -info Twitter
4、osx+wireshark抓包
>在终端执行下面这条命令,前提是下载好dumpdecrypted.dylib文件即可
$rvictl -s
$instruments -s devices
$brew install ideviceinstaller
$idevice_id -l
$rvictl -s 07c815ece77928322b48aaadbf3599d521eb5fb1
参与链接:
http://versprite.com/og/ios-reverse-engineering-part-one-configuring-lldb/
https://aigudao.net/archives/244.html
http://casatwy.com/shi-yong-lldbdiao-shi-cheng-xu.html
http://bbs.iosre.com/t/debugserver-lldb-gdb/65
版权声明:本文为CSDN博主「weixin_33898233」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_33898233/article/details/92280130