iOS 逆向 - 使用 dumpdecrypted 給 APP 砸殼
對 Google Sheets 進行砸殼
iDevice: iPod (armv7)
System: iOS 8.1
- 找到 TargetApp 的 Documents 目錄(在設備上操作)
- 將
dumpdecrypted.dylib
拷貝到 TargetApp 的 Docuemnts 目錄下(在 Mac 上操作) - 用
dumpdecrypted.dylib
砸殼(在設備上操作) - 將砸殼后的
TargetApp.decrypted
拷貝回本地 Mac(在 Mac 上操作)
找到 TargetApp 的 Documents 目錄(在設備上操作)
找到你想要砸殼的 app
ps: 需要在 Cydia
中安裝 MobileTerminal 和 Cycript
- 將設備上所有其他的 app 都關掉朵纷,只打開你想要砸殼的 TargetApp(如筆者想要砸殼的 Sheets)贝润。
- 通過
ps
命令查看當前在運行的進程,配合grep
命令找到 TargetApp诉字。可以grep AppName
或者grep Containers
蜻底,后者不用輸入 TargetApp 的名字氮块,畢竟有一些名字不好輸入,筆者用的是后面的方法校哎。 - 使用
cycript
注入 TargetApp两波。可以使用cycript -p AppPID
或cycript -p AppName
兩種方式指定要注入的 TargetApp闷哆。名字可能不是唯一的腰奋,有可能失敗。筆者傾向于用 PID 的方法抱怔。 - 出現(xiàn)
cy#
即說明進入了cycript
的環(huán)境劣坊。
MyiPod:~ root# ps -e | grep Containers
2527 ?? 0:08.64 /var/mobile/Containers/Bundle/Application/5C6D0D63-82B0-442B-BCB3-97B800369FCD/Sheets.app/Sheets
2530 ttys000 0:00.01 grep Containers
MyiPod:~ root# cycript -p 2527
cy#
找到 App 的 Document 所在目錄
使用 OC 的方法 [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomans:NSUserDomainMask][0]
,直接將 TargetApp 的 Document
目錄打印出來屈留。
cy# [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomans:NSUserDomainMask][0]
#"file:///var/mobile/Containers/Data/Application/397CCFE0-69E0-43B1-8894-8F0BB0152656/Documents/"
cy#
ps: Ctrl+D 退出 cycript
將 dumpdecrypted.dylib
拷貝到 TargetApp 的 Docuemnts 目錄下(在 Mac 上操作)
將 dumpdecrypted.dylib
從 Mac 中拷貝到 iPod 的 Documents
目錄局冰。該目錄有讀寫權限,我們需要寫入權限灌危,把砸殼后的數(shù)據(jù)先寫到 Documents
目錄下康二。
likids-MBP:~ Likid$ scp /Develop/iOSRE/dumpdecrypted.dylib root@172.20.10.9:/var/mobile/Containers/Data/Application/397CCFE0-69E0-43B1-8894-8F0BB0152656/Documents/
root@172.20.10.9's password:
dumpdecrypted.dylib 100% 193KB 192.9KB/s 00:00
用 dumpdecrypted.dylib
砸殼(在設備上操作)
在 iPod 中進行砸殼,獲得 Sheets.decrypted
勇蝙。
-
cd
進入 TargetApp 的 Documents 目錄 - 查看
dumpdecrypted.dylib
是否已經(jīng)拷貝到 Documents 下 - 將
dumpdecrypted.dylib
注入 TargetApp沫勿,會自動進行砸殼,輸出砸殼后的 appTargetApp.decrypted
,如Sheets.decrypted
MyiPod:~ root# cd /var/mobile/Containers/Data/Application/397CCFE0-69E0-43B1-8894-8F0BB0152656/Documents/
MyiPod:/var/mobile/Containers/Data/Application/397CCFE0-69E0-43B1-8894-8F0BB0152656/Documents root# ls
112161084947550660392/ drivekit/ dumpdecrypted.dylib*
MyiPod:/var/mobile/Containers/Data/Application/397CCFE0-69E0-43B1-8894-8F0BB0152656/Documents root# DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib /var/mobile/Containers/Bundle/Application/5C6D0D63-82B0-442B-BCB3-97B800369FCD/Sheets.app/Sheets
mach-o decryption dumper
DISCLAIMER: This tool is only meant for security research purposes, not for application crackers.
[+] detected 32bit ARM binary in memory.
[+] offset to cryptid found: @0x7fa08(from 0x7f000) = a08
[+] Found encrypted data at address 00004000 of length 49872896 bytes - type 1.
[+] Opening /private/var/mobile/Containers/Bundle/Application/5C6D0D63-82B0-442B-BCB3-97B800369FCD/Sheets.app/Sheets for reading.
[+] Reading header
[+] Detecting header type
[+] Executable is a FAT image - searching for right architecture
[+] Correct arch is at offset 16384 in the file
[+] Opening Sheets.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 4a08
[+] Closing original file
[+] Closing dump file
MyiPod:/var/mobile/Containers/Data/Application/397CCFE0-69E0-43B1-8894-8F0BB0152656/Documents root# ls
112161084947550660392/ Sheets.decrypted drivekit/ dumpdecrypted.dylib*
MyiPod:/var/mobile/Containers/Data/Application/397CCFE0-69E0-43B1-8894-8F0BB0152656/Documents root#
MyiPod:/var/mobile/Containers/Data/Application/397CCFE0-69E0-43B1-8894-8F0BB0152656/Documents root# exit
將砸殼后的 TargetApp.decrypted
拷貝回本地 Mac(在 Mac 上操作)
將 Sheets.decrypted
拷貝回本地 Mac产雹,查看是否砸殼成功烫罩,cryptid
為 0 則表示砸殼成功,該架構沒有加密
likids-MBP:~ Likid$ scp root@172.20.10.9:/var/mobile/Containers/Data/Application/397CCFE0-69E0-43B1-8894-8F0BB0152656/Documents/Sheets.decrypted /Develop/iOSRE/Sheets/
root@172.20.10.9's password:
Sheets.decrypted 100% 141MB 1.8MB/s 01:19
likids-MBP:~ Likid$ cd /Develop/iOSRE/Sheets/
likids-MBP:Sheets Likid$ ls
Sheets.decrypted
likids-MBP:Sheets Likid$ file Sheets.decrypted
Sheets.decrypted: Mach-O universal binary with 2 architectures: [arm_v7: Mach-O executable arm_v7] [arm64]
Sheets.decrypted (for architecture armv7): Mach-O executable arm_v7
Sheets.decrypted (for architecture arm64): Mach-O 64-bit executable arm64
likids-MBP:Sheets Likid$ otool -l Sheets.decrypted | grep crypt
Sheets.decrypted (architecture armv7):
cryptoff 16384
cryptsize 49872896
cryptid 0
Sheets.decrypted (architecture arm64):
cryptoff 16384
cryptsize 53395456
cryptid 1
ref: 《iOS應用逆向工程(第2版)》