iOS逆向之dumpdecrypt破壳

1、前言

我们从App Store上下载的app是被苹果加密过的,从其他渠道下载一般没有加密,可执行文件被套上了一层保护壳,而class-dump是无法作用在加密过的App上的。在这种情况下,要想获取头文件,需要先解密App的可执行文件,俗称“砸壳”,这里我们需要使用到的砸壳工具是dumpdecrypted。

2、获取dumpdecrypted

1)打开github官网,搜索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命令执行后会生成一个dumpdecrypted.dylib文件,这就是砸壳需要用到的榔头。这个文件生成一次就可以了,以后可以重复使用,下次破壳就不需要再重新编译了。

4、定位待砸壳TargetApp的可执行文件

首先准备一个越狱的iphone手机,我们关掉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/下,其中可执行文件位于/var/mobile/Containers/Bundle/Applications/X下,因为我们只打开了我们需要砸壳的TargetApp,那么进程中唯一的一个“/var/mobile/Applications/”路径就是我们需要路径,也就是TargetApp可执行文件的全路径。

5、用Cycript找出TargetApp的Document目录路径

StoreApp的Document目录位于/var/mobile/Containers/Data/Applications/Y下,因为X与Y不同,利用ps是没办法区别这两个目录的路径,那么我们借助强大的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

当前目录下会生成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文件导出到OSX设备上备用。

以上就是砸壳的全部过程了,看起来很简单,但是也是经过了一翻折腾的。

备注问题:为什么要把dumpdecrypted.dylib文件拷贝到Document目录下?

StoreApp对沙盒以外的绝大多数目录是没有写权限的。dumpdecrypted.dylib要写一个decrypted文件,但它是运行在StoreApp中的,与StoreApp的权限相同,那么它的写操作就必须发生在StoreApp拥有写权限的路径下才能成功。StoreApp一定是能写入其Document目录的,因此在Document目录下使用dumpdecrypted.dylib时,保证它能在当前目录下写一个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

之后重新上传砸壳。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,509评论 6 504
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,806评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,875评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,441评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,488评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,365评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,190评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,062评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,500评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,706评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,834评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,559评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,167评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,779评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,912评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,958评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,779评论 2 354

推荐阅读更多精彩内容