简介

在上一节中我们介绍了如何编写一个 iblessing 插件,这里我们来介绍如何用 iblessing 对其进行加载。

下载壳程序和依赖配置

首先从 https://github.com/Soulghost/iblessing/releases 中下载 v1.0.0-framework 下的 iblessing 程序,注意它并不能独立运行,需要依赖 libiblessing-core.dylib,它可以在 iblessing-framework-darwin.tar.gz 中找到:
image.png

将壳程序运行起来

最简单的办法是将 libiblessing-core.dylib 放到 rpath 中,例如 /usr/local/lib,这样我们可以直接将 iblessing-darwin 和插件跑起来

如果你不想将 libiblessing-core.dylib 放到全局目录,也可以选择使用 install_name_tool 去修正 @rpath @executable_path,操作方法如下(不推荐,这样插件的 libiblessing-core.dylib 搜索目录也必须全部修正掉):
我们可以通过 otool 看到,iblessing-darwin 通过 rpath 查找 libiblessing-core.dylib:

  1. $ otool -l iblessing-darwin | grep DYLIB -A 5
  2. cmd LC_LOAD_DYLIB
  3. cmdsize 56
  4. name @rpath/libiblessing-core.dylib (offset 24)
  5. time stamp 2 Thu Jan 1 08:00:02 1970
  6. current version 0.0.0
  7. compatibility version 0.0.0

我们先将 libiblessing-core.dylib 放到当前目录,然后使用 install_name_tool 修正为 @executable_path:

install_name_tool -change @rpath/libiblessing-core.dylib @executable_path/libiblessing-core.dylib iblessing-darwin

再检查一下 header:

$ otool -l iblessing-darwin | grep DYLIB -A 5
          cmd LC_LOAD_DYLIB
      cmdsize 72
         name @executable_path/libiblessing-core.dylib (offset 24)
   time stamp 2 Thu Jan  1 08:00:02 1970
      current version 0.0.0
compatibility version 0.0.0

接下来,只需要让 libiblessing-core.dylib 在当前目录就可以正常加载啦:

$ ls
iblessing-darwin        libiblessing-core.dylib

$ ./iblessing-darwin

           ☠️
           ██╗██████╗ ██╗     ███████╗███████╗███████╗██╗███╗   ██╗ ██████╗
           ██║██╔══██╗██║     ██╔════╝██╔════╝██╔════╝██║████╗  ██║██╔════╝
           ██║██████╔╝██║     █████╗  ███████╗███████╗██║██╔██╗ ██║██║  ███╗
           ██║██╔══██╗██║     ██╔══╝  ╚════██║╚════██║██║██║╚██╗██║██║   ██║
           ██║██████╔╝███████╗███████╗███████║███████║██║██║ ╚████║╚██████╔╝
           ╚═╝╚═════╝ ╚══════╝╚══════╝╚══════╝╚══════╝╚═╝╚═╝  ╚═══╝ ╚═════╝

[***] iblessing iOS Security Exploiting Toolkit Beta 1.0.0-plugin (http://blog.asm.im)
[***] Author: Soulghost (高级页面仔) @ (https://github.com/Soulghost)
[***] System Integrity Protection is on

加载插件

在当前目录新建一个 Plugins 文件夹,并将第二篇文章中(https://www.yuque.com/yansugu/nkwc1m/ik58xz)构建的插件放到 Plugins 中,这里以 libotool-scanner.dylib 为例:

$ tree .
.
├── Plugins
│   └── libotool-scanner.dylib
├── iblessing-darwin
└── libiblessing-core.dylib

随后运行 iblessing-darwin,如果成功你会看到顶部黄色的插件加载成功提示,同时通过 -l 也可以找到 otool 这个插件:

$ ./iblessing-darwin -l

           ☠️
           ██╗██████╗ ██╗     ███████╗███████╗███████╗██╗███╗   ██╗ ██████╗
           ██║██╔══██╗██║     ██╔════╝██╔════╝██╔════╝██║████╗  ██║██╔════╝
           ██║██████╔╝██║     █████╗  ███████╗███████╗██║██╔██╗ ██║██║  ███╗
           ██║██╔══██╗██║     ██╔══╝  ╚════██║╚════██║██║██║╚██╗██║██║   ██║
           ██║██████╔╝███████╗███████╗███████║███████║██║██║ ╚████║╚██████╔╝
           ╚═╝╚═════╝ ╚══════╝╚══════╝╚══════╝╚══════╝╚═╝╚═╝  ╚═══╝ ╚═════╝

[***] iblessing iOS Security Exploiting Toolkit Beta 1.0.0-plugin (http://blog.asm.im)
[***] Author: Soulghost (高级页面仔) @ (https://github.com/Soulghost)
[+] scan and load plugins in /Users/soulghost/Desktop/git/iblessing/cmake-build/dytest/Plugins
[+] load plugin at /Users/soulghost/Desktop/git/iblessing/cmake-build/dytest/Plugins/libotool-scanner.dylib
[***] System Integrity Protection is on

[*] Scanner List:
    - app-info: extract app infos
    - objc-msg-xref: generate objc_msgSend xrefs record
    - otool: obj dump tool
    - symbol-wrapper: symbol wrapper scanner
    - symbol-xref: symbol (function) xref scanner

如果你发现插件加载失败,可以参考上面修复壳程序 rpath 的方法,对插件的搜索目录进行修正,最简单的办法当然是直接把 libiblessing-core.dylib 装到系统级目录。