Skip to main content

ios-pentesting

iOS 应用渗透测试方法论。涵盖 IPA 静态分析(反编译/Plist分析/二进制检查)、动态分析(Frida/Objection/Cycript)、数据存储安全(Keychain/NSUserDefaults/CoreData)、网络通信安全、越狱检测绕过、URL Scheme 滥用。当 Agent 需要测试 iOS 应用安全、分析 IPA 文件、或绕过 iOS 保护机制时触发。

Quellinformationen

Repository
wgpsec/AboutSecurity
Letzte Quellaktivität
21. Mai 2026 um 09:17
Erkannte Sprache von SKILL.md
Chinesisch
Sterne
1.778
Forks
246

Installationsoptionen

Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.

Quelldateien prüfen

Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.

Datei-Explorer
3 Dateien

SKILL.md wird angezeigt

SKILL.md
Quellanweisungen · Schreibgeschützte Vorschau
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 → 保护机制绕过 ## 深入参考 - IPA 静态分析与二进制安全检查 → [references/ios-static-analysis.md](references/ios-static-analysis.md) - Frida/Objection 动态 Hook 与认证绕过 → [references/ios-frida-dynamic.md](references/ios-frida-dynamic.md) --- ## 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 获取 ```bash # 从越狱设备提取 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 静态分析 ### IPA 结构解析 ```bash # 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) ``` ### 二进制安全检查 ```bash # 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 ``` ### 不安全函数检查 ```bash # 弱哈希 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 审计 ```bash # 转为可读 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 ``` 关键检查项: | 配置 | 风险 | 影响 | |------|------|------| | `NSAllowsArbitraryLoads = true` | 高 | 禁用 ATS,允许 HTTP | | `CFBundleURLTypes` | 中 | URL Scheme 可被劫持 | | 无 `NSAppTransportSecurity` | 低 | 使用默认 ATS(安全) | | `LSApplicationQueriesSchemes` | 信息 | 可探测已安装应用 | ### ObjC 类信息提取 ```bash # 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: 动态分析 (Frida/Objection) ### Frida 基础操作 ```bash # 列出设备上的应用 frida-ps -Uai # 附加到运行中的应用 frida -U "AppName" # 以 spawn 模式启动 frida -U -f com.target.app # 使用脚本 frida -U -f com.target.app -l hook.js ``` ### Objection 核心功能 ```bash # 连接到应用 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 ``` ### 进程枚举与 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 是否正确设置? ``` ### 实际操作 ```bash # 定位应用目录(越狱设备 / 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: 网络通信安全 ### 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 绕过 ```bash # 方案 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 ### 自定义 URL Scheme ```bash # 从 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 ```bash # 检查 apple-app-site-association 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 相关检查函数 ``` ```bash # 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 插件) # 按应用启用越狱隐藏 ``` ### 反调试绕过 ``` 反调试机制? ├─ 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 内存压力终止 └─ 心跳定时器延迟执行 ``` ### 生物认证绕过 ```bash # 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: 其他检查项 ``` 补充检查清单? ├─ 键盘缓存 → /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` | --- ## 参考资源 - [OWASP MASTG - iOS Testing Guide](https://mas.owasp.org/MASTG/) - [HackTricks - iOS Pentesting](https://book.hacktricks.wiki/mobile-pentesting/ios-pentesting/) - [Frida Documentation](https://frida.re/docs/home/) - [Objection Wiki](https://github.com/sensepost/objection/wiki)
Auf GitHub ansehen