SuperAPI AI Directory

ios-pentesting

Testing & quality

View repository

Updated 10-16 05:48

About this skill

iOS application penetration testing methodology

Phase flow: Environment preparation → IPA static analysis → Dynamic analysis (Frida/Objection) → Data storage security → Network communication security → URL Scheme → Protection mechanism bypass

In-depth reference


Phase 0: Environment preparation

Device requirements

测试设备选择?
├─ 越狱 iPhone(推荐)
│   ├─ checkra1n (A5-A11, 硬件级)
│   ├─ unc0ver / Taurine (软件越狱)
│   └─ Dopamine / palera1n (较新设备)
├─ 非越狱设备
│   ├─ 功能有限: 无法访问沙箱、Keychain dump
│   ├─ 可用 objection + Frida Gadget 注入
│   └─ 仍可做: 网络分析、IPA 静态分析、备份分析
└─ 模拟器(Xcode Simulator)
    └─ Intel Mac 常见 x86_64 simulator 架构,Apple Silicon 支持 arm64 simulator 架构
    └─ 不支持真机越狱场景,硬件能力与 Keychain 行为也不同于真机

Core toolchain

Tool Purpose Installation
Frida + frida-tools Dynamic Hook / runtime analysis pip install frida-tools
objection Frida automation wrapper pip install objection
otool / jtool2 Binary analysis macOS built-in / brew
class-dump ObjC class information extraction brew install class-dump
Ghidra / IDA / Hopper Disassembly/decompilation Respective official websites
Burp Suite Traffic interception PortSwigger
MobSF Automated static + dynamic analysis Docker deployment
ideviceinstaller IPA installation/management brew install ideviceinstaller
ios-deploy Device deployment brew install ios-deploy
Keychain-Dumper Keychain data extraction GitHub (jailbroken device)
SSL Kill Switch 2 SSL Pinning bypass Cydia

IPA acquisition

# 从越狱设备提取
ssh root@device_ip
find /var/containers/Bundle/Application/ -name "*.app" 2>/dev/null

# 使用 frida-ios-dump
pip install frida-ios-dump
python dump.py -H device_ip -p 22 "AppName"

# 从 iTunes 备份提取
# macOS: ~/Library/Application Support/MobileSync/Backup/

# 第三方下载
# iMazing / Apple Configurator 2

Phase 1: IPA static analysis

IPA structure parsing

# IPA 本质是 ZIP
mv target.ipa target.zip
unzip target.zip -d ipa_contents/

# 目录结构:
# Payload/
#   AppName.app/
#     Info.plist          ← 应用配置(权限/URL Scheme/ATS)
#     _CodeSignature/     ← 代码签名
#     Frameworks/         ← 第三方框架
#     Assets.car          ← 资源文件
#     AppName             ← 主二进制(Mach-O)

Binary security inspection

# PIE(地址随机化)
otool -hv AppName | grep PIE
# 应包含 PIE flag

# Stack Canaries(栈保护)
otool -I -v AppName | grep stack_chk
# 应包含 stack_chk_guard 和 stack_chk_fail

# ARC(自动引用计数)
otool -I -v AppName | grep objc_release
# 应包含 _objc_release

# 加密状态
otool -arch all -Vl AppName | grep -A5 LC_ENCRYPT
# cryptid = 1 → 已加密(App Store 版本)
# cryptid = 0 → 未加密(可直接分析)

# 第三方库
otool -L AppName

Insecure function inspection

# 弱哈希
otool -Iv AppName | grep -w "_CC_MD5"
otool -Iv AppName | grep -w "_CC_SHA1"

# 不安全随机数
otool -Iv AppName | grep -w "_random\|_srand\|_rand"

# 不安全内存操作
otool -Iv AppName | grep -w "_gets\|_memcpy\|_strncpy\|_strlen\|_sprintf\|_vsprintf"

# 不安全 malloc
otool -Iv AppName | grep -w "_malloc"

Info.plist audit

# 转为可读 XML
plutil -convert xml1 Info.plist

# 关键字搜索
grep -i "NSAppTransportSecurity" Info.plist
grep -i "CFBundleURLTypes" Info.plist
grep -i "UsageDescription" Info.plist
grep -i "NSAllowsArbitraryLoads" Info.plist

Key inspection items:

Configuration Risk Impact
NSAllowsArbitraryLoads = true High ATS disabled, HTTP allowed
CFBundleURLTypes Medium URL Scheme can be hijacked
None NSAppTransportSecurity Low Use default ATS (secure)
LSApplicationQueriesSchemes Info Can detect installed applications

ObjC class information extraction

# class-dump 提取头文件
class-dump AppName > headers.h

# 搜索敏感方法
grep -n "password\|token\|secret\|encrypt\|decrypt\|key" headers.h

# 反汇编 text 段
otool -tV AppName | head -100

