iOS逆向之代码注入(framework)
题外话:此教程是一篇严肃的学术探讨类文章,仅仅用于学习研究,也请读者不要用于商业或其他非法途径上,笔者一概不负责哟~~
准备工作
- 非越狱的iPhone手机
- 用PP助手下载: 微信6.6.5(越狱应用)
- MachOView
MachOView下载地址:http://sourceforge.net/projects/machoview/
MachOView源码地址:https://github.com/gdbinit/MachOView
- yololib
yololib下载地址https://github.com/KJCracks/yololib?spm=a2c4e.11153940.blogcont63256.9.5126420eAJpqBD
代码注入思路:
DYLD会动态加载Frameworks中所有的动态库,那么在Frameworks中加一个自己的动态库,然后在自己动态库中hook和注入代码
动态库存放的位置:Frameworks

找到可执行文件WeChat

用MachOView打开可执行文件WeChat,在Load Commands里可以查看到动态库



步骤:
1、根据iOS逆向之自动化重签名先编译运行微信,然后新建Framework
TARGETS添加:


2、新建一个WJHook类

3、想实现刚加载就要运行,代码就要写在load方法里

4、为工程添加依赖关系
-
在代码注入targets的Build Phases中添加Copy Files
image.png
-
在Copy Files中选择Frameworks
image.png
-
添加WJHookFrameWork
image.png
5、编译一下,在app包的位置查看

显示包内容,在Frameworks中查看

由上可知,WJHookFrameWork已经加入成功
6、运行,并没有成功,没有执行load里的代码
原因:用MachOView打开可执行文件WeChat,在Load Commands找不到WJHookFrameWork
7、将WJHookFrameWork写入MachO文件
需要用到工具:yololib
因为经常会用到这个工具,建议将它放到 /usr/local/bin

- 显示隐藏文件,可以使用
$defaults write com.apple.finder AppleShowAllFiles -bool true
$KillAll Finder
这条命令来显示。同时,将 true 改成 false, 就可恢复隐藏状态。- 或者使用快捷键 ⌘ + ⬆️ + . 来实现
-
解压微信越狱包
image.png
- 将WeChat.app显示包内容,找到WeChat可执行文件
增加执行权限:chmod +x WeChat
- 写入WeChat可执行文件:
yololib WeChat Frameworks/WJHookFrameWork.framework/WJHookFrameWork
"Frameworks/WJHookFrameWork.framework/WJHookFrameWork"路径是指WJHookFrameWork可执行文件的路径
image.png
-
检查MachO文件的Load Commands里是否有WJHookFrameWork
image.png
如图,加入成功。
- 删除原来的微信-6.6.5(越狱应用).ipa,打包Payload
zip -ry WeChat.ipa Payload
将WeChat.ipa放入APP目录,删除其他文件夹
image.png
8、运行,成功!

代码和工具已上传:https://gitee.com/winjayq/ios_reverse_code_injection