IOS 解密APP(逆向工程完整详解)

最近手痒,整理了下IOS APP逆向工程相关资料,分享出来大家一起看看。

逆向工程可分为四步:砸壳、dump、hook、重签。

一、砸壳:

概述:IOS的APP,若上传了App Store会被苹果进行一次加密,所以我们下载下来的安装包都是加密的,若要进行dump需要进行一次解密,即砸壳。

我们以微信为例:

首先我们需要一台已经越狱了的iPhone手机,然后进入Cydia安装需要的三款工具openSSH、Cycript、iFile。(调试程序时可以方便地查看日志文件)

新版本iTunes已经将应用功能去掉了,所以大家只能用手机从App Store下载最新微信。

砸壳第一步:获取微信的可执行文件的具体位置和沙盒的具体位置,我们先把iPhone上的所有程序都关掉,唯独留下微信。

连接ssh,打开Mac的bash,用ssh连上iPhone(确保iPhone跟Mac在同一个网段)。openSSH的root密码默认为:alpine

然后输入命令 ps -e | grep WeChat

有时候我们需要一个APP的Bundle id了,这里笔者有一个小技巧,我们可以把iPhone上的所有App都关掉,唯独保留APP如微信,然后输入命令

ps -e ,便可输出当前运行的APP的Bundle id。

寻找沙盒Documents具体路径,我们需要用Cycript找出微信的Documents具体路径。输入命令cycript -p WeChat

打开微信,进入cy#模式输入NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, ES)[0]就能找出Documents的具体路径,或者使用cy# directory = NSHomeDirectory(),也可以得到沙河位置(缺少/Documents)。

control D 可退出模式

编译dumpdecrypted 进入dumpdecrypted源码的目录,输入指make来编译dumpdecrypted。一般make后会在当前目录下生成一个dylib文件。

4.创建动态库文件

(1)一错

在确保Makefile中对动态库的设置和iOS真机环境一致后,在当前目录下输入: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 /bin/sh: /Applications/Xcode: No such file or directory make: *** [dumpdecrypted.o] Error 127

原因是找不到/Applications/Xcode来执行其中的一些脚本。 好吧,我的Mac中有3个Xcode:/Applications/Xcode 5.0.2, /Applications/Xcode 5.1.1, /Applications/Xcode 6 Beta4,就是没有/Applications/Xcode。

没事,将Xcode 5.1.1重命名为Xcode就行了:

$ sudo mv Xcode\ 5.1.1.app/ Xcode.app/

(2)再错

再make,还是报错,错误信息和上面一样。 不怕,我们还有xcode-select这个小伙伴,通常Xcode找不到之类的错误都应该找它帮忙: $ xcode-select -p /Applications/Xcode 5.1.1.app/Contents/Developer 原来xcrun查找cmd tool时的路径还是Xcode 5.1.1/,当然什么都找不到了。这时候将它重置就行了(默认是/Applications/Xcode.app/): $ sudo xcode-select -r $ xcode-select -p /Applications/Xcode.app/Contents/Developer

(3)成功再make,成功,输出如下:

$ 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 $ ls Makefile dumpdecrypted.c dumpdecrypted.o README dumpdecrypted.dylib

可以看到目录中多了两个文件,其中dylib后缀的就是我们要创建的动态库文件,也就是用来砸壳的锤子。

scp拷贝指令 使用scp指令把dumpdecrypted.dylib拷贝到iPhone的Documents路径目录下输入指令:scp

开始砸壳!!! 回到手机的ssh上,输入dumpdecrypted的指令。

dumpdecrypted的具体用法:

DYLD_INSERT_LIBRARIES=/PathFrom/dumpdecrypted.dylib /PathTo 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: @0x56a4c(from 0x56000) = a4c [ ] Found encrypted data at address 00004000 of length 38748160 bytes – type 1. [ ] Opening /private/var/mobile/Containers/Bundle/Application/2C920956-E3D6-4313-BD88-66BD24CEBE9B/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-
© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!插入图片请使用ssl
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容