The post Intent Spoofing on Android appeared first on Palomino Labs Blog.
Palomino Labs unlocks the potential of software to change people and industries. Our team of experienced software developers, designers, and product strategists can help turn any idea into reality. Check out our website for more information, or send us an email and let's start talking about how we can work together.
An Android application consists of a set of components of the following types:
ACTION_BATTERY_LOW
message from the system when the battery level drops below a certain threshold.Intents come into play here because they are the main mechanism for communication between components. (There’s actually a fourth type of component, namely content providers, but we’ll leave those aside because they do not use intents for communication.) Intents are used to start activities and services, bind to services, and convey notifications to broadcast receivers. By default, a component can only receive intents from other components in the same application, but it can be configured to accept intents from outside applications by setting the android:exported
attribute in the manifest.
An intent can be classified as one of two types based on how it is addressed. Explicit intents name the exact recipient of the message. Implicit intents do not name a recipient, and instead rely on the message being routed to an appropriate component based on the nature of the intent. A component registers to receive implicit intents by declaring an intent filter specifying the kinds of intents it can handle. Implicit intents are useful when you want to request a particular piece of functionality without having to specify exactly which component should provide that functionality. For example, the easiest way to allow the user to take a picture is to send an implicit intent with the MediaStore.ACTION_IMAGE_CAPTURE
intent action. A camera app capable of handling that action will receive it, allow the user to take a picture, and make the result available to the caller. If a camera app with extended features happens to be installed at run time, the user can opt to use that one instead of the standard Android camera app.
There are two main ways that the security of intents can be compromised:
For this post we’ll focus on intent spoofing attacks. A typical scenario is that the vulnerable application has a component which only expects to receive intents from other components of the same application. However, if the component is exported then any application can send intents to it. Often it isn’t even necessary to be particularly clever about crafting a malicious intent—since the vulnerable component doesn’t expect intents from other applications, it blindly trusts whatever it receives.
This is where a few disadvantages of implicit intents come into play. Although they offer a useful level of flexibility in run-time binding of components, they are frequently overused or used inappropriately, with negative consequences for security. A major problem with respect to intent spoofing is that registering an intent filter to receive implicit intents makes that component exported by default. This allows all applications to send intents to that component. Moreover, they don’t have to be implicit intents, and if they’re explicit then they don’t even have to match the intent filter. Ironically, creating an intent filter for a component greatly widens the scope of intents that Android will allow to be sent to it. Developers must not rely on intent filters for security, because these filters place no restrictions whatsoever on explicit intents.
Last year I worked with a team on an Android security research project, and as part of that we downloaded about 500 of the most popular Android apps on Google Play. In addition to performing some automated static analysis on them, we had a closer look at a random sample of twenty applications. We were able to crash fourteen of them by sending malformed intents and found that four of them appeared to expose functionality that was intended for internal use only. The most interesting one we looked at is what is now an old version of the PayPal app for Android.
Among other things, the app allows users to send money electronically to other PayPal users. With some investigation we found that one way this is done is by starting a component called SendMoneyActivity
in the PayPal app. The component appears to be intended solely for the internal use of the app, but nonetheless it declares an intent filter and is therefore exported by default.
Conveniently, Android has a utility called am
that makes it easy to construct and send intents interactively when you log into a device or emulator with adb shell
. With a bit of experimentation we were able to figure out how to send forged but valid intents to SendMoneyActivity
. Here’s an example:
am start \ -a android.intent.action.SENDTO \ -d mailto:adam@palominolabs.com \ --es com.paypal.android.p2pmobile.Amount 9.99 \ --ei com.paypal.android.p2pmobile.ParamType 42 \ -n com.paypal.android.p2pmobile/.activity.SendMoneyActivity
Here we specify:
android.intent.action.SENDTO
)mailto:adam@palominolabs.com
)ParamType
field that has to be non-null to satisfy the activity’s expectations of the inputThe result is that even though we have no special permissions, the activity opens with the recipient and dollar amount filled out and with the default payment method pre-selected. The only thing blocking this exploit is that the user must hit the “Send” button before the funds are transferred.
Although this flaw is not easily exploitable (and fortunately no longer appears to exist in current versions of the PayPal app), it is still remarkable that a finance-related application had an undocumented backdoor such as this one exposed to any unprivileged app on the device.
Here are a few recommendations on how to write Android apps that are safe from intent spoofing:
android:exported
for each component in your manifest. This eliminates the risk of having a component exported inadvertently if it declares an intent filter.Above all, it’s a good idea to remain vigilant about security and to always be aware that applications on a phone or tablet must co-exist with other apps that might not be trustworthy.
The post Intent Spoofing on Android appeared first on Palomino Labs Blog.
Palomino Labs unlocks the potential of software to change people and industries. Our team of experienced software developers, designers, and product strategists can help turn any idea into reality. Check out our website for more information, or send us an email and let's start talking about how we can work together.