# IOS Exploiting

> iOS system-level exploitation methodology. Covers iOS kernel exploitation (UAF/heap overflow/type confusion), Safari/WebKit exploitation, PAC bypass, sandbox escape, the Corellium research environment, and analysis of known CVEs (CVE-2020-27950, CVE-2021-30807, iMessage zero-click). Triggered when an Agent needs to analyze iOS system-level vulnerabilities, conduct kernel exploitation research, or understand iOS exploit chains.

- Skill: `dangeroussong/ios-exploiting` (Agent Skill)
- Install (CLI): `npx get-skill add dangeroussong/ios-exploiting`
- Raw SKILL.md: https://api.skillmd.com/api/skills/dangeroussong/ios-exploiting/raw
- Safety review: pending (external: skill-scanner PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: DangerousSONG (https://skillmd.com/u/dangeroussong)
- Updated: 2026-11-19
- Page: https://skillmd.com/skills/dangeroussong/ios-exploiting

---


# iOS System-Level Exploitation Methodology
- 攻击大类:C46 二进制漏洞利用与Pwn

> **Phase flow**: Environment setup (Corellium) → Attack surface analysis → Kernel exploitation → WebKit exploitation → PAC bypass → Sandbox escape → Known CVE analysis

## Further Reading

- iOS kernel heap mechanics and exploitation techniques → [references/ios-kernel-heap.md](references/ios-kernel-heap.md)
- Detailed mitigation mechanisms and bypass methods → [references/ios-exploit-mitigations.md](references/ios-exploit-mitigations.md)

---

## Phase 0: Environment Setup (Corellium)

### Research Environment Selection

```
Research environment?
├─ Corellium (cloud iOS virtualization)
│   ├─ Supports kernel debugging
│   ├─ Supports snapshots/rollback
│   ├─ Supports running multiple iOS versions in parallel
│   └─ Paid, but highest research value
├─ Jailbroken physical device
│   ├─ Below A11: checkra1n (hardware-level jailbreak)
│   ├─ Requires JTAG/SWD (advanced research)
│   └─ Limitation: cannot debug kernel boot
├─ QEMU (open source)
│   ├─ Partial support via Project Sandcastle
│   └─ Limited functionality, incomplete
└─ Patch-diffing environment
    ├─ Ghidra + BinDiff
    └─ Compare kernelcache across iOS versions
```

### kernelcache Extraction

```bash
# 1. Download the IPSW
# https://ipsw.me/ → select the target device and version

# 2. Unpack the IPSW (it is actually a ZIP)
unzip iPhone*.ipsw -d ipsw_contents/

# 3. Unpack kernelcache
# Use img4tool or joker
img4tool -e -o kernelcache.raw ipsw_contents/kernelcache.*
# or
jtool2 --dec kernelcache.release.*

# 4. Load into Ghidra for analysis
ghidraRun
# Create a new project → import kernelcache → ARM64 / AARCH64
# After auto-analysis completes, you can search functions/symbols
```

### BinDiff Version Comparison

```bash
# Locate functions modified by security patches
# 1. Download the IPSW of the vulnerable and patched versions
# 2. Extract both kernelcache files
# 3. Analyze both versions with Ghidra
# 4. Export BinExport: File → Export → Binary BinExport (v2) for BinDiff
# 5. Open BinDiff → create a new workspace → add a diff
# 6. Primary file = vulnerable version, secondary file = patched version
# 7. Focus: Changed Functions → the modified functions are the patch locations
```

### XNU Version Mapping

```bash
# iOS version → XNU version mapping
# https://www.theiphonewiki.com/wiki/kernel
# Example: iOS 15.1 → Darwin Kernel Version 21.1.0 → xnu-8019.43.1
```

---

## Phase 1: Attack Surface Analysis

### iOS Attack Surface Classification

```
Attack surface?
├─ Remote, no interaction (Zero-Click)
│   ├─ iMessage parsers (image/audio/video/PDF/vCard)
│   ├─ FaceTime / VoIP
│   ├─ AirDrop / Bluetooth
│   └─ WiFi driver / protocol stack
├─ Remote, needs interaction (One-Click)
│   ├─ Safari / WebKit (JavaScript → JIT → RCE)
│   ├─ URL Scheme handling
│   └─ Malicious configuration profiles (.mobileconfig)
├─ Local privilege escalation
│   ├─ Kernel syscall interfaces
│   ├─ IOKit drivers (IOSurface/AGX/IOMFB)
│   ├─ XPC services
│   ├─ Mach IPC (port/message/voucher)
│   └─ Filesystem / sandbox escape
└─ Physical access
    ├─ USB (lockdownd/usbmuxd)
    ├─ bootrom (checkm8 series)
    └─ DFU mode attacks
```

### Common Vulnerability Types

| Vulnerability Type | Common Location | Exploitation Complexity |
|----------|----------|------------|
| UAF (Use-After-Free) | IPC ports, IOKit objects | Medium-High |
| Heap Overflow | Parsers (image/font/media) | Medium |
| Type Confusion | WebKit JIT, IOKit | High |
| Integer Overflow | Kernel memory allocation, length validation | Medium |
| Race Condition | Syscall concurrency, missing locks | High |
| Information Leak | KASLR bypass, heap address leak | Low-Medium |
| OOB Read/Write | Missing array/buffer bounds checks | Medium |

---

## Phase 2: Kernel Exploitation

### Kernel Heap Layout (Heap Feng Shui)

```
Heap layout strategy?
├─ Legacy (pre-iOS 15)
│   ├─ kalloc zones: partitioned by size (16/32/64/.../1280)
│   ├─ Same-size objects adjacent → heap spraying yields predictable layout
│   ├─ freelist pointers exposed → can be forged
│   └─ Steps:
│       ├─ 1. Spray to fill fragmentation holes
│       ├─ 2. Continue spraying to force new page allocation
│       ├─ 3. Place attacker-controlled objects
│       ├─ 4. Free one object to create a hole
│       ├─ 5. Trigger the target object to be allocated into the hole
│       └─ 6. Overflow/UAF to overwrite the target object
└─ New (iOS 15+)
    ├─ kalloc_type: partitioned by type + size
    ├─ Isolates objects of different types (OSData ≠ task_t)
    ├─ freelist pointers XOR-encoded
    ├─ per-CPU cache reduces determinism
    ├─ guard pages detect overflow
    └─ Requires type-specific bugs or information leaks
```

### Kernel Primitive Construction

```
Exploitation primitive construction path?
├─ Information leak → KASLR bypass
│   ├─ Mach port information leak
│   ├─ IOKit property read out-of-bounds
│   └─ Obtain kernel base address + heap address
├─ Arbitrary Read
│   ├─ Forge the vtable of an IOKit object
│   ├─ Abuse mach_msg OOL descriptors
│   └─ Forge the kernel task port
├─ Arbitrary Write
│   ├─ Forge freelist pointers (legacy)
│   ├─ Vtable hijacking → control function pointers
│   └─ Tamper with pipe buffer
└─ Arbitrary code execution
    ├─ Modify process credentials (ucred)
    ├─ Bypass code signing (trust cache)
    ├─ Obtain the kernel task port
    └─ Requires bypassing PAC + PPL/SPTM
```

### IOSurface Physical UAF (Classic Case)

```
IOSurface exploitation flow:
├─ 1. Allocate an IOSurface object
├─ 2. Obtain a reference to the underlying physical page
├─ 3. Free the IOSurface (but keep the physical page reference)
├─ 4. The physical page is reclaimed and allocated to another kernel object
├─ 5. Read/write the reused kernel object through the retained mapping
└─ 6. Build a kernel r/w primitive
```

---

## Phase 3: WebKit/Safari Exploitation

### WebKit Exploit Chain

```
WebKit → full system exploit chain:
├─ Stage 1: WebKit Renderer RCE
│   ├─ JIT compiler bugs (DFG/FTL)
│   ├─ DOM object UAF / type confusion
│   ├─ ArrayBuffer out-of-bounds read/write
│   └─ Obtain: arbitrary r/w at the JS level
├─ Stage 2: Sandbox escape
│   ├─ XPC service bugs
│   ├─ Mach port manipulation
│   └─ Obtain: out-of-process code execution
├─ Stage 3: Kernel privilege escalation
│   ├─ IPC UAF → kernel r/w
│   ├─ IOKit driver bugs
│   └─ Obtain: kernel-level privileges
└─ Stage 4: Persistence
    ├─ Modify the trust cache
    ├─ Code signing bypass
    └─ Install unsigned payloads
```

### JSKit Framework Pattern (Commercial Spyware)

Patterns observed in real-world operations:

```
JSKit exploitation framework characteristics:
├─ Reusable entry: any WebKit JIT bug → JS arbitrary r/w
├─ Version abstraction: built-in multi-version PAC bypass modules
├─ Target fingerprinting: automatically identifies the iOS version and selects the corresponding bypass
├─ Manual Mach-O mapping: parses the dyld cache in memory, no disk writes needed
├─ Combination pattern:
│   WebKit RCE → kernel IPC UAF → kernel r/w → code signing bypass → unsigned stager
└─ Anti-analysis: Watcher module detects:
    ├─ developer_mode_status
    ├─ Jailbreak traces (Cydia/checkrain/frida/sshd)
    ├─ Security apps (McAfee/Avast/Norton)
    ├─ Custom proxy/root certificates
    └─ Specific locales (US/IL)
```

---

## Phase 4: PAC Bypass

### PAC Mechanism Overview

```
PAC (Pointer Authentication Codes):
├─ Hardware: ARMv8.3+ (A12 and later)
├─ Five 128-bit keys:
│   ├─ APIAKey / APIBKey → instruction pointer signing
│   ├─ APDAKey / APDBKey → data pointer signing
│   └─ APGAKey → generic signing
├─ Instructions:
│   ├─ PACxx → sign pointer (embed PAC in high bits)
│   ├─ AUTxx → verify + strip PAC
│   └─ XPACxx → strip PAC (without verification)
├─ Modifier (context binding):
│   └─ SP / frame pointer / object ID → prevent cross-context reuse
└─ Apple customization:
    ├─ Randomizes keys on each boot
    ├─ User/kernel domain isolation
    └─ Nine modifier types
```

### PAC Bypass Technique Classification

```
PAC bypass methods?
├─ Kernel-mode PAC bypass (extremely difficult)
│   ├─ Signing gadget reuse
│   ├─ Unprotected indirect branches
│   ├─ CVE-2023-32424 (Apple Silicon M1/M2)
│   └─ Usually requires implementation-level bugs; no generic bypass
├─ User-mode PAC bypass
│   ├─ dyld shared cache
│   │   ├─ Reuse of pre-signed function pointers
│   │   └─ PAC oracle construction
│   ├─ dlsym(3) returns already-signed pointers
│   │   ├─ Call dlsym("symbol") → obtain an A-key signed pointer
│   │   ├─ iOS 18.4 dlsym bug (Synacktiv)
│   │   └─ Signatures with context = 0 are reusable across processes
│   ├─ DYLD relocation window
│   │   ├─ Temporary RW pages during dynamic linking
│   │   ├─ Race exploitation to modify relocation tables
│   │   └─ SPRR/VM_FLAGS_TPRO protection (newer versions)
│   └─ ObjC Runtime (SLOP)
│       ├─ NSPredicate / NSExpression / NSInvocation
│       ├─ ISA / selector pointers not fully PAC-protected
│       └─ SeLector Oriented Programming
└─ Combined bypass
    ├─ Information leak + signing gadget
    ├─ Type confusion → control a signed object
    └─ Multi-stage chain: each stage provides a different primitive
```

---

## Phase 5: Sandbox Escape

### iOS Sandbox Architecture

```
Sandbox layers:
├─ App Sandbox (strictest)
│   ├─ Filesystem: only access to its own container
│   ├─ IPC: restricted XPC/Mach port access
│   ├─ Network: constrained by ATS
│   └─ Escape path: XPC service bugs / Mach port manipulation
├─ WebContent Sandbox (Safari renderer process)
│   ├─ Stricter than App sandbox
│   ├─ No direct filesystem access
│   ├─ Limited set of Mach services
│   └─ Escape path: abuse reachable Mach services
├─ System service Sandbox
│   ├─ mediaserverd / imagent / SpringBoard
│   ├─ Each has a different privilege scope
│   └─ Can serve as an intermediate hop for privilege escalation
└─ Kernel (no sandbox)
    └─ Full privileges
```

### PPL / SPTM Bypass

```
PPL (Page Protection Layer) protection:
├─ A kernel within the kernel: even kernel r/w cannot modify protected pages
├─ Protected scope:
│   ├─ Page table structures
│   ├─ Code signing metadata / trust cache
│   ├─ Entitlement tables
│   └─ Kernel code pages
├─ Based on APRR (Access Permission ReRouting)
│   └─ PTE index → APRR registers → actual permissions
├─ Known bypasses:
│   ├─ Project Zero TLB stale entry trick
│   │   ├─ Manipulate page table mappings + incomplete TLB flush
│   │   └─ Obtain writable mappings to PPL-protected pages
│   └─ Bugs in the PPL code itself (missing bounds checks, etc.)
└─ Evolution: A15+/M2+ → SPTM replaces PPL
    └─ Page table monitoring at a higher privilege level
```

---

## Phase 6: Known CVE Analysis

### Typical Exploit Chains

#### Safari → Kernel Full Chain (CVE-2023-419xx Series)

```
Intellexa Predator exploit chain:
├─ CVE-2023-41993: WebKit JIT → renderer RCE
│   └─ JSKit framework obtains JS arbitrary r/w
├─ CVE-2023-41992: kernel IPC UAF
│   └─ Free IPC object → reallocate → use-after-free exploitation
│   └─ Build kernel r/w
├─ CVE-2023-41991: code signing bypass
│   └─ Modify trust cache → unsigned code execution
└─ PREYHUNTER: follow-on monitoring implant
    ├─ VoIP recording (mediaserverd hook)
    ├─ Keylogging
    ├─ Photo capture (no UI)
    └─ Recording indicator hidden (SpringBoard hook)
```

#### iMessage Zero-Click Pattern

```
iMessage zero-click attack surface:
├─ Image parser: ImageIO (TIFF/GIF/PNG/JPEG/HEIF)
├─ Audio parser: CoreAudio (CAF/MP3/AAC)
├─ Video parser: AVFoundation
├─ PDF rendering: CoreGraphics
├─ vCard parsing: Contacts framework
├─ Typical exploit chain pattern:
│   ├─ 1. A malformed media file triggers a parser bug
│   ├─ 2. Achieve RCE in the imagent/mediaserverd process
│   ├─ 3. Escalate privileges using kernel interfaces reachable from that process
│   └─ 4. Requires no user interaction whatsoever
└─ Cases:
    ├─ FORCEDENTRY (NSO): JBIG2 PDF → Turing-complete virtual machine
    ├─ Operation Triangulation: font parsing → kernel
    └─ CVE-2021-30860: CoreGraphics PDF integer overflow
```

### Mitigation Evolution

| Mitigation | Introduction Period | Protection Target |
|----------|----------|----------|
| Code Signing | Initial | Unsigned code execution |
| DEP/W^X | Early | Shellcode execution |
| ASLR | iOS 4-5 | Address prediction |
| KASLR | iOS 5-6 | Kernel address prediction |
| KPP / Watchtower | iOS 9 era, common on A7-A9 | Kernel code tampering |
| KTRR / KIP | A10+ | Writes to kernel code pages |
| PPL | A12+ | Kernel memory protection pages |
| PAC | A12+ (ARMv8.3) | Pointer tampering/ROP/JOP |
| BTI | ARMv8.5+ | Indirect branch hijacking |
| PAN | ARMv8.1+ | Kernel accessing user memory |
| PXN | ARMv8+ | Kernel executing user code |
| SPTM/TXM | Newer platforms (e.g. A15+ / iOS 17+) | Kernel memory and page table permission management |
| MTE/EMTE/MIE | A19+ | UAF/heap overflow/OOB |

---

## Phase 7: Exception Handling Mechanisms (Exploitation-Related)

### XNU Exception Handling Flow

```
Exception triggered → exploitation impact:
├─ CPU exceptions (Data Abort / Illegal Instruction / PAC Fail)
├─ trap handler → exception_triage()
├─ Dispatch order:
│   ├─ 1. Thread exception port (debugger)
│   ├─ 2. Task exception port (process-level)
│   └─ 3. Host exception port (ReportCrash)
├─ No handler → bsd_exception() → UNIX signal
│   ├─ EXC_BAD_ACCESS → SIGSEGV/SIGBUS
│   ├─ EXC_BAD_INSTRUCTION → SIGILL
│   ├─ EXC_ARM_PAC → SIGILL (non-fatal) / immediate termination (TFRO_PAC_EXC_FATAL)
│   └─ EXC_CRASH → SIGKILL
└─ Special PAC exception handling:
    ├─ Platform binaries: TFRO_PAC_EXC_FATAL = true
    ├─ PAC failure terminates immediately without going through the debugger
    └─ Prevents debuggers from bypassing PAC checks
```

### Exception Handling in Exploitation

```
The role of exceptions in exploitation:
├─ Information gathering: leak addresses through exception information
├─ Condition checks: trigger/not trigger exceptions to determine conditions
├─ Crash stability: graceful exit on exploitation failure
├─ anti-analysis countermeasures:
│   ├─ Hook EXC_BREAKPOINT → implement custom breakpoints
│   ├─ Mach exception port → custom exception handling
│   └─ thread_set_state → modify registers to resume execution
└─ Counter-mitigation:
    ├─ PAC exceptions → must avoid triggering (rather than handle)
    └─ Register overwriting → destroy crash forensics
```

---

## Tool Quick Reference

| Tool | Purpose | Scenario |
|------|------|------|
| Ghidra | kernelcache decompilation | Patch diffing/function analysis |
| BinDiff | Binary diffing | Locating security patches |
| Corellium | iOS virtualization research | Kernel debugging/vulnerability reproduction |
| Frida | Runtime hooking | User-mode exploitation verification |
| r2frida | Memory analysis | Runtime heap analysis |
| jtool2 / otool | Binary parsing | Mach-O structure analysis |
| img4tool | IPSW parsing | kernelcache extraction |
| checkra1n | A5-A11 jailbreak | Research device preparation |

---

## Reference Resources

- [HackTricks - iOS Exploiting](https://book.hacktricks.wiki/binary-exploitation/ios-exploiting/)
- [Project Zero Blog - iOS Kernel PAC](https://bazad.github.io/presentations/BlackHat-USA-2020-iOS_Kernel_PAC_One_Year_Later.pdf)
- [Apple Platform Security Guide](https://support.apple.com/guide/security/)
- [The iPhone Wiki - Kernel](https://www.theiphonewiki.com/wiki/kernel)
- [Google TAG - Intellexa Zero-Day Exploits](https://cloud.google.com/blog/topics/threat-intelligence/intellexa-zero-day-exploits-continue)
