逆向工具集的安裝和使用
iOS 逆向工程的工具分類
檢查工具
如:Reveal(界面分析工具)、tcpdump(抓包工具)等反編譯工具(反匯編工具-分析二進制文件并得到一些信息)
如:IDA、Hopper Disassembler、class-dump、yololib等調試工具
如:lldb、Cycript等開發工具
如:Xcode、theos等
class-dump介紹
class-dump可以將Mach-O文件中的Objective-C運行時的聲明信息導出,即編寫OC代碼時的.h文件。class-dump只能導出未加密的app頭文件,class-dump是對"otool -ov"信息的翻譯.以一種我們熟悉的易讀的方式呈現。
- otool工具簡介
otool(object file displaying tool):目標文件的展示工具。可以用來發現應用中使用到了那些系統庫,調用了那些系統方法。使用了庫中那些對象及屬性,它是Xcode自帶的常用工具。
終端輸入otool會得到如下使用命令:
```
-f print the fat headers
-a print the archive header
-h print the mach header
-l print the load commands
-L print shared libraries used
-D print shared library id name
-t print the text section (disassemble with -v)
-p <routine name> start dissassemble from routine name
-s <segname> <sectname> print contents of section
-d print the data section
-o print the Objective-C segment
-r print the relocation entries
-S print the table of contents of a library
-T print the table of contents of a dynamic shared library
-M print the module table of a dynamic shared library
-R print the reference table of a dynamic shared library
-I print the indirect symbol table
-H print the two-level hints table
-G print the data in code table
-v print verbosely (symbolically) when possible
-V print disassembled operands symbolically
-c print argument strings of a core file
-X print no leading addresses or headers
-m don't use archive(member) syntax
-B force Thumb disassembly (ARM objects only)
-q use llvm's disassembler (the default)
-Q use otool(1)'s disassembler
-mcpu=arg use `arg' as the cpu for disassembly
-j print opcode bytes
-P print the info plist section as strings
-C print linker optimization hints
--version print the version of /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool
```
-
otool簡單使用
== 進入APP包文件目錄/../xxoo.app
$cd ../xx00.app
== 依賴庫的查詢
$otool -L 依賴庫名稱
== 是否加殼
$otool -l WeChat.app/WeChat | grep -B 2 crypt
1代表加密了,0代表被解密了: cmd LC_ENCRYPTION_INFO cmdsize 20 cryptoff 16384 cryptsize 47841280 cryptid 1 -- cmd LC_ENCRYPTION_INFO_64 cmdsize 24 cryptoff 16384 cryptsize 51200000 cryptid 1
classdump的使用
1、點擊 class-dump下載dmg安裝包
2、將class-dump執行文件拖入到/usr/local/bin目錄下
3、終端輸入class-dump
查看版本號檢查是否安裝成功
4、class-dump的使用命令:
$class-dump -s -S -H /../xx00.app -o /.../heads
5、框架一樣可以導出:
$class-dump -s -S -H /System/Library/Frameworks/AppKit.framework -o /.../heads
解釋:
/../xx00.app 是app的路徑
/../heads 是存放dump出來頭文件的文件夾路徑
dumpdecrypted砸殼工具
打開兩個終端窗口:
打開兩個終端窗口:
打開兩個終端窗口:
== 一個ssh登錄iPhone后,對iPhone進行操作
== 一個操作本地電腦
下載dumpdecrypted最新源碼
終端命令:
git clone https://github.com/stefanesser/dumpdecrypted.git-
make命令編譯生成dumpdecrypted.dylib動態庫文件(砸殼的錘子)
- cd 到下載的工程dumpdecrypted目錄下
- 輸入終端命令即可:
$make
使用ssh登錄越獄的iPhone設備拿到Data和Bundle兩個文件路徑
==bundle文件路徑 (我們需要砸殼的app路徑)
方式一:知道app名稱情況
$ps -e | grep WeChat
1787 ?? 0:05.98 /var/containers/Bundle/Application/D28A1C43-2F50-435D-AD0E-DDB14992D63B/WeChat.app/WeChat
1794 ttys001 0:00.01 grep WeChat
方式二:不知道APP名稱,只打開砸殼app
$ps -e 找到含bundle的路徑,只會存在一個
/var/containers/Bundle/Application/D28A1C43-2F50-435D-AD0E-DDB14992D63B/WeChat.app/WeChat
==Data文件路徑 (放錘子的地方)
$ cycript -p WeChat
cy# directory = NSHomeDirectory()
@"/var/mobile/Containers/Data/Application/E9232D81-80E3-4684-BB0E-FC3643703947"
/var/mobile/Containers/Data/Application/E9232D81-80E3-4684-BB0E-FC3643703947
退出:control+D
- 拷貝dumpdecrypted.dylib到iPhone
- 打開本地電腦窗口
- 復制剛剛拿到的Data文件路徑,我們要把電腦上生成的dumpdecrypted.dylib放在它的Documents文件目錄下
- 使用ssh傳輸文件
$scp /.../dumpdecrypted/dumpdecrypted.dylib root@192.168.1.2:/var/mobile/Containers/Data/Application/E9232D81-80E3-4684-BB0E-FC3643703947/Documents
為什么要把dumpdecrypted.dylib拷貝到Documents目錄下操作?
StoreApp對沙盒以外的絕大多數目錄是沒有寫權限。dumpdecrypted.dylib要寫一個decrypted文件,但它是運行在StoreApp中的,與StoreApp的權限相同,那么它的寫操作就必須發生在StoreApp擁有寫權限的路徑下才能成功。StoreApp一定是能寫入其Documents目錄的,因此我們在Documents目錄下使用dumpdecrypted.dylib時,保證它能在當前目錄下寫一個decrypted文件,這就是把dumpdecrypted.dylib拷貝到Documents目錄下操作的原因。
-
砸殼
- 打開ssh連接iPhone的終端窗口
- cd到Data文件路徑的Document目錄下也就是我們放錘子的地方
- 開砸
DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib /var/containers/Bundle/Application/D28A1C43-2F50-435D-AD0E-DDB14992D63B/WeChat.app/WeChat 解釋: 注入我們的動態庫文件 DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib APP包路徑 /var/containers/Bundle/Application/D28A1C43-2F50-435D-AD0E-DDB14992D63B/WeChat.app/WeChat
-
砸殼錯誤:
dyld: could not load inserted library 'dumpdecrypted.dylib' because no suitable image found. Did find: dumpdecrypted.dylib: required code signature missing for 'dumpdecrypted.dylib' Abort trap: 6 重簽名再次上傳文件即可解決: ## 列出可簽名證書 security find-identity -v -p codesigning ## 為dumpecrypted.dylib簽名 codesign --force --verify --verbose --sign "iPhone Developer: xxx xxxx (xxxxxxxxxx)" dumpdecrypted.dylib
-
微信砸殼后結果
mach-o decryption dumper DISCLAIMER: This tool is only meant for security research purposes, not for application crackers. [+] detected 64bit ARM binary in memory. [-] This mach-o file is not encrypted. Nothing was decrypted.
尷尬了,沒有破譯文件,沒有生成decrypted文件,可能微信做了處理,我們換成簡書app再次操作一次,成功拿到破譯文件
-
簡書砸殼成功
-
拷貝生成的decryption文件到電腦,再使用class-dump導出頭文件
- 回到電腦終端窗口
- 傳輸獲取的破譯文件Hugo.decrypted,去掉decrypted就是我們app的二進制文件
拷貝命令: scp -r root@192.168.1.2:/var/mobile/Containers/Data/Application/E5A9CC73-1EF7-42F7-95BB-D154DA83E1BE/Documents/Hugo.decrypted /Users/Yohann/Desktop/Hugo
- 使用class-dump導出頭文件
class-dump -S -s -H /Users/Yohann/Desktop/Hugo/Hugo.decrypted -o /Users/Yohann/Desktop/Header dump如果沒有出現東西,可以確定下當前的處理器,加相應參數 如: class-dump --arch armv7 -S -s -H WeChat.decrypted -o Headers 其他型號使用相對應的 4(armv7),4s(armv7),5(armv7),5s(arm64),6(arm64),6s(arm64)
- 又尷尬了導出頭文件報錯,再試一次換為自己公司APP成功
Error: Cannot find offset for address 0x98000000010080d2 in stringAtAddress:
網上搜索錯誤信息,得出結論:
1、class-dump是利用Object-C語言的runtime特性,提取頭文件,使用swift或其它語言混編無法提取頭信息
2、使用dumpdecrypted.dylib得不到decrypted破解文件,
(1)可能是app未加殼,
(2)無法破解,例如同樣的操作對微信無效。
(3)探索中。。。有見解望留言
本次砸殼iOS10.0.2