| name | ios-pentesting |
| description | iOS 应用渗透测试方法论。涵盖 IPA 静态分析(反编译/Plist分析/二进制检查)、动态分析(Frida/Objection/Cycript)、数据存储安全(Keychain/NSUserDefaults/CoreData)、网络通信安全、越狱检测绕过、URL Scheme 滥用。当 Agent 需要测试 iOS 应用安全、分析 IPA 文件、或绕过 iOS 保护机制时触发。
|
| metadata | {"tags":["ios","ipa","frida","objection","移动安全","keychain","越狱检测"],"category":"mobile"} |
iOS 应用渗透测试方法论
阶段流: 环境准备 → IPA静态分析 → 动态分析(Frida/Objection) → 数据存储安全 → 网络通信安全 → URL Scheme → 保护机制绕过
深入参考
Phase 0: 环境准备
设备要求
测试设备选择?
├─ 越狱 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 行为也不同于真机
核心工具链
| 工具 | 用途 | 安装 |
|---|
| Frida + frida-tools | 动态 Hook / 运行时分析 | pip install frida-tools |
| objection | Frida 自动化封装 | pip install objection |
| otool / jtool2 | 二进制分析 | macOS 内置 / brew |
| class-dump | ObjC 类信息提取 | brew install class-dump |
| Ghidra / IDA / Hopper | 反汇编/反编译 | 各自官网 |
| Burp Suite | 流量拦截 | PortSwigger |
| MobSF | 自动化静态+动态分析 | Docker 部署 |
| ideviceinstaller | IPA 安装/管理 | brew install ideviceinstaller |
| ios-deploy | 设备部署 | brew install ios-deploy |
| Keychain-Dumper | Keychain 数据提取 | GitHub (越狱设备) |
| SSL Kill Switch 2 | SSL Pinning 绕过 | Cydia |
IPA 获取
ssh root@device_ip
find /var/containers/Bundle/Application/ -name "*.app" 2>/dev/null
pip install frida-ios-dump
python dump.py -H device_ip -p 22 "AppName"
Phase 1: IPA 静态分析
IPA 结构解析
mv target.ipa target.zip
unzip target.zip -d ipa_contents/
二进制安全检查
otool -hv AppName | grep PIE
otool -I -v AppName | grep stack_chk
otool -I -v AppName | grep objc_release
otool -arch all -Vl AppName | grep -A5 LC_ENCRYPT
otool -L AppName
不安全函数检查
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"
otool -Iv AppName | grep -w "_malloc"
Info.plist 审计
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
关键检查项:
| 配置 | 风险 | 影响 |
|---|
NSAllowsArbitraryLoads = true | 高 | 禁用 ATS,允许 HTTP |
CFBundleURLTypes | 中 | URL Scheme 可被劫持 |
无 NSAppTransportSecurity | 低 | 使用默认 ATS(安全) |
LSApplicationQueriesSchemes | 信息 | 可探测已安装应用 |
ObjC 类信息提取
class-dump AppName > headers.h
grep -n "password\|token\|secret\|encrypt\|decrypt\|key" headers.h
otool -tV AppName | head -100
otool -oV AppName | head -100
Phase 2: 动态分析 (Frida/Objection)
Frida 基础操作
frida-ps -Uai
frida -U "AppName"
frida -U -f com.target.app
frida -U -f com.target.app -l hook.js
Objection 核心功能
objection --gadget "AppName" explore
env
ios hooking list classes
ios hooking list class_methods ClassName
ios nsuserdefaults get
ios keychain dump
ios cookies get --json
ios plist cat /path/to/file.plist
ios info binary
ios sslpinning disable
ios jailbreak disable
ios monitor crypt
ios ui biometrics_bypass
进程枚举与 Hook
动态分析目标?
├─ 数据存储审计 → Keychain dump + NSUserDefaults + Plist
├─ 网络流量分析 → SSL Pinning 绕过 + Burp 拦截
├─ 认证绕过 → Hook evaluatePolicy / 生物认证
├─ 加密算法审计 → ios monitor crypt
├─ URL Scheme 测试 → 构造 scheme:// URL 触发
└─ 内存分析 → 搜索敏感数据残留
Phase 3: 数据存储安全
存储位置全检查
数据存储审计清单?
├─ 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 是否正确设置?
实际操作
find /private/var/containers -name "AppName*" 2>/dev/null
cat .../Library/Preferences/com.target.app.plist
find .../ -name "*.sqlite" -or -name "*.db"
sqlite3 found.db "SELECT * FROM credentials;"
/usr/bin/keychain-dumper
ls .../Library/Caches/Snapshots/
grep -i "firebase" Info.plist
curl https://target.firebaseio.com/.json
Phase 4: 网络通信安全
Burp 配置(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 绕过
objection --gadget com.target.app explore -s "ios sslpinning disable"
frida -U -f com.target.app -l ios_ssl_bypass.js
Phase 5: URL Scheme / Universal Links
自定义 URL Scheme
grep -A 10 "CFBundleURLTypes" Info.plist
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
curl https://target.com/.well-known/apple-app-site-association
curl https://target.com/apple-app-site-association
Phase 6: 保护机制绕过
越狱检测绕过
越狱检测机制?
├─ 文件系统检查
│ ├─ /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 --gadget com.target.app explore -s "ios jailbreak disable"
frida -U -f com.target.app -l jailbreak_bypass.js
反调试绕过
反调试机制?
├─ 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 内存压力终止
└─ 心跳定时器延迟执行
生物认证绕过
objection --gadget com.target.app explore -s "ios ui biometrics_bypass"
frida -U -f com.target.app -l fingerprint_bypass.js
Phase 7: 其他检查项
补充检查清单?
├─ 键盘缓存 → /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 → 权限是否超出必要
自动化工具速查
| 工具 | 类型 | 用法 |
|---|
| MobSF | 静态+动态 | Docker 部署,上传 IPA |
| objection | 动态 | objection --gadget AppName explore |
| Frida | 动态 | frida -U -f com.target.app -l script.js |
| Keychain-Dumper | 数据提取 | 越狱设备直接运行 |
| class-dump | 静态 | class-dump AppName > headers.h |
| Malimite | 反编译 | GUI 工具,支持 Swift/ObjC |
| r2frida | 内存分析 | r2 frida://usb//AppName |
参考资源