1 class dumphtml
class dump 是一個用於檢查保存在 Mach-O 文件中的 objective-c 運行時信息的工具,攻防中最經常使用、實用的命令行工具。java
1.1 class dump 好玩在哪?
class dump 絕對能夠知足你的好奇心。你能夠經過 class dump :ios
- 查看閉源的應用、frameworks、bundles。
- 對比一個 APP 不一樣版本之間的接口變化。
- 對一些私有 frameworks 作些有趣的試驗。
1.2 Download
當前版本: 3.5 (64 bit Intel)
須要 Mac OS X 10.8 或更高版本git
class-dump-3.5.dmg
class-dump-3.5.tar.gz
class-dump-3.5.tar.bz2github
1.3 Use
下載好後,雙擊dmg文件,將其中的 class-dump 文件放到/usr/local/sbin 目錄下,而後就能夠在命令行中使用了。objective-c
官方用法指南:express
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
class-dump 3.5 (64 bit)
Usage: class-dump [options]
where options are:
-a show instance variable offsets
-A show implementation addresses
--arch choose a specific architecture from a universal binary (ppc, ppc64, i386, x86_64)
-C only display classes matching regular expression
-f find string in method name
-H generate header files in current directory, or directory specified with -o
-I sort classes, categories, and protocols by inheritance (overrides -s)
-o
output directory used for -H
-r recursively expand frameworks and fixed VM shared libraries
-s sort classes and categories by name
-S sort methods by name
-t suppress header in output, for testing
--list-arches list the arches in the file, then exit
--sdk-ios specify iOS SDK version (will look in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
--sdk-mac specify Mac OS X version (will look in /Developer/SDKs/MacOSX.sdk
--sdk-root specify the full SDK root path (or use --sdk-ios/--sdk-mac for a shortcut)
|
簡單的舉例:微信
1
|
class-dump -H /Applications/Calculator.app -o ~/Desktop/dump/Calculate-dump
|
/Applications/Calculator.app
是 Mac 上計算器應用的路徑。~/Desktop/dump/Calculate-dump
是指定的存放 dump 出來頭文件的文件夾路徑。架構
執行完成後能夠看到指定的保存目錄下已經有 dump 出來的頭文件了:app
打開一個 .h
文件能夠看到相應內容:
2 Dumpdecrypted
class dump 雖然能幫你解析出一個 app 的頭文件,可是對於 App Store 下載的 App 都是經過蘋果的一層簽名加密,一般咱們成爲『加殼』。對於已經加殼的 APP,解析後的效果就和加了代碼混淆相似。
好比直接去 dump 微信,出來的結果大概是這樣:
2.1 Download
2.2 Install
Dumpdecrypted 比另外一個砸殼工具 Clutch 要難用的多。但因爲 Clutch 沒法砸開含有兼容 WatchOs
2 的 App,因此只能使用 Dumpdecrypted。
下載後打開 Makefile
文件,注意第三行:
1
|
$ SDK=`xcrun --sdk iphoneos --show-sdk-path`
|
這裏填寫的 SDK 必須與你越獄的 iPhone 系統等級一致,你能夠這樣查看你 MAC 的 SDK :
1
|
$ xcrun --sdk iphoneos --show-sdk-path
|
輸出:
1
|
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk
|
而個人手機是 7.0 的,因此只能去這裏下載對應的 SDK。
Makefile 全部須要填寫的填好後:
1
2
|
$ cd dumpdecrypted
$ make
|
在當前目錄下生成 dumpdecrypted.dylib 文件。
2.3 Use
將 dumpdecrypted.dylib
放到須要砸殼 app 的 Documents 下。
查找微信的 Documents:
1
|
$ find / -name WeChat.app
|
獲得路徑:
1
|
/private/var/mobile/Applications/3DE3657E-0F69-45FF-928B-3DD5CD7A59FD/WeChat.app
|
scp 傳輸:
1
|
$ scp ~/Desktop/dump/dumpdecrypted/dumpdecrypted_7.dylib root@172.16.212.217:/private/var/mobile/Applications/3DE3657E-0F69-45FF-928B-3DD5CD7A59FD/Documents
|
砸殼:
1
2
|
$ cd /private/var/mobile/Applications/3DE3657E-0F69-45FF-928B-3DD5CD7A59FD/Documents
$ DYLD_INSERT_LIBRARIES=dumpdecrypted_7.dylib /private/var/mobile/Applications/3DE3657E-0F69-45FF-928B-3DD5CD7A59FD/WeChat.app/WeChat
|
注意
DYLD_INSERT_LIBRARIES=
後填寫的是你剛剛傳輸的 .dylib 文件名,個人是 dumpdecrypted_7.dylib
砸殼成功:
1
2
3
4
5
6
7
|
[+] detected 32bit ARM binary in memory.
[+] offset to cryptid found: @0xfea4c(from 0xfe000) = a4c
[+] Found encrypted data at address 00004000 of length 42237952 bytes - type 1.[+] Opening /private/var/mobile/Applications/3DE3657E-0F69-45FF-928B-3DD5CD7A59FD/WeChat.app/WeChat 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 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 4a4c
[+] Closing original file[+] Closing dump file
|
ls 查看 Documents 中文件多了一個 WeChat.decrypted
,這就是砸殼事後的文件,scp出來:
1
|
$ scp WeChat.decrypted zhoulingyu@172.16.211.181:/Users/zhoulingyu/Desktop/dump/Wechat
|
3 class dump 砸殼後的文件
上一步咱們獲得了 WeChat.decrypted
,如今能夠對其進行 dump:
1
|
class-dump --arch armv7 WeChat.decrypted -H -o /Users/zhoulingyu/Desktop/dump/Wechat/Wechat-decrypted-dump
|
–arch armv7 是指定架構,dumpdecrypted 只會砸你手機處理器對應的那個殼,fat binary 的其它部分仍然是有殼的,而 class-dump 的默認目標又不是被砸殼的那個部分,若是不指定架構只能導出 CDStructures.h 一個文件
如今就能夠看到 dump 後是明文的了:
4 Learn More
當你能看到 .h 文件時候,意味着你知道了這個應用程序的各類接口,除了學習別人的優雅代碼以外,顯然也也能夠作一些更有意思的事情,經過一些猜測和試驗,咱們能夠去嘗試作一個微信的插件。
下一次iOS攻防將會介紹動態庫的注入和微信插件的製做~
若是您感興趣~請點擊下方打賞支持萌妹子的原創喲~
有什麼問題均可以在博文後面留言,或者微博上私信我,或者郵件我coderfish@163.com。
博主主要寫 java 和 iOS 的。
但願你們一塊兒進步。
CSDN: CSDN博客地址
個人微博:小魚周凌宇