> For the complete documentation index, see [llms.txt](https://hacktricks.xsx.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacktricks.xsx.tw/mobile-pentesting/ios-pentesting/ios-universal-links.md).

# iOS Universal Links

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或 **关注**我们的**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

## 介绍

通用链接通过直接在应用中打开内容，绕过Safari重定向的需求，为用户提供了**无缝重定向**体验。这些链接是**独特**且安全的，因为其他应用无法声明它们。这是通过在网站的根目录上托管`apple-app-site-association` JSON文件来实现的，建立了网站和应用之间可验证的链接。在应用未安装的情况下，Safari将接管并将用户引导到网页，保持应用的存在。

对于渗透测试人员，`apple-app-site-association`文件尤为重要，因为它可能会揭示**敏感路径**，可能包括与未发布功能相关的路径。

### **分析关联域权利**

开发人员通过在Xcode的Capabilities选项卡中配置**关联域**或检查`.entitlements`文件来启用通用链接。每个域名都以`applinks:`为前缀。例如，Telegram的配置可能如下所示：

```xml
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:telegram.me</string>
<string>applinks:t.me</string>
</array>
```

### **获取苹果应用网站关联文件**

应从服务器使用在权限中指定的域检索`apple-app-site-association`文件。确保文件可以通过HTTPS直接访问，网址为`https://<domain>/apple-app-site-association`。工具如[苹果应用网站关联（AASA）验证器](https://branch.io/resources/aasa-validator/)可以帮助进行此过程。

### **处理应用中的通用链接**

应用必须实现特定方法来正确处理通用链接。要查找的主要方法是[`application:continueUserActivity:restorationHandler:`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623072-application)。处理的URL方案必须是HTTP或HTTPS，其他方案将不受支持。

#### **验证数据处理方法**

当通用链接打开应用时，将使用`NSUserActivity`对象将URL传递给应用。在处理此URL之前，必须验证和清理它以防止安全风险。以下是Swift中演示此过程的示例：

```swift
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// Check for web browsing activity and valid URL
if userActivity.activityType == NSUserActivityTypeBrowsingWeb, let url = userActivity.webpageURL {
application.open(url, options: [:], completionHandler: nil)
}

return true
}
```

URLs 应该被仔细解析和验证，特别是如果它们包含参数，以防止潜在的欺骗或格式不正确的数据。`NSURLComponents` API 对于这个目的非常有用，如下所示：

```swift
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let incomingURL = userActivity.webpageURL,
let components = NSURLComponents(url: incomingURL, resolvingAgainstBaseURL: true),
let path = components.path,
let params = components.queryItems else {
return false
}

if let albumName = params.first(where: { $0.name == "albumname" })?.value,
let photoIndex = params.first(where: { $0.name == "index" })?.value {
// Process the URL with album name and photo index

return true

} else {
// Handle invalid or missing parameters

return false
}
}
```

通过**勤奋的配置和验证**，开发人员可以确保通用链接提升用户体验的同时保持安全和隐私标准。

## 参考资料

* <https://mas.owasp.org/MASTG/tests/ios/MASVS-PLATFORM/MASTG-TEST-0070/#static-analysis>
* <https://mobile-security.gitbook.io/mobile-security-testing-guide/ios-testing-guide/0x06h-testing-platform-interaction#testing-object-persistence-mstg-platform-8>

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**上关注**我们。
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>
