furkanaydi/zerohunter
GitHub: furkanaydi/zerohunter
一款用 C++20 编写的 iOS 固件漏洞扫描器,通过启发式规则自动检测 kernelcache 和 Mach-O 二进制中的整数溢出、IOKit 缺陷及 PAC 绕过等安全漏洞。
Stars: 0 | Forks: 0
# ZeroHunter
**iOS 0-day 漏洞扫描器** — 原生 C++20 工具,用于发现 iOS 固件中类似 FORCEDENTRY 的整数溢出、逻辑错误和 PAC 绕过 gadget。
## 快速开始
### 构建 (所有平台)
```
# 前提条件:CMake 3.20+, C++20 compiler (GCC 12+, Clang 15+, MSVC 2022+)
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . -j$(nproc)
```
**Windows (Visual Studio 2022):**
```
mkdir build && cd build
cmake .. -G "Visual Studio 17 2022" -A x64
cmake --build . --config Release
```
**Windows (MinGW-w64 / MSYS2):**
```
mkdir build && cd build
cmake .. -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release
cmake --build . -j8
```
所有依赖项(Capstone、miniz、lzfse)均通过 CMake FetchContent 自动获取。无需手动安装。
### 分析 IPSW
```
# Kernel 分析(始终有效 — kernelcache 从未加密)
./zerohunter --ipsw iPhone18,3_26.3_Restore.ipsw --kernel -o report.html
# 针对特定 framework(需要未加密的 RootFS)
./zerohunter --ipsw iPhone18,3_26.3_Restore.ipsw --target ImageIO -o report.html
# 直接 Binary 分析
./zerohunter --binary ./kernelcache.macho -o report.html
```
### CLI 选项
| 标志 | 描述 |
|------|-------------|
| `--ipsw ` | 输入 IPSW 固件文件 |
| `--binary ` | 直接输入 Mach-O 二进制文件 |
| `--kernel` | 分析 kernelcache (IOKit 驱动) |
| `--target ` | 目标框架 (例如 ImageIO, WebKit) |
| `-o, --output ` | HTML 报告输出路径 |
| `--max-funcs ` | 限制函数数量 (0 = 全部) |
| `--work-dir ` | 临时工作目录 |
| `-v, --verbose` | 详细日志 |
## 架构
```
zerohunter/
├── CMakeLists.txt # Build config, FetchContent deps
└── src/
├── main.cpp # CLI, pipeline orchestration
├── common.hpp # Types, logging, byte utils, constants
├── img4_parser.hpp/cpp # ASN.1 DER parser for IMG4/IM4P containers
├── lzfse_adapter.hpp/cpp # LZFSE + LZSS decompression
├── ipsw_handler.hpp/cpp # ZIP extraction, DMG handling, inventory
├── macho_parser.hpp/cpp # Custom Mach-O 64-bit parser
├── analyzer.hpp/cpp # Capstone disassembly + vulnerability detection
└── reporter.hpp/cpp # Terminal + HTML report generation
```
## 检测规则
| 规则 | 严重程度 | 模式 | CVE 示例 |
|------|----------|---------|--------------|
| **ZH-001** | 高 | 整数溢出 → 堆分配 (MUL → 无 CMP → BL _malloc) | CVE-2021-30860 (FORCEDENTRY) |
| **ZH-002** | 中 | 用户控制的大小流向 memcpy/memmove,无边界检查 | CVE-2022-22674 |
| **ZH-003** | 中 | 32 位算术运算无溢出检查 (宽度截断) | CVE-2021-1782 |
| **ZH-004** | 高 | IOKit dispatch: 缺少 selector 边界检查 | CVE-2021-30883 |
| **ZH-005** | 高 | PAC strip + 间接分支 gadget (XPACI → BR) | PACMAN (2022) |
| **ZH-006** | 中 | 来自用户控制输入的格式化字符串 | — |
### ZH-001 原理 (FORCEDENTRY 模式)
FORCEDENTRY 漏洞利用 (CVE-2021-30860) 使用了 JBIG2 整数溢出:
```
width × height × bytes_per_pixel → overflows 32-bit integer
malloc(small_value) → undersized allocation
memcpy(buf, data, actual_size) → heap buffer overflow
```
ZH-001 扫描此特定序列:
1. 查找 `MUL`/`MADD`/`UMULL` 指令
2. 检查结果寄存器是否流入 `malloc`/`calloc`/`IOMalloc`
3. 验证在乘法和分配之间不存在溢出检查(`CMP`/`cbz`/`TBNZ`)
## 流水线
```
IPSW (ZIP)
├── Extract via miniz (native, no 7z dependency)
├── Parse BuildManifest.plist for firmware version
├── Inventory: DMGs, kernelcaches, IMG4 payloads
│
├── RootFS DMG extraction (if unencrypted)
│ ├── macOS: hdiutil
│ └── Windows/Linux: 7z (tolerates symlink warnings)
│
└── Kernelcache processing
├── Strip IMG4/IM4P (ASN.1 DER parser)
├── Decompress LZFSE (Apple's reference library)
└── Output: raw Mach-O binary
│
├── MH_FILESET? → Parse embedded kexts (LC_FILESET_ENTRY)
│ Prioritize IOKit, IOSurface, IOGraphics, ...
└── Regular Mach-O
│
├── Custom parser: segments, sections, symbols,
│ LC_FUNCTION_STARTS, ARM64e PAC detection
│
└── Capstone disassembly (ARM64)
│
├── Function boundary detection
├── Per-function taint analysis (x0-x7 = user input)
└── Heuristic scanners (ZH-001 through ZH-006)
│
└── Findings → Terminal output + HTML report
```
## AEA 加密
iOS 16+ 固件通常使用 Apple Encrypted Archive (AEA) 作为 RootFS DMG。ZeroHunter 能妥善处理此情况:
1. **检测** 通过检查 DMG 魔数检测 AEA 加密
2. **跳过** 跳过加密的 DMG(无可用密钥材料)
3. **回退** 回退到 kernelcache 分析(始终可访问)
4. **报告** 在清单中报告哪些 DMG 已加密
kernelcache 包含所有 IOKit 驱动程序,这是零点击漏洞利用最常见的目标。对于框架分析,可在 macOS 上提取:
```
brew install blacktop/tap/ipsw
ipsw extract --dyld
zerohunter --binary -o report.html
```
## 自定义 Mach-O 解析器
ZeroHunter 使用完全自定义的 Mach-O 解析器(无 lief,无 MachOKit),支持:
- **Fat/universal binaries** — 自动选择 ARM64 slice
- **MH_FILESET** — 带有嵌入式 kexts 的 iOS kernel filesets (LC_FILESET_ENTRY)
- **ARM64e** — 检测 PAC (cpusubtype 0x02),去除指针中的 PAC 位
- **LC_FUNCTION_STARTS** — ULEB128 编码的函数边界
- **LC_SYMTAB** — 带有安全字符串处理的完整符号表解析
- **容错性** — 妥善跳过损坏/截断的加载命令
## 依赖项 (自动获取)
| 库 | 版本 | 用途 | 许可证 |
|---------|---------|---------|---------|
| [Capstone](https://github.com/capstone-engine/capstone) | 5.0.1 | ARM64 反汇编 | BSD |
| [miniz](https://github.com/richgel999/miniz) | 3.0.2 | ZIP 解压 | MIT |
| [lzfse](https://github.com/lzfse/lzfse) | 1.0 | Apple LZFSE 解压 | BSD |
## 输出
### 终端
带有反汇编上下文、按严重程度排序的彩色发现结果:
```
╔══════════════════════════════════════════════════╗
║ ZeroHunter — Analysis Summary ║
╚══════════════════════════════════════════════════╝
Binaries analyzed: 47
Functions scanned: 12,384 / 15,201
Instructions: 894,221
Elapsed: 3.42s
Findings: 23 total 2H 14M 7L
[HIGH] #1 — Integer overflow → heap allocation (FORCEDENTRY pattern)
Rule: ZH-001 Addr: 0xfffffff007a4c1b0 Func: IOSurface::
--- disassembly ---
0xfffffff007a4c1a8: ldr w8, [x0, #0x10]
0xfffffff007a4c1ac: ldr w9, [x0, #0x14]
>>> 0xfffffff007a4c1b0: mul w8, w8, w9
0xfffffff007a4c1b4: mov x0, x8
0xfffffff007a4c1b8: bl _IOMalloc
...
```
### HTML 报告
具有严重程度标记、反汇编和推荐建议的专业深色主题报告。生成单一自包含的 HTML 文件。
## 法律声明
本工具专为**防御性安全研究**设计。请负责任地使用,并遵守适用法律。作者不对滥用行为负责。
标签:0-day 挖掘, Bash脚本, BLASTPASS, C++20, Capstone, Clang, CMake, CVE 分析, DNS 反向解析, FORCEDENTRY, GCC, ImageIO, IOKit, iOS 安全, IPSW, Kernelcache, Mach-O, MSVC, PAC 绕过, Wayback Machine, WebKit, 二进制分析, 云安全监控, 云安全运维, 云资产清单, 代码生成, 反汇编, 固件分析, 域名收集, 攻击面分析, 整数溢出, 渗透测试工具, 目录枚举, 移动安全, 苹果漏洞, 误配置预防, 逆向工程, 逻辑漏洞, 静态分析