iOS 逆向 - 使用 dumpdecrypted 給 APP 砸殼

iOS 逆向 - 使用 dumpdecrypted 給 APP 砸殼

對 Google Sheets 進行砸殼

iDevice: iPod (armv7)
System: iOS 8.1

  1. 找到 TargetApp 的 Documents 目錄(在設備上操作)
  2. dumpdecrypted.dylib 拷貝到 TargetApp 的 Docuemnts 目錄下(在 Mac 上操作)
  3. dumpdecrypted.dylib 砸殼(在設備上操作)
  4. 將砸殼后的 TargetApp.decrypted 拷貝回本地 Mac(在 Mac 上操作)

找到 TargetApp 的 Documents 目錄(在設備上操作)

找到你想要砸殼的 app

ps: 需要在 Cydia 中安裝 MobileTerminal 和 Cycript

  1. 將設備上所有其他的 app 都關掉,只打開你想要砸殼的 TargetApp(如筆者想要砸殼的 Sheets)。
  2. 通過 ps 命令查看當前在運行的進程,配合 grep 命令找到 TargetApp。可以 grep AppName 或者 grep Containers,后者不用輸入 TargetApp 的名字,畢竟有一些名字不好輸入,筆者用的是后面的方法。
  3. 使用 cycript 注入 TargetApp。可以使用 cycript -p AppPIDcycript -p AppName 兩種方式指定要注入的 TargetApp。名字可能不是唯一的,有可能失敗。筆者傾向于用 PID 的方法。
  4. 出現 cy# 即說明進入了 cycript 的環境。
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 目錄。該目錄有讀寫權限,我們需要寫入權限,把砸殼后的數據先寫到 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

  1. cd 進入 TargetApp 的 Documents 目錄
  2. 查看 dumpdecrypted.dylib 是否已經拷貝到 Documents 下
  3. dumpdecrypted.dylib 注入 TargetApp,會自動進行砸殼,輸出砸殼后的 app TargetApp.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版)》

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容