iOS Universal Links

Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks

Introduction

유니버설 링크는 사용자가 Safari 리디렉션을 우회하여 앱에서 직접 콘텐츠를 열 수 있도록 하여 매끄러운 리디렉션 경험을 제공합니다. 이러한 링크는 고유하고 안전하며, 다른 앱에서 주장할 수 없습니다. 이는 웹사이트의 루트 디렉토리에 apple-app-site-association JSON 파일을 호스팅하여 웹사이트와 앱 간의 검증 가능한 링크를 설정함으로써 보장됩니다. 앱이 설치되지 않은 경우 Safari가 사용자에게 웹페이지로 안내하여 앱의 존재를 유지합니다.

침투 테스터에게 apple-app-site-association 파일은 민감한 경로를 드러낼 수 있기 때문에 특히 관심이 있습니다. 여기에는 출시되지 않은 기능과 관련된 경로가 포함될 수 있습니다.

연관 도메인 권한 분석

개발자는 Xcode의 Capabilities 탭에서 연관 도메인을 구성하거나 .entitlements 파일을 검사하여 유니버설 링크를 활성화합니다. 각 도메인은 applinks:로 접두사가 붙습니다. 예를 들어, 텔레그램의 구성은 다음과 같이 나타날 수 있습니다:

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

더 포괄적인 통찰력을 원하시면 보관된 Apple Developer Documentation을 참조하세요.

컴파일된 애플리케이션을 사용하는 경우, 이 가이드에 설명된 대로 권한을 추출할 수 있습니다.

Apple App Site Association 파일 가져오기

apple-app-site-association 파일은 권한에 지정된 도메인을 사용하여 서버에서 가져와야 합니다. 파일이 https://<domain>/apple-app-site-association에서 HTTPS를 통해 직접 접근 가능해야 합니다. Apple App Site Association (AASA) Validator와 같은 도구가 이 과정에 도움이 될 수 있습니다.

앱에서의 유니버설 링크 처리

앱은 유니버설 링크를 올바르게 처리하기 위해 특정 메서드를 구현해야 합니다. 주목해야 할 주요 메서드는 application:continueUserActivity:restorationHandler:입니다. 처리되는 URL의 스킴이 HTTP 또는 HTTPS여야 하며, 다른 스킴은 지원되지 않습니다.

데이터 핸들러 메서드 검증

유니버설 링크가 앱을 열면, NSUserActivity 객체가 URL과 함께 앱에 전달됩니다. 이 URL을 처리하기 전에 보안 위험을 방지하기 위해 이를 검증하고 정리하는 것이 필수적입니다. 다음은 이 과정을 보여주는 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는 이를 위해 유용하며, 아래에 설명되어 있습니다:

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

Through 부지런한 구성 및 검증, developers can ensure that universal links enhance user experience while maintaining security and privacy standards.

Tools

  • GetUniversal.link: Helps simplify the testing and management of your app's Universal Links and AASA file. Simply enter your domain to verify AASA file integrity or use the custom dashboard to easily test link behavior. This tool also helps you determine when Apple will next index your AASA file.

References

Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks

Last updated