iOS 安全攻防之构建暴力破解工具

2017/07/06 blog

我们知道,任何的加密都可以使用暴力破解来解密,前提是你的电脑运算速度足够快,时间足够长(这只是理论值,实际上现在是做不到的)。即使像iPhone这样,文件系统中所有文件都是加密的。也总是有漏洞,攻击者总能找到办法,据说现在iOS11 都已经被越狱了。

Sogeti数据保护工具

Sogeti 是一家拥有2万人的强大的公司,提供专业的技术服务,尤其是提供软件管理、基础设置管理,高科技工程和测试服务。Sogeti 公司的Jean-Bapties 和Jean-Sigwald 开发了一套iOS 数据保护工具,用于获取设备秘钥并解密iOS 文件系统的分区。他们这个研究工作通过Google Code 开源。地址是:https://code.google.com/archive/p/iphone-dataprotection.Sogeti 工具套件包括一组Python脚本,任何人都可以用来了解iOS 的加密是如何工作的,甚至可以修改解密工具的代码。

安装数据保护工具

要安装Sogeti 工具软件,首先要安装Mercurial—-一个跨平台的源码版本控制工具,与git、subversion、CVS 类似,Mercurial 也是Google code 源码所使用的一种版本控制器,从:https://www.mercurial-scm.org/downloads 下载对应的版本,然后安装。

安装好之后,检查是否安装正确,打开终端,输入hg 就应该可以看到很多帮助信息:

$ hg
Mercurial Distributed SCM

basic commands:

 add           add the specified files on the next commit
 annotate      show changeset information by line for each file
 clone         make a copy of an existing repository
 commit        commit the specified files or all outstanding changes
 diff          diff repository (or selected files)
 export        dump the header and diffs for one or more changesets
 forget        forget the specified files on the next commit
 init          create a new repository in the given directory
 log           show revision history of entire repository or files
 merge         merge another revision into working directory
 pull          pull changes from the specified source
 push          push changes to the specified destination
 remove        remove the specified files on the next commit
 serve         start stand-alone webserver
 status        show changed files in the working directory
 summary       summarize working directory state
 update        update working directory (or switch revisions)

(use 'hg help' for the full list of commands or 'hg -v' for details)

然后下载Sogeti源码进行编译:

$ hg clone https://code.google.com/p/iphone-dataprotection/
abort: error: No route to host

可以看到我这个不行,那就换个方式:

$git clone https://github.com/dinosec/iphone-dataprotection.git
构建暴力破解器

下载下来之后,在当前会有个iphone-dataprotection 目录,该目录包含了完整的项目源码,进入ramdisk_tools 子目录,其中就是我们要构建的暴力破解器的源码,不过要先make, make 完之后,会产生一个bruteforce 的工具,这个工具会执行对4位数字密码设备PIN码的暴力破解,即使使用的设备是复杂的密码而无法破解时,这个工具也能取回EMF! 和DKey 加密秘钥,可以用于解密文件系统中未受保护的文件。

在构建前,先要修改Makefile 文件:

SDKVER?=10.3
ARCH?=arm64
MINIOS=8.0

将SDK版本、架构、最小支持版本,这里面下载下来的默认最小支持版本是4.0 这个一定要更改过来,否则编译不过。SDK版本改成你的SDK版本。

在构建的过程中有可能会遇到很多麻烦:

$ make
abort: no repository found in '/Users/heyonly/Learning/iphone-dataprotection-master/ramdisk_tools' (.hg not found)!
clang -arch armv7 -Wall -Wno-pointer-sign -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk/ -DHGVERSION="\"unknown\"" -O3 -I. -framework CoreFoundation -framework IOKit -framework Security -miphoneos-version-min=8.0 -o restored_external restored_external.c device_info.c remote_functions.c plist_server.c AppleKeyStore.c AppleEffaceableStorage.c IOKit.c IOAESAccelerator.c util.c registry.c AppleKeyStore_kdf.c bsdcrypto/pbkdf2.c bsdcrypto/sha1.c bsdcrypto/rijndael.c bsdcrypto/key_wrap.c ioflash/ioflash.c ioflash/IOFlashPartitionScheme.c kernel_patcher.c
In file included from restored_external.c:20:
./headers/IOCFPlugIn.h:37:10: fatal error: 'IOKit/IOKitLib.h' file not found
#include <IOKit/IOKitLib.h>
         ^~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [restored_external] Error 1

这是缺少IOKIT框架支持,IOKit.framework 在网上有很多,可以自己下载下来,将headers 目录拷贝到ramdisk_tools 目录中,然后:

#include "headers/IOTypes.h"
#include "headers/IOReturn.h"

这样改过之后:

$ make
abort: no repository found in '/Users/heyonly/Learning/iphone-dataprotection-master/ramdisk_tools' (.hg not found)!
clang -arch arm64 -Wall -Wno-pointer-sign -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk/ -DHGVERSION="\"unknown\"" -O3 -I. -framework CoreFoundation -framework IOKit -framework Security -miphoneos-version-min=8.0 -o device_infos device_infos.c device_info.c IOAESAccelerator.c AppleEffaceableStorage.c AppleKeyStore.c bsdcrypto/pbkdf2.c bsdcrypto/sha1.c bsdcrypto/key_wrap.c bsdcrypto/rijndael.c util.c IOKit.c registry.c ioflash/ioflash.c ioflash/IOFlashPartitionScheme.c kernel_patcher.c
..........

完美编译通过,会在ramdisk_tools 目录中产生一个bruteforce 文件。这就是我们要构建的暴力破解器。接下来就是如何使用了。

构建所需要的Python库

用于解密已保护数据的工具使用Python写的,

Search

    Post Directory