# ObjC segment
otool -oV AppName | head -100

Phase 2: Dynamic analysis (Frida/Objection)

Frida basic operations

# 列出设备上的应用
frida-ps -Uai

# 附加到运行中的应用
frida -U "AppName"

# 以 spawn 模式启动
frida -U -f com.target.app

# 使用脚本
frida -U -f com.target.app -l hook.js

Objection core features

# 连接到应用
objection --gadget "AppName" explore

# 环境信息
env

# 枚举组件
ios hooking list classes
ios hooking list class_methods ClassName

# NSUserDefaults 读取
ios nsuserdefaults get

# Keychain dump
ios keychain dump

# Cookie 读取
ios cookies get --json

# Plist 查看
ios plist cat /path/to/file.plist

# 二进制信息
ios info binary

# 禁用 SSL Pinning
ios sslpinning disable

# 禁用越狱检测
ios jailbreak disable

# 加密监控
ios monitor crypt

# 生物认证绕过
ios ui biometrics_bypass

Process enumeration and Hook

动态分析目标?
├─ 数据存储审计 → Keychain dump + NSUserDefaults + Plist
├─ 网络流量分析 → SSL Pinning 绕过 + Burp 拦截
├─ 认证绕过 → Hook evaluatePolicy / 生物认证
├─ 加密算法审计 → ios monitor crypt
├─ URL Scheme 测试 → 构造 scheme:// URL 触发
└─ 内存分析 → 搜索敏感数据残留

Phase 3: Data storage security

Full inspection of storage locations

数据存储审计清单?
├─ NSUserDefaults → Library/Preferences/<BundleID>.plist
│   └─ objection: ios nsuserdefaults get
│   └─ 是否存储明文凭据/Token?
├─ Keychain
│   └─ objection: ios keychain dump
│   └─ Keychain-Dumper(越狱设备)
│   └─ 数据保护等级是否合适?
├─ CoreData/SQLite → Library/Application Support/
│   └─ find ./ -name "*.sqlite" -or -name "*.db"
│   └─ 数据是否加密?
├─ Realm → Documents/default.realm
│   └─ find ./ -name "*.realm*"
│   └─ 使用 Realm Studio 查看
├─ Plist 文件
│   └─ find ./ -name "*.plist"
│   └─ 是否存储敏感信息?
├─ Cookie → Library/Cookies/cookies.binarycookies
│   └─ objection: ios cookies get --json
│   └─ Secure/HttpOnly flag?
├─ Cache → Library/Caches/<BundleID>/Cache.db
│   └─ sqlite3 Cache.db → 检查缓存的请求/响应
├─ 快照 → Library/Caches/Snapshots/ 或 Library/SplashBoard/Snapshots/
│   └─ 是否包含敏感界面截图?
│   └─ ApplicationDidEnterBackground 是否清除?
└─ 备份数据
    └─ iTunes/Finder 备份 → 检查敏感数据是否被排除
    └─ NSURLIsExcludedFromBackupKey 是否正确设置?

Practical operations

# 定位应用目录(越狱设备 / objection env 命令)
find /private/var/containers -name "AppName*" 2>/dev/null

# 关键检查命令
cat .../Library/Preferences/com.target.app.plist    # NSUserDefaults
find .../  -name "*.sqlite" -or -name "*.db"         # SQLite
sqlite3 found.db "SELECT * FROM credentials;"        # 查数据库
/usr/bin/keychain-dumper                              # Keychain dump
ls .../Library/Caches/Snapshots/                      # 后台快照
grep -i "firebase" Info.plist                         # Firebase URL
curl https://target.firebaseio.com/.json              # 未授权访问测试

Phase 4: Network communication security

Burp configuration (iOS)

流量拦截配置?
├─ WiFi 代理设置
│   └─ 设置 → WiFi → HTTP 代理 → 手动 → Burp IP:8080
├─ Burp CA 安装
│   └─ Safari 访问 http://burp → 下载 CA
│   └─ 设置 → 通用 → VPN 与设备管理 → 安装
│   └─ 设置 → 通用 → 关于 → 证书信任设置 → 启用
├─ SSL Pinning 绕过(如果需要)
│   ├─ SSL Kill Switch 2 (Cydia)
│   ├─ objection: ios sslpinning disable
│   ├─ Frida 脚本 Hook
│   └─ Burp Mobile Assistant
└─ 非 HTTP 流量
    └─ tcpdump 抓包
    └─ Wireshark 分析

SSL Pinning bypass

# 方案 1: SSL Kill Switch 2 (Cydia,全局绕过)
# 方案 2: objection
objection --gadget com.target.app explore -s "ios sslpinning disable"
# 方案 3: Frida 脚本
frida -U -f com.target.app -l ios_ssl_bypass.js
# 方案 4: Burp Mobile Assistant (自动配置)

# 主机名验证: Burp 生成不同主机名证书 → 应用仍工作 = 验证缺失

Phase 5: URL Scheme / Universal Links

Custom URL Scheme

# 从 Info.plist 提取
grep -A 10 "CFBundleURLTypes" Info.plist

# 测试 URL Scheme
# Safari 输入: myapp://action?param=value
# 或通过命令:
xcrun simctl openurl booted "myapp://auth?token=test"
URL Scheme 测试点?
├─ 是否通过 URL 传递敏感数据(Token/密码)?
│   └─ 任何应用可注册相同 scheme 截获
├─ 参数是否做输入验证?
│   └─ 路径穿越: myapp://page/../admin
│   └─ JavaScript 注入(如果打开 WebView)
├─ WebView 是否将 URL 直接传给 openURL / UIApplication.open?
│   └─ 可能导致外部 App 跳转、deep link 路由绕过或参数注入
└─ Open Redirect?
    └─ myapp://redirect?url=https://evil.com

Universal Links

# 检查 apple-app-site-association
curl https://target.com/.well-known/apple-app-site-association
curl https://target.com/apple-app-site-association

# 验证配置是否正确限制路径

Phase 6: Protection mechanism bypass

Jailbreak detection bypass

越狱检测机制?
├─ 文件系统检查
│   ├─ /Applications/Cydia.app
│   ├─ /Library/MobileSubstrate/MobileSubstrate.dylib
│   ├─ /bin/bash, /usr/sbin/sshd
│   └─ 绕过: Hook NSFileManager fileExistsAtPath → 返回 NO
├─ 沙箱违规检查
│   ├─ 尝试写入 /private/
│   └─ 绕过: Hook 写入函数返回失败
├─ API 检查
│   ├─ fork() 是否成功
│   ├─ system() 是否可用
│   └─ 绕过: Hook 返回预期的受限值
├─ 进程检查
│   ├─ 检测 Cydia/Substrate/sshd 进程
│   └─ 绕过: Hook 进程列表函数
├─ URL Scheme 检查
│   ├─ canOpenURL("cydia://")
│   └─ 绕过: Hook canOpenURL 返回 NO
└─ 环境变量/动态库检查
    ├─ DYLD_INSERT_LIBRARIES
    ├─ 加载的 dylib 列表
    └─ 绕过: Hook 相关检查函数
# objection 一键绕过
objection --gadget com.target.app explore -s "ios jailbreak disable"

# Frida 手动 Hook
frida -U -f com.target.app -l jailbreak_bypass.js

# Liberty Lite (Cydia 插件)
# 按应用启用越狱隐藏

Anti-debugging bypass

反调试机制?
├─ sysctl 检查调试器
│   └─ Hook sysctl 返回无调试器
├─ ptrace(PT_DENY_ATTACH)
│   └─ Hook ptrace NOP
├─ 计时检查(检测断点导致的延迟)
│   └─ Hook 时间函数返回合理值
├─ 内存检查(检测调试器痕迹)
│   └─ Hook 内存读取函数
├─ Mach Port 检查
│   └─ Hook mach exception port 查询
└─ 多层联合检查
    ├─ 自签名状态检测 (csops)
    ├─ 完整性校验 (CRC32/MD5)
    ├─ kill-on-attach (abort/exit)
    ├─ Jetsam 内存压力终止
    └─ 心跳定时器延迟执行

Biometric authentication bypass

# objection 绕过
objection --gadget com.target.app explore -s "ios ui biometrics_bypass"

# Frida 脚本绕过 evaluatePolicy
# Hook LAContext.evaluatePolicy → 强制 callback 返回 success=1
frida -U -f com.target.app -l fingerprint_bypass.js

Phase 7: Other inspection items

补充检查清单?
├─ 键盘缓存 → /var/mobile/Library/Keyboard/*dynamic-text*
│   └─ 第三方键盘可窃取击键; secureTextEntry 是否设置
├─ 日志泄露 → idevicesyslog -u <id> | grep app
│   └─ NSLog/print 是否记录敏感信息
├─ 备份安全 → iTunes/Finder 备份中是否包含敏感数据
│   └─ NSURLIsExcludedFromBackupKey 是否排除关键文件
├─ Hot Patching → JSPatch / RN 热更新可被恶意 SDK 滥用
└─ 第三方 SDK → otool -L AppName → 权限是否超出必要

Automated tool quick reference

Tool Type Usage
MobSF Static + dynamic Docker deployment, upload IPA
objection Dynamic objection --gadget AppName explore
Frida Dynamic frida -U -f com.target.app -l script.js
Keychain-Dumper Data extraction Run directly on jailbroken device
class-dump Static class-dump AppName > headers.h
Malimite Decompilation GUI tool, supports Swift/ObjC
r2frida Memory analysis r2 frida://usb//AppName

Reference resources