freeBuf
主站

分类

云安全 AI安全 开发安全 终端安全 数据安全 Web安全 基础安全 企业安全 关基安全 移动安全 系统安全 其他安全

特色

热点 工具 漏洞 人物志 活动 安全招聘 攻防演练 政策法规

点我创作

试试在FreeBuf发布您的第一篇文章 让安全圈留下您的足迹
我知道了

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

inject:强大的machO文件代码注入工具
FreeBuf实验室 2021-12-06 10:19:27 214949

关于inject

一直以来,iOS的代码注入工具有optool和yololib,但是这两个库已经许久不维护了。因此inject的出现为代码注入事业重新注入了活力。

inject采用Swift代码编写,可以直接运行在装有最新macOS的mac电脑上。

inject可以向machO文件中写入load commands,让machO在运行的过程中加载相应的动态库,实现代码注入的功能。

功能介绍

❯ ./inject -h
OVERVIEW: inject v2.0.0

inject is a tool which interfaces with MachO binaries in order to insert load commands.

USAGE: inject <file-path> [--dylib <dylib>] [--cmd <cmd>] [--ipa] [--strip] [--aslr] [--weak <weak>]

ARGUMENTS:
  <file-path>             The machO/ipa to inject.

OPTIONS:
  -d, --dylib <dylib>     The dylib to inject, please give me path.
  -c, --cmd <cmd>         Specify which type of load command to use in INSTALL. Can be reexport for LC_REEXPORT_DYLIB, weak for LC_LOAD_WEAK_DYLIB, upward
                          for LC_LOAD_UPWARD_DYLIB, or load for LC_LOAD_DYLIB. (default: LC_LOAD_DYLIB)
  -i, --ipa               If inject into ipa, please set this flag. Default false mean is machO file path.
  -s, --strip             Removes a code signature load command from the given binary.
  -a, --aslr              Removes an ASLR flag from the macho header if it exists. This may render some executables unusable.
  -w, --weak <weak>       Used with the STRIP command to weakly remove the signature. Without this, the code signature is replaced with null bytes on the
                          binary and it's LOAD command is removed. (default: true)
  --version               Show the version.
  -h, --help              Show help information.

使用方法

向mac可执行文件中注入dylib:

❯ ./inject testExec -d @executable_path/testMac/libtestinject.dylib

向IPA文件中注入dylib:

该方法可以直接得到一个重打包的IPA文件

❯ ./inject testiOS/app.ipa -d  @executable_path/testiOS/libinjectiOS.dylib --ipa

向IPA文件中注入framework:

该方法可以直接得到一个重打包的IPA文件

❯ ./inject testiOS/app.ipa -d  @executable_path/testiOS/injectiOSFramework.framework/injectiOSFramework --ipa

直接使用.framework后缀的路径也可以注入成功

❯ ./inject testiOS/app.ipa -d  @executable_path/testiOS/injectiOSFramework.framework --ipa

需要注意

重新打包后的IPA文件需要重签名才可以运行,并且如果注入了dylib文件,需要针对dylib文件单独重签名,否则App运行时闪退。

重签名主要是使用codesign命令,大概像这样:

❯ security find-identity -v -p codesigning
1) xxxxx "Apple Development: xxx xx (xxxxxxxxxx)"
     1 valid identities found
❯ codesign -f -s "xxxxx" Payload/app.app
Payload/app.app: replacing existing signature
❯ codesign -f -s "xxxxx" Payload/app.app/Inject/libxxxxx.dylib
Payload/app.app/Inject/libxxxxx.dylib: replacing existing signature

项目地址

https://github.com/paradiseduo/inject

# ios安全 # ios越狱 # 移动应用安全 # iOS逆向 # ios企业级开发者账号
免责声明
1.一般免责声明:本文所提供的技术信息仅供参考,不构成任何专业建议。读者应根据自身情况谨慎使用且应遵守《中华人民共和国网络安全法》,作者及发布平台不对因使用本文信息而导致的任何直接或间接责任或损失负责。
2. 适用性声明:文中技术内容可能不适用于所有情况或系统,在实际应用前请充分测试和评估。若因使用不当造成的任何问题,相关方不承担责任。
3. 更新声明:技术发展迅速,文章内容可能存在滞后性。读者需自行判断信息的时效性,因依据过时内容产生的后果,作者及发布平台不承担责任。
本文为 FreeBuf实验室 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
FreeBuf实验室 LV.3
FreeBuf网络安全实验室
  • 4 文章数
  • 7 关注者
2023年iOS最新版class-dump方案
2022-03-01
appdecrypt: 强大的iOS APP脱壳工具
2021-08-17
ApplicationScanner:一款App等保的预检测工具
2021-04-21