隱含意圖盜用
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
OWASP 類別:MASVS-PLATFORM:平台互動
總覽
叫用意圖時,如果應用程式並未指定完整的元件類別名稱或套件,就會產生隱含意圖遭盜用的安全漏洞。這會讓惡意應用程式取代預期的應用程式,藉由註冊意圖篩選器的方式攔截意圖。
視意圖內容而定,攻擊者可能會讀取機密資訊,或是與可變動的物件互動,例如可變動的 PendingIntent 或 Binder。
影響
盜用隱含意圖後,攻擊者就能讀取或修改意圖內容,並且攔截要執行動作的意圖。這可能會導致像是機密資訊/資料外洩的後果,或啟動受攻擊者控制的元件。
因應措施
呼叫 setPackage()
建立明確意圖,如以下程式碼片段所示:
Kotlin
val intent = Intent("android.intent.action.CREATE_DOCUMENT").apply {
addCategory("android.intent.category.OPENABLE")
setPackage("com.some.packagename")
setType("*/*")
putExtra("android.intent.extra.LOCAL_ONLY", true)
putExtra("android.intent.extra.TITLE", "Some Title")
}
startActivity(intent)
Java
Intent intent = new Intent("android.intent.action.CREATE_DOCUMENT");
intent.addCategory("android.intent.category.OPENABLE");
intent.setPackage("com.some.packagename");
intent.setType("*/*");
intent.putExtra("android.intent.extra.LOCAL_ONLY", true);
intent.putExtra("android.intent.extra.TITLE", "Some Title");
startActivity(intent);
如果您需要使用隱含意圖,請刪除所有不應公開的機密資訊或可變動物件。如果應用程式無法確切瞭解將由哪個應用程式執行動作 (例如撰寫電子郵件、拍照等),就可能需要使用隱含意圖。
資源
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2024-01-05 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-01-05 (世界標準時間)。"],[],[],null,["# Implicit intent hijacking\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-PLATFORM: Platform Interaction](https://mas.owasp.org/MASVS/09-MASVS-PLATFORM)\n\nOverview\n--------\n\nThe [implicit intent](/guide/components/intents-filters#Types) hijacking vulnerability occurs when an application does\nnot specify a fully-qualified component class name or package when invoking an\nintent. This allows a malicious application to register an intent filter to\nintercept the intent instead of the intended application.\n\nDepending on the intent content, attackers could read or modify sensitive\ninformation or interact with mutable objects, such as [mutable](/reference/android/app/PendingIntent#FLAG_MUTABLE)\n[PendingIntents](/reference/android/app/PendingIntent) or [Binders](/reference/android/os/Binder).\n\nHijacking an implicit intent can also allow an attacker to perform arbitrary\nactions such as launching attacker-controlled components.\n\nImpact\n------\n\nIf an implicit intent handling sensitive data passes a session token within an\nextra URL string to open a WebView, any application specifying the proper intent\nfilters can read this token. This can allow any properly-configured application\non the device to intercept the intent and read the sensitive data within,\nallowing attackers to exfiltrate data such as PII or session tokens.\n\nMitigations\n-----------\n\nUnless the application requires it, make intents explicit by calling\n`setPackage()`. This allows the intent to be interpreted only by a specific\ncomponent (either in-app or from other applications), preventing untrusted\napplications from intercepting the data sent along with the intent. The\nfollowing snippet shows how to make an intent explicit: \n\n### Kotlin\n\n val intent = Intent(\"android.intent.action.CREATE_DOCUMENT\").apply {\n addCategory(\"android.intent.category.OPENABLE\")\n setPackage(\"com.some.packagename\")\n setType(\"*/*\")\n putExtra(\"android.intent.extra.LOCAL_ONLY\", true)\n putExtra(\"android.intent.extra.TITLE\", \"Some Title\")\n }\n startActivity(intent)\n\n### Java\n\n Intent intent = new Intent(\"android.intent.action.CREATE_DOCUMENT\");\n intent.addCategory(\"android.intent.category.OPENABLE\");\n intent.setPackage(\"com.some.packagename\");\n intent.setType(\"*/*\");\n intent.putExtra(\"android.intent.extra.LOCAL_ONLY\", true);\n intent.putExtra(\"android.intent.extra.TITLE\", \"Some Title\");\n startActivity(intent);\n\nIf you need to use implicit intents, omit any sensitive information or mutable\nobjects that you don't want to expose. Implicit intents may need to be used when\nan app does not have exact knowledge about which app will resolve the action\n(e.g. composing an email, taking a picture, etc.).\n\nResources\n---------\n\n- [Manifest intent-filter element](/guide/topics/manifest/intent-filter-element)\n- [Privileged Permission Allowlisting](https://source.android.com/devices/tech/config/perms-allowlist)\n- [Intents and Intent filters](/guide/components/intents-filters)\n- [Forcing chooser for implicit intents](/guide/components/intents-filters#ForceChooser)\n- [Common implicit intents](/guide/components/intents-common)"]]