iOS逆向之dumpdecrypt破殼

1、前言

我們從App Store上下載的app是被蘋果加密過的,從其他渠道下載一般沒有加密,可執(zhí)行文件被套上了一層保護殼,而class-dump是無法作用在加密過的App上的。在這種情況下,要想獲取頭文件,需要先解密App的可執(zhí)行文件,俗稱“砸殼”,這里我們需要使用到的砸殼工具是dumpdecrypted。

2、獲取dumpdecrypted

1)打開github官網(wǎng),搜索dumpdecrypted,第一個就是。

2)使用命令:

git clone git://github.com/stefanesser/dumpdecrypted/

3、編譯dumpdecrypted.dylib

wifi:~ clf$ cd /Users/ppd/Documents/dumpdecrypted-master 
wifi:dumpdecrypted-master clf$ make

`xcrun --sdk iphoneos --find gcc` -Os  -Wimplicit -isysroot `xcrun --sdk iphoneos --show-sdk-path` -F`xcrun --sdk iphoneos --show-sdk-path`/System/Library/Frameworks -F`xcrun --sdk iphoneos --show-sdk-path`/System/Library/PrivateFrameworks -arch armv7 -arch armv7s -arch arm64 -c -o dumpdecrypted.o dumpdecrypted.c 
`xcrun --sdk iphoneos --find gcc` -Os  -Wimplicit -isysroot `xcrun --sdk iphoneos --show-sdk-path` -F`xcrun --sdk iphoneos --show-sdk-path`/System/Library/Frameworks -F`xcrun --sdk iphoneos --show-sdk-path`/System/Library/PrivateFrameworks -arch armv7 -arch armv7s -arch arm64 -dynamiclib -o dumpdecrypted.dylib dumpdecrypted.o
ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk/System/Library/PrivateFrameworks'
ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk/System/Library/PrivateFrameworks'
ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk/System/Library/PrivateFrameworks'

make命令執(zhí)行后會生成一個dumpdecrypted.dylib文件,這就是砸殼需要用到的榔頭。這個文件生成一次就可以了,以后可以重復(fù)使用,下次破殼就不需要再重新編譯了。

4、定位待砸殼TargetApp的可執(zhí)行文件

首先準(zhǔn)備一個越獄的iphone手機,我們關(guān)掉iphone上的所有App,打開我們需要砸殼的TargetApp(這里我用微信來測試),接著ssh連接到iphone上,用ps指令打印所有的進程。

連接iphone

wifi:~ clf$ ssh root@192.168.2.14

root@192.168.2.14's password: 

打印進程

iPhone:~ root# ps -e

  PID TTY           TIME CMD
1 ??         0:04.73 /sbin/launchd
17 ??         0:04.72 /usr/sbin/notifyd
20 ??         0:42.42 /usr/libexec/UserEventAgent (System)
21 ??         0:06.38 /usr/libexec/pphelper/PPHelperLaunchd
22 ??         0:00.28 /usr/libexec/aosnotifyd
23 ??         0:00.36 /usr/sbin/BTServer
24 ??         0:49.21 /System/Library/Frameworks/CoreTelephony.framework/Sup
29 ??         2:10.53 /System/Library/CoreServices/SpringBoard.app/SpringBoa
30 ??         0:32.47 /System/Library/PrivateFrameworks/AggregateDictionary.
31 ??         0:00.15 /System/Library/PrivateFrameworks/AssistantServices.fr
35 ??         9:22.20 /usr/libexec/backboardd
37 ??         0:07.09 /usr/libexec/configd
38 ??         0:00.03 /System/Library/CoreServices/AppleIDAuthAgent
40 ??         0:00.81 /usr/sbin/fairplayd.H2

...
 318 ??         0:00.25 sshd: root@ttys000 
457 ??         0:02.12 /System/Library/CoreServices/AssistiveTouch.app/assistivetouchd
458 ??         0:09.97 /System/Library/CoreServices/SpringBoard.app/SpringBoard
459 ??         0:31.09 /usr/libexec/backboardd
476 ??         0:02.61 /Applications/MobileMail.app/MobileMail
492 ??         0:00.05 /System/Library/Frameworks/UIKit.framework/Support/pasteboardd
495 ??         0:00.99 /var/mobile/Applications/F9BB912B-E6C3-4266-AE06-4AF1B3B969D5/WeChat.app/WeChat
319 ttys000    0:00.08 -sh
496 ttys000    0:00.01 ps -e

StoreApp全部位于/var/mobile/Containers/下,其中可執(zhí)行文件位于/var/mobile/Containers/Bundle/Applications/X下,因為我們只打開了我們需要砸殼的TargetApp,那么進程中唯一的一個“/var/mobile/Applications/”路徑就是我們需要路徑,也就是TargetApp可執(zhí)行文件的全路徑。

5、用Cycript找出TargetApp的Document目錄路徑

StoreApp的Document目錄位于/var/mobile/Containers/Data/Applications/Y下,因為X與Y不同,利用ps是沒辦法區(qū)別這兩個目錄的路徑,那么我們借助強大的Cycript工具,讓App告訴我們Document的路徑。如下:

使用命令:cycript -p TargetApp

iPhone:~ root# cycript -p WeChat

cy# [[NSFileManager defaultManager]URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask][0]

#"file:///var/mobile/Applications/F9BB912B-E6C3-4266-AE06-4AF1B3B969D5/Documents/"

上面就是Document的路徑了。

6、將dumpdecrypted.dylib拷貝到Document目錄下

wifi:~ clf$ scp /Users/ppd/Documents/dumpdecrypted-master/dumpdecrypted.dylib root@192.168.2.14:/var/mobile/Applications/F9BB912B-E6C3-4266-AE06-4AF1B3B969D5/Documents/


root@192.168.2.14's password: 
dumpdecrypted.dylib                           100%  193KB   2.0MB/s   00:00

這里采用的是scp方式。

7、開始砸殼

dumpdecrypted.dylib的用法:
DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib /path/to/executable
進入到document文件下:

iPhone:/var/mobile/Applications/F9BB912B-E6C3-4266-AE06-4AF1B3B969D5/Documents root# DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib  /var/mobile/Applications/F9BB912B-E6C3-4266-AE06-4AF1B3B969D5/WeChat.app/WeChat

mach-o decryption dumper

DISCLAIMER: This tool is only meant for security research purposes, not for application crackers.

[+] detected 64bit ARM binary in memory.
[+] offset to cryptid found: @0x100088ca8(from 0x100088000) = ca8
[+] Found encrypted data at address 00004000 of length 56770560 bytes - type 1.
[+] Opening /private/var/mobile/Applications/F9BB912B-E6C3-4266-AE06-4AF1B3B969D5/WeChat.app/WeChat for reading.
[+] Reading header
[+] Detecting header type
[+] Executable is a FAT image - searching for right architecture
[+] Correct arch is at offset 62078976 in the file
[+] Opening WeChat.decrypted for writing.
[+] Copying the not encrypted start of the file
[+] Dumping the decrypted data into the file
[+] Copying the not encrypted remainder of the file
[+] Setting the LC_ENCRYPTION_INFO->cryptid to 0 at offset 3b34ca8
[+] Closing original file
[+] Closing dump file

當(dāng)前目錄下會生成WeChat.decrypted,即砸殼后的文件,使用ls命令查看,如下:

iPhone:/var/mobile/Applications/F9BB912B-E6C3-4266-AE06-4AF1B3B969D5/Documents root# ls

00000000000000000000000000000000  MMResourceMgr  MemoryStat    WeChat.decrypted  dumpdecrypted.dylib
LocalInfo.lst             MMappedKV  SafeMode.dat  db.globalconfig   heavy_user_id_mapping.dat

利用itools將WeChat.decrypted文件導(dǎo)出到OSX設(shè)備上備用。

以上就是砸殼的全部過程了,看起來很簡單,但是也是經(jīng)過了一翻折騰的。

備注問題:為什么要把dumpdecrypted.dylib文件拷貝到Document目錄下?

StoreApp對沙盒以外的絕大多數(shù)目錄是沒有寫權(quán)限的。dumpdecrypted.dylib要寫一個decrypted文件,但它是運行在StoreApp中的,與StoreApp的權(quán)限相同,那么它的寫操作就必須發(fā)生在StoreApp擁有寫權(quán)限的路徑下才能成功。StoreApp一定是能寫入其Document目錄的,因此在Document目錄下使用dumpdecrypted.dylib時,保證它能在當(dāng)前目錄下寫一個decrypted文件。

備注

查看是否加殼(cryptid 1為加殼)
wifi:Documents clf$ otool -l WeChat.decrypted | grep crypt
cryptid 1
  cryptid 0
wifi:Documents clf$ otool -l WeChat.decrypted | grep crypt
WeChat.decrypted (architecture armv7):
 cryptoff 16384
cryptsize 52756480
  cryptid 1
WeChat.decrypted (architecture arm64):
 cryptoff 16384
cryptsize 56770560
  cryptid 0
ios10.1.1遇到的問題:
 iPhone:/var/mobile/Containers/Data/Application/914E1ECE-D68A-47D1-83CE-3C848DDA0FC9/Documents root# DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib /var/containers/Bundle/Application/FB01F34B-E7EB-40E9-8F33-23A008F3DD60/XXX.app/XXX
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

之后重新上傳砸殼。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容