Intent Injection
Research taken from https://blog.oversecured.com/Android-Access-to-app-protected-components/****
Introduction
This vulnerability resembles Open Redirect in web security. Since class Intent
is Parcelable
, objects belonging to this class can be passed as extra data in another Intent
object.
Many developers make use of this feature and create proxy components (activities, broadcast receivers and services) that take an embedded Intent and pass it to dangerous methods like startActivity(...)
, sendBroadcast(...)
, etc.
This is dangerous because an attacker can force the app to launch a non-exported component that cannot be launched directly from another app, or to grant the attacker access to its content providers. WebView
also sometimes changes a URL from a string to an Intent
object, using the Intent.parseUri(...)
method, and passes it to startActivity(...)
.
As summary: If an attacker can send an Intent that is being insecurely executed he can potentially access not exported components and abuse them.
A typical case
Let us examine an example. Fragment of the AndroidManifest.xml
file
Activity ProxyActivity
Activity AuthWebViewActivity
AuthWebViewActivity
is an example of hidden app functionality that performs certain unsafe actions, in this case passing the user’s authentication session to a URL obtained from the url
parameter.
Export restrictions mean the attacker cannot access AuthWebViewActivity
directly. A direct call
throws a java.lang.SecurityException
, due to Permission Denial
: AuthWebViewActivity not exported from uid 1337
.
But the attacker can force the victim to launch AuthWebViewActivity
itself:
and no security violation will arise, because the app that is under attack does have access to all its own components. Using this code fragment, the attacker can bypass the Android system’s built-in restrictions.
Escalation of Impact
In order to escalate the impact of this vulnerability you need to find other vulns/missconfigurations that could allow to increate the impact of the vulnerability (as the vulnerability by it's own isn't creating any risks).
Escalation of attacks via Content Providers
Besides access to arbitrary components of the original app, the attacker can attempt to gain access to those of the vulnerable app’s Content Providers that satisfy the following conditions:
it must be non-exported (otherwise it could be attacked directly, without using the vulnerability we are discussing in this article)
it must have the
android:grantUriPermissions
flag set totrue
.android:grantUriPermissions="true"
indicates that your Java code can useFLAG_GRANT_READ_URI_PERMISSION
andFLAG_GRANT_WRITE_URI_PERMISSION
for anyUri
served by thatContentProvider
.android:grantUriPermissions="false"
indicates that only theUri
values specified by child<grant-uri-permission>
elements can be used withFLAG_GRANT_READ_URI_PERMISSION
andFLAG_GRANT_WRITE_URI_PERMISSION
.
The attacker must set itself as the recipient of an embedded intent and set the following flags
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
permits persistent access to the provider (without this flag, the access is one-time only)Intent.FLAG_GRANT_PREFIX_URI_PERMISSION
permits URI access by prefix – for example, instead of repeatedly obtaining separate access using a complete path such ascontent://com.victim.provider/image/1
the attacker can grant access to all the provider’s content using the URIcontent://com.victim.provider/
and then useContentResolver
to addresscontent://com.victim.provider/image/1
,content://com.victim.provider/image/2
, etc.Intent.FLAG_GRANT_READ_URI_PERMISSION
permits read operations on the provider (such asquery
,openFile
,openAssetFile
)Intent.FLAG_GRANT_WRITE_URI_PERMISSION
permits write operations
An example of a typical provider where an attacker can gain access to it and perform regular operations like query
, update
, insert
, delete
, openFile
, openAssetFile
Example of the theft of user pictures AndroidManifest.xml
file
MainActivity.java
file
LeakActivity.java
Attacks on Android File Provider
This vulnerability also makes it possible for the attacker to steal app files located in directories that the developer predetermined. For a successful attack, the malign app needs to obtain access rights to Android File Provider and then read content from the file provider using Android ContentResolver.
Example file provider (for more details see https://developer.android.com/reference/android/support/v4/content/FileProvider)
It provides read/write access to files on a special list that can be found in the app resources, in this case at res/xml/provider_paths.xml
It may look somewhat like
Each tag specifies a root directory with a path
value relative to the root. For instance, the value external_files
will correspond to new File(Environment.getExternalStorageDirectory(), "images")
The value root-path
corresponds to /
, i.e. provides access to arbitrary files.
Let us say we have some secret data stored in the file /data/data/com.victim/databases/secret.db
: the theft of this file may look something like this MainActivity.java
LeakActivity.java
Access to arbitrary components via WebView
An Intent object can be cast to a string with a call to Intent.toUri(flags)
and back from a string to an Intent using Intent.parseUri(stringUri, flags)
. This functionality is often used in WebView (the app’s built-in browser): the app can verify an intent://
scheme, parse the URL into an Intent and launch the activity.
This vulnerability can be exploited both via other vulnerabilities (e.g. the ability to open arbitrary links in-app in WebView directly via exported activities or by way of the deeplink mechanism) in the client app and also remotely, including cross-site scripting on the server side or MitM on the client side
Example of vulnerable code
The point here is that the shouldOverrideUrlLoading(...)
method of class WebViewClient
is called each time WebView tries to load a new link, but gives the app the option of adding a custom handler.
To exploit this vulnerability the attacker needs to create a WebView redirect to a specially prepared intent-scheme URL. Example of URL creation
Example attack
This version contains several restrictions compared to the classic version of the vulnerability:
Embedded
Parcelable
andSerializable
objects cannot be cast to string (they will be ignored)The insecure flags
Intent.FLAG_GRANT_READ_URI_PERMISSION
andIntent.FLAG_GRANT_WRITE_URI_PERMISSION
are ignored whenIntent.parseUri(...)
is called. The parser will only leave them if theIntent.URI_ALLOW_UNSAFE
(startActivity(Intent.parseUri(url, Intent.URI_INTENT_SCHEME | Intent.URI_ALLOW_UNSAFE))
flag is set, which is very rare
Many developers still forget to carry out a complete filtering of intents received via WebView
The attacker can specify a non-exported component via a selector
And bypass the app’s protection against explicit intents. We therefore recommend filtering the selector as well
But even complete filtering does not guarantee complete protection, because an attacker can create an implicit intent corresponding to the intent-filter
of some non-exported activity. Example of an activity declaration:
We therefore recommend checking that an activity is exported before it is launched.
Other ways of creating insecure intents
Some app developers implement their own intent parsers (often to handle deeplinks or push messages), using e.g. JSON objects, strings or byte arrays, which either do not differ from the default or else present a great danger, because they may expand Serializable
and Parcelable
objects and they also allow insecure flags to be set. The security researcher may also encounter more exotic versions of intent creation, such as casting a byte array to a Parcel
and then reading an intent from it
Vuln app
Last updated