# iOS Custom URI Handlers / Deeplinks / Custom Schemes

<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>

这是来自<https://mas.owasp.org/MASTG/tests/ios/MASVS-PLATFORM/MASTG-TEST-0075/>相关信息的摘要。

### 基本信息

自定义URL schemes使应用程序能够使用自定义协议进行通信，详细信息请参阅[Apple开发人员文档](https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html#//apple_ref/doc/uid/TP40007072-CH6-SW1)。这些方案必须由应用程序声明，然后处理遵循这些方案的传入URL。**验证所有URL参数**并**丢弃任何格式错误的URL**是至关重要的，以防止通过此向量进行攻击。

例如，URI `myapp://hostname?data=123876123` 调用特定应用程序操作。一个已知的漏洞出现在Skype移动应用程序中，允许通过`skype://`协议执行未经许可的呼叫操作。注册的方案可以在应用程序的`Info.plist`中的`CFBundleURLTypes`下找到。恶意应用程序可以通过重新注册URI来拦截敏感信息来利用这一点。

#### 应用程序查询方案注册

从iOS 9.0开始，要检查应用程序是否可用，`canOpenURL:`需要在`Info.plist`中的`LSApplicationQueriesSchemes`下声明URL方案。这限制了应用程序可以查询的方案为50个，通过阻止应用程序枚举来增强隐私保护。

```xml
<key>LSApplicationQueriesSchemes</key>
<array>
<string>url_scheme1</string>
<string>url_scheme2</string>
</array>
```

#### 测试URL处理和验证

开发人员应检查源代码中的特定方法，以了解URL路径的构建和验证，例如 `application:didFinishLaunchingWithOptions:` 和 `application:openURL:options:`。例如，Telegram 使用各种方法来打开URL：

```swift
func application(_ application: UIApplication, open url: URL, sourceApplication: String?) -> Bool {
self.openUrl(url: url)
return true
}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?,
annotation: Any) -> Bool {
self.openUrl(url: url)
return true
}

func application(_ app: UIApplication, open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
self.openUrl(url: url)
return true
}

func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
self.openUrl(url: url)
return true
}
```

#### 测试向其他应用程序发送URL请求

诸如 `openURL:options:completionHandler:` 这样的方法对于打开URL以与其他应用程序交互至关重要。在应用程序源代码中识别这些方法的使用对于理解外部通信至关重要。

#### 测试已弃用的方法

应该识别处理URL打开的已弃用方法，例如 `application:handleOpenURL:` 和 `openURL:`，并对其进行安全性影响审查。

#### 对URL方案进行模糊测试

对URL方案进行模糊测试可以识别内存损坏漏洞。像[Frida](https://codeshare.frida.re/@dki/ios-url-scheme-fuzzing/)这样的工具可以通过使用不同有效负载打开URL来自动化此过程，以监视崩溃情况，例如在 iGoat-Swift 应用程序中操纵URL。

```bash
$ frida -U SpringBoard -l ios-url-scheme-fuzzing.js
[iPhone::SpringBoard]-> fuzz("iGoat", "iGoat://?contactNumber={0}&message={0}")
Watching for crashes from iGoat...
No logs were moved.
Opened URL: iGoat://?contactNumber=0&message=0
```

### 参考资料

* <https://mas.owasp.org/MASTG/tests/ios/MASVS-PLATFORM/MASTG-TEST-0075/>

<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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/mobile-pentesting/ios-pentesting/ios-custom-uri-handlers-deeplinks-custom-schemes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
