Andriod Pentest Drozer
Andriod Pentest Drozer
Andriod Pentest Drozer
in Page | 1
TABLE OF CONTENTS
1 Drozer 4
1.1 Installation 4
1.2 Shell Command 10
1.3 Information Gathering on Device 11
1.4 Information Gathering on Packages 11
1.5 Debuggable Packages 13
1.6 Dumping AndroidManifest.xml File 14
1.7 Exploring Attack Surface of an Application 15
1.8 Exploiting Activities 16
1.9 Exploiting Content Providers 20
1.10 Exploiting Services 30
1.11 Exploiting Broadcast Receivers 32
2 About Us 35
www.hackingarticles.in Page | 2
www.hackingarticles.in Page | 3
Drozer
Drozer is an android application security testing framework developed by FSecureLABS that makes it
easy for a tester to create test cases and check for possible vulnerabilities in the components of an
application. It was formerly known as Mercury and has honorable mentions in much leading mobile
application security testing books as well. It is the de-facto standard for android application security
testing frameworks.
Features of Drozer are:
Installation
First, we need to install Python 2.7 and pip for Python 2.7. The direct method to install Python 2.7 and
pip for the same version was buggy and so the following method is a workaround for it. Many users
might get problems while doing this in recent versions of Kali Linux so we prefer doing this in Ubuntu
20.04 instead.
Note: If Drozer throws up an error sys.stderr.write(f””) method, you might need to manually copy
paste the latest get-pip.py file using the following command:
www.hackingarticles.in Page | 4
Next, we need to download the drozer agent for the phone’s latest release, and the pre-compiled
python builds wheel for the Drozer framework for Ubuntu. To do this:
www.hackingarticles.in Page | 5
Now, we need to install pip and build this wheel. To do this:
www.hackingarticles.in Page | 6
Now that everything is done and good to go, we’ll quickly check if Drozer had got installed or not
drozer
www.hackingarticles.in Page | 7
Let’s start the agent on the device. Notice the port mentioned down below that is the default port
drozer’s agent is 31415
Now that drozer agent is successfully installed, we need to connect drozer with it. For that, we’ll
forward the default port 31415 on the device to local port 31415.
adb forward tcp:31415 tcp:31415
drozer console connect
www.hackingarticles.in Page | 8
Now that drozer is up and running, we’ll first look at all the modules that drozer has. Below, you can
see all the various operations you can perform on activities, services, content providers, broadcast
receivers as well as some other scanners, information gathering modules, and exploits.
list
www.hackingarticles.in Page | 9
Shell Command
We can launch a shell on the device from within drozer console by:
shell
whoami
id
www.hackingarticles.in Page | 10
Information Gathering on Device
Drozer has a couple of modules to display date/time of the device and some other information on the
device as well
run information.datetime
run information.deviceinfo
run app.package.list
Further, to filter out the certain package we can apply the -f flag
www.hackingarticles.in Page | 11
To view information about an installed package, we run the app.package.info module:
www.hackingarticles.in Page | 12
Debuggable Packages
If a certain package is marked debuggable, we can inject our custom code in it while run-time and
modify its behaviour. For this we can manually check the manifest file for the string
“android_debuggable=”true”” or we can run the following drozer module:
run app.package.debuggable
www.hackingarticles.in Page | 13
Dumping AndroidManifest.xml File
To dump the manifest file of a package, we run the following command:
www.hackingarticles.in Page | 14
Exploring Attack Surface of an Application
One of the handiest features of Drozer is to identify the attack surface of an application. This module
will give us information on the attack surface of an android application. Android applications have 4
essential components that can be exploited along with the debuggable flag. This is known as an attack
surface. The following module highlights that out for two such applications we have installed:
www.hackingarticles.in Page | 15
Exploiting Activities
An application may have exported activities that can be launched remotely and bypass various kinds
of authentication mechanisms which the developer may have put on the class calling that activity. To
check for all the exported activity, we have the following command:
As you can see below, APICredsActivity has now been launched without any authentication
www.hackingarticles.in Page | 16
Exploiting Activities through intents:
In English, “intent” means “purpose”. Similarly, intents in Android refers to an abstract description of
an operation to be performed. Intents most importantly are used to start service, launch an activity,
broadcast message, dial a number etc. Intent itself, in android, is an object holding two main things:
• action
• data
There is a third parameter that can be added in an intent known as “extra.” This is better understood
through the means of code (ref from here):
Now, here we can see that action is “ACTION_SEND” (To send email)
Data is “mailto:”
And extra parameters define the recipients, subject and body of the e-mail.
Now, intents are also of two types:
Explicit intent: In this type of intent, a developer pre-defines the component or external class that has
to be called. For example,
Implicit intent: In this type of intent, a developer need not define which component executes an
instruction, rather, it pops open a window and lets the user choose which package would execute that
instruction. For example,
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.hackingarticles.com"));
startActivity(intent);
Here, we can see, the action is VIEW, data is a URL and there are no extras.
Hence, similarly in drozer, we can either:
• start an activity by specifying the component and it’s data to be executed or,
• we can define an action and data, and let the user choose which component would launch it.
www.hackingarticles.in Page | 17
For case 1, we try to launch hackingarticles.in on Chrome browser:
www.hackingarticles.in Page | 18
For case 2: we type the action we want to perform, in this case, the action is VIEW that refers to
parsing a URL. (For all actions see developer guide here)
And sure enough, all the applications that can launch the defined action with the defined data
parameter have now popped up and the user can choose which application to open it from.
A tester can also add an “extra” parameter which is analogous to “putExtra()” in android.
www.hackingarticles.in Page | 19
Exploiting Content Providers
Content Providers in Android help an application to access and manage data stored in its own SQLite
database or operate on files. Hence, two types of content providers are widely used namely, database-
backed and file-backed. They are standard interfaces that connect data in one process with code
running in another process. Hence, some applications can access the database/file-backed provider
running in your application through your content provider’s interface.
To extract information about content providers, present in one application:
Now, in the screenshot above, we see one such content provider that is being “exported” that means
nothing but “it can be accessed by other application”
There is also an interesting path revealed with permissions to read and write as well. There is a module
in drozer that scans and finds all the “queriable” content providers in an application. When we say
queriable, it means nothing but which can be accessed in layman terms.
The above command finds all the URIs that are present. The following command, however, filters out
the URIs that can be queried or not.
www.hackingarticles.in Page | 20
run scanner.provider.finduris -a com.mwr.example.sieve
Now that we have all the accessible content URIs, we’ll begin testing on them. The first command
displays the columns present in the provider, second command attempts operations on file-backed
content providers to read a certain file. Here, the provider is only supporting the database so we won’t
see any output. But this module can attempt directory traversal, read files etc on the providers that
do support files. The third command queries a database and dumps information out.
run app.provider.columns
content://com.mwr.example.sieve.DBContentProvider/Keys/
run app.provider.read
content://com.mwr.example.sieve.DBContentProvider/Keys/
run app.provider.query
content://com.mwr.example.sieve.DBContentProvider/Keys/
www.hackingarticles.in Page | 21
Inserting in a database using content provider:
Now, we know the provider’s database has to write permissions, so we’ll insert a new pin and
password into the provider with the following commands and hence, we will be able to successfully
bypass the front page login screen authentication:
run app.provider.insert
content://com.mwr.example.sieve.DBContentProvider/Keys/ --string pin 1111 -
-string Password H4ck3d
run app.provider.query
content://com.mwr.example.sieve.DBContentProvider/Keys/
www.hackingarticles.in Page | 22
You can verify the updated database by changing directory to /data/data/<package name>/databases
and then use sqlite3 command to view the databases.
run app.provider.update
content://com.mwr.example.sieve.DBContentProvider/Keys/ --selection
"Password=?" --selection-args H4ck3d --string pin 1769
run app.provider.query
content://com.mwr.example.sieve.DBContentProvider/Keys/
Here, –selection has the specific format of “<key name>=?” and further selection-args is used to
specify the argument for the specified selection key. Further, to update the record specified by the –
selection parameter, we use –string <column name> <updated record name>
Think of this like updating a traditional SQL database of the form: update set values <value> where
key=<some key>
www.hackingarticles.in Page | 23
Deleting from a database using provider:
We can delete from a database with the following command:
run app.provider.delete
content://com.mwr.example.sieve.DBContentProvider/Keys/ --selection
"Password=?" --selection-args H4ck3d
run app.provider.query
content://com.mwr.example.sieve.DBContentProvider/Keys/
Here, –selection and selection-args parameter serve the purpose of a key to be deleted as stated in
the previous screenshot’s explanation.
Now, to detect all the injectable content providers of an application we have a scanner that can do
the same thing using the following command:
www.hackingarticles.in Page | 24
Interesting things here to note are “projection” and “selection.”
As we have seen above, selection serves the purpose of where in the database. Similarly, projection
serves the purpose of what to select, as in “select <projection> from table where(<–selection> and <–
selection-args>)”
You can see this in the help menu:
www.hackingarticles.in Page | 25
To view all the SQL tables in the database of the server, we have a module in drozer:
run app.provider.query
content://com.mwr.example.sieve.DBContentProvider/Keys/ --projection "*
FROM SQLITE_MASTER where type=’table’;--"
www.hackingarticles.in Page | 26
Now, we know –selection is analogous to “where” clause. So, just like in traditional SQL statements,
an apostrophe would break the query and throw an error and so we were able to exploit SQL
injections. This way:
run app.provider.query
content://com.mwr.example.sieve.DBContentProvider/Keys/ --selection " ' "
The above command would break the query and we’d see an error. Now, the following command
would render the complete query as true and should dump the entire database
run app.provider.query
content://com.mwr.example.sieve.DBContentProvider/Keys/ --selection "1 or
1=1"
It is safe to say, many other of the traditional SQL injection payloads should also work this way using
content providers
www.hackingarticles.in Page | 27
Similarly, one more payload that we can try for fun is:
run app.provider.query
content://com.mwr.example.sieve.DBContentProvider/Keys/ --projection
"Password" --selection "1 or 1=1"
www.hackingarticles.in Page | 28
Now, this demonstration was about database-backed content providers. Let’s see another case of a
content provider where the application is working with files, instead of an SQLite database. The code
would be the same, except we won’t need selection, projection arguments for this.
In the sieve app, for example, we have a file backup provider that backs up various files from the
storage. Now, if an attacker was to use this provider’s interface to view internal system files, it would
be a critical vulnerability. In the following command, the same has been demonstrated:
run app.provider.read
content://com.mwr.example.sieve.FileBackupProvider/etc/hosts
Mitigation:
One possible mitigation for this security threat is not to use files using content providers but use a
subclass called File Provider. You can read more about its implementation here.
www.hackingarticles.in Page | 29
Exploiting Services
Services are often used to run code inside an application that is important to keep running, even when
the application is not in the foreground. Now, there is something called a bound service. They provide
a mechanism for applications on a device to interconnect directly with each other using remote
procedure calls (RPCs). An application can implement a bound service in three ways:
• Extending the Binder class
• Using a messenger
• Using AIDL
Implementation of AIDL is particularly difficult and complex (although, recommended) so most of the
developers rely on using a messenger. These messages are defined by the Message class. As part of a
Message object, a “message code,” which is defined as the what variable, is specified and compared
against predefined values in the class’s handler code to perform different actions according to this
value. Sending arbitrary objects inside the Message object that can be used by the receiving code is
also possible. However, there is no direct interaction with methods when using this technique.
For example, in sieve app we see a messenger service being implemented in the AuthService class.
www.hackingarticles.in Page | 30
Here, “message.what” is implemented using the check code of 2354 and an argument “arg1” that has
a code 9234 that returns a password. Now, we’ll exploit this and return a password associated with a
dedicated pin:
And we can see that the password with the pin 8080 is now returned. Any other msg arguments would
simply force the module to return garbage value.
The above demonstration is one example of exploiting services. We can also exploit service by creating
a custom APK, invoking vulnerable service in an existing application and reading from that service in
our own app. One example could be stealing a user’s location from an application that is exporting
location service. We’d cover exploiting services in detail in further articles.
www.hackingarticles.in Page | 31
Exploiting Broadcast Receivers
For this demonstration, we’ll be using an application called pivaa. The download link is available in the
introduction. It’s created by HTBridge. Let’s run a quick package scan first
Now, to display information about an installed application’s exported broadcast receivers we run the
following command:
Now, we see an exported receiver. On inspecting its source code we can see that the broadcast is
being sent with data and location parameters and the data is being written in a log file in the storage.
www.hackingarticles.in Page | 32
Note: Now, to perform the next experiment we suggest you do these on an older version of android.
Recent versions (Android Oreo +) are not allowing these attacks to be successful.
With that being said, we’ll now run the following command to invoke vulnerable receiver so-named
“service.vulnerable.vulnerableservice.LOG” that is mentioned in the code above with location and
data and see if the receiver actually writes our custom data in the log file or not.
Now, note.txt in the /tmp directory is a file that I had created just before running the above command.
Let’s first run logcat and see what had happened when I typed in the above command.
Sure enough, we see that the app has recently accessed the location /tmp/note.txt
adb shell
cd /tmp
cat note.txt
As we can see, the vulnerable receiver has received our forged command and written my custom data
in its log file. Now, we can exploit this vulnerability by inputting malicious payload here.
www.hackingarticles.in Page | 33
www.hackingarticles.in Page | 34
About Us
“Simple training makes Deep Learning”
We provide training and education in the field of Ethical Hacking & Information Security to the
students of schools and colleges along with the corporate world. The training can be provided at the
client’s location or even at Ignite’s Training Center.
We have trained over 10,000 + individuals across the globe, ranging from students to security experts
from different fields. Our trainers are acknowledged as Security Researcher by the Top Companies like
- Facebook, Google, Microsoft, Adobe, Nokia, Paypal, Blackberry, AT&T and many more. Even the
trained students are placed into a number of top MNC's all around the globe. Over with this, we are
having International experience of training more than 400+ individuals.
The two brands, Ignite Technologies & Hacking Articles have been collaboratively working from past
10+ Years with about more than 100+ security researchers, who themselves have been recognized by
several research paper publishing organizations, The Big 4 companies, Bug Bounty research programs
and many more.
Along with all these things, all the major certification organizations recommend Ignite's training for its
resources and guidance.
Ignite's research had been a part of number of global Institutes and colleges, and even a multitude of
research papers shares Ignite's researchers in their reference.
www.hackingarticles.in Page | 35
www.hackingarticles.in Page | 36
www.hackingarticles.in Page | 37