Android Components
Components
Activities
They dictate the UI and handle the user interaction to the smartphone screen
Services
They handle background processing associated with an application.
Broadcast Receivers
They handle communication between Android OS and applications.
Content Providers
They handle data and database management issues.
Activity
An activity represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. If an application has more than one activity, then one of them should be marked as the activity that is presented when the application is launched
Services
A service is a component that runs in the background to perform long-running operations. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity
Broadcast Receivers
Broadcast Receivers simply respond to broadcast messages from other applications or from the system. For example, applications can also initiate broadcasts to let other applications know that some data has been downloaded to the device and is available for them to use, so this is broadcast receiver who will intercept this communication and will initiate appropriate action
An application can be registered to receive broadcasts occurred by system events such as BOOT COMPLETE, SMS RECEIVED, BATTERY LOW, etc. When an application is registered for an SMS RECEIVED event, its receiver will be invoked every time a new SMS is received.
Content Providers
A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. The data may be stored in the file system, the database or somewhere else entirely
One of the most important attributes of components is the exported property : android:exported
Whether or not the activity can be launched by components of other applications. “true” if it can be, and “false” if not. If “false”, the activity can be launched only by components of the same application or applications with the same user ID.The default value depends on whether the activity contains intent filters. The absence of any filters means that the activity can be invoked only by specifying its exact class name. This implies that the activity is intended only for application-internal use
Attacking Components
Download InsecureBankv2 : https://github.com/dineshshetty/Android-InsecureBankv2/blob/master/InsecureBankv2.apk
Download AndroLab Server : git clone https://github.com/dineshshetty/Android-InsecureBankv2.git
pip install -r requirements.txt
python app.py
Login
dinesh/Dinesh@123$
jack/Jack@123$
Exported Activity Exploit
Decompile the application : apktool d InsecureBank.apk -o insecure/
Explore the AndroidMainfest.xml file
We can see the activity
com.android.insecurebankv2.PostLogin
is exposed and the value set to true. This means, any application on the device can invoke this activityInvoke the activity using ADB
Invoke the activity using another application
Broadcast Receivers Exploit
Explore the AndroidMainfest.xml file
Let's explore the Java code in order to exploit this
Exploit using ADB
Content Providers Exploit
Application data is private to an application, hence it is not possible for an application to access another application’s data by default. When applications want to share their data with other applications, Content Provider is a way which acts as an interface for sharing data between applications. Content providers use standard insert(), query(), update(), and delete() methods to access application data. A special form of URI which starts with “content://” is assigned to each content provider. Any app which knows this URI can insert, update, delete, and query data from the database of the provider app.
The inbuilt SMS application in Android devices is a classic example of content providers. Any app can query the inbox from the device using its URI content://sms/inbox. But, READ_SMS permission must be declared in the app’s AndroidManifest.xml file in order to access the SMS app’s data.
Now, let's explore the AndroidMainfest.xml
We can see the provider
com.android.insecurebankv2.TrackUserContentProvider
is exportedExploring the java code reveal the content URI
Attack using ADB
Attack using another application ( Query Data )
Read files
Path Traversal
Another type of vulnerability that affects content providers (as well as services) is the directory traversal vulnerability.
If the app allows file reads without specifying permissions, other apps can exploit this vulnerability to read data from the vulnerable app.
Definition of Path Traversal
Directory traversal is a form of HTTP exploit in which a hacker uses the software on a Web server to access data in a directory other than the server's root directory. If the attempt is successful, the hacker can view restricted files or even execute commands on the server.
How Path Traversal impacts the Android O.S
Directory Traversal within Android, allows attackers to perpetrate a path traversal attack in the context of a user application and read files inside/outside internal storage.
Vulnerability Identification (Static Code Analysis)
in the case of the FileBrowser application, file operations are offered through the implementation of a content provider, that, given a URI, allows file access to the application itself (or to other applications). To do this, the content provider needs to implement the openFile method. Methods like query, insert, update, etc. are not suitable for these kinds of operations; obviously, they are best for interacting with databases.
When examining the FileBrowser application’s source code, you will identify that the application uses the openFile method as depicted below (accessfile.java).
Given a URI, the previous method will return a ParcelFileDescriptor file object. The application can then operate on this object to handle the file. It should be noted here that if the content provider is not well-implemented any application can request a file using this method by simply passing a URI.
After further examination you will identify how the application opens a file and reads its content (Content.java).
Vulnerability Exploitation
Path Traversal vulnerabilities can be exploited using he
../
charactersParsing URI with path traversal vulnerability
Read sample file and print the content
Last updated