ios逆向小試牛刀之操做手記

1、環境準備html

    一、vmware中安裝osx系統,參照連接:http://jingyan.baidu.com/article/ff411625b9011212e48237b4.htmlios

    二、osx上安裝lldb命令行版(安裝xcode6.4後lldb版本過低,會形成調試時指令解析錯誤)git

$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

   三、ios設備上安裝debugserver,參考:http://bbs.iosre.com/t/debugserver-lldb-gdb/65github

   四、安裝facebook的chisel.py插件,支持更多高級命令express

;安裝brew
$/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
;更新
$brew update

;安裝chisel
$brew install chisel

2、開始調試xcode

    一、附加進程調試ruby

        (1)附加進程架構

;*.1234 端口號 -a 附加(appname/進程id)
$debugserver *:1234 -a "SpringBoard" 
$debugserver *:1234 -a procID

        (2)osx使用lldb鏈接app

$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

    二、啓動進程調試,斷在函數入口curl

         (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  ;模塊都已經加載,此時是進程最開始時候,能夠隨便下斷點

    三、有符號支持的調試(因沒有sdk有條件的同窗能夠一試)

;將ios設備上的可執行程序下載到osx可使用scp吧
$target create -arch armv7 ~/APP
$b -[T1CommerceOfferHowWorksView setHiddenObserver:]
$image lookup --address 0x100123aa3 --verbose

3、問題與總結

一、lldb版本過低形成指令解析與ida中不對稱

>卸載xcode,使用xcode-select --install直接安裝最新的命令行工具,我安裝後的版本是340,以前的330會有這個問題

二、脫殼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

 

三、怎麼知道app的架構?

>

查看架構

otool -f app

查看架構

lipo -info Twitter

四、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

相關文章
相關標籤/搜索