Android Emulator Setup
Android:
ADB:
ADB = Android Debug Bridge
adb
consists of a client, a server, and a daemon (adbd
)client & server run on our computer, while the daemon runs on our device
Config:
For Windows:
First, you need to find where adb
is located on your computer. If you installed Android Studio with default settings, the adb tool is usually found in the C:\Users\[Your-Username]\AppData\Local\Android\Sdk\platform-tools directory
. Replace [Your-Username]
with your actual username.
Right-click on the Start button and select System.
Click on Advanced system settings on the left sidebar.
In the System Properties window, go to the Advanced tab and click on the Environment Variables button at the bottom.
Edit the Path Environment Variable: In the Environment Variables window, under the System variables section, find and select the Path variable, then click Edit.
In the Edit Environment Variable window, click New and paste the path to the
platform-tools
folder whereadb
is located.Click OK to close each of the open dialogs and apply the changes.
Commands:
root@sibi #~ adb devices
List down the devices connect to the system
root@sibi #~ adb shell
we will get the regular shell of the device
Specify the active device using the
s
parameter, for example:adb -s emulator-5554 shell
Specify to use a single USB device using the
d
parameter, for example:adb -d shell
Transfering files:
root@sibi#~ adb push <local_file_on_computer> <target_path_on_device>
root@sibi#~ adb pull <file_path_on_device> [<optional_target path_on_the_computer>]
Managing apps:
AM - Activity manager
PM - Package manager
Managing apps using adb
Using adb install we can manually install packages using the command line.
Lists all installed packages - including system packages.
List only third party packages.
Clear the application data without removing the actual application.
List information such as activities and permissions of a package.
Starts the activity of the specified package.
Uninstalls the specified application.
You can find the full documentation for pm here.
Logs with Logcat:
adb logcat
Change the log format - for example using brief
to get a more condensed version of the log.
Log Filtering
In some cases there can be lots of log entries which makes it hard to focus on the things that matter. For example if you are only interested in the logs produced by the MainActivity
, you can use a log filter for that:
Filter format:
MainActivity:V
ensures that logs from the tag MainActivity with a severity of Verbose and above are logged:S
Ensures that all other Tags are ignored (as nothing will log with log-level Silent or above)
Logging severities:
V
Verbose
D
Debug
I
Info
W
Warning
E
Error
F
Fatal
S
Silent
Android networking:
INTERNET Permissions
To be able to send HTTP requests or perform any other kind of network operation, the AndroidManifest.xml
must include the INTERNET
permission:
Cleartext Traffic
Generally Android tries to prevent developers from accidentally sending cleartext http://
traffic. But if developers explicitly declare usesCleartextTraffic=true
in the manifest or network security config, it is still possible.
Emulator start:
C:\Users\Rishivasan\AppData\Local\Android\Sdk\emulator\emulator.exe -tcpdump packets.cap -avd Pixel_8_API_29
Packet Logging with tcpdump
In order to capture packets you can look up the AVD id of your emulator and find the emulator
binary in the Android SDK installation. Then start the emulator with packet capture enabled:
The file packets.cap
will contain all raw packets sent and received by the Emulator - which obviously includes all app traffic as well.
C:\Users\Rishivasan\AppData\Local\Android\Sdk\emulator\emulator.exe -tcpdump C:\Users\Rishivasan\packets.cap -avd Pixel_8_API_30
Installing Certificate in System Store
Due to the default network security config rules, most apps only trust "system" certificates. The default configuration for apps targeting Android 9 (API level 28) and higher is as follows:
Rooted Device
In order to install our certificate into the system store, root access is required. Thus for this method you require a rooted physical phone, rooted emulator or use a non-Google emulator image that allows root access.
Install System Certificate
If you have a device with root access follow the following steps:
Install the proxy certificate as a regular user certificate
Ensure you are root (
adb root
), and execute the following commands inadb shell
:
In order to install our certificate into the system store, root access is required. Thus for this method you require a rooted physical phone, rooted emulator or use a non-Google emulator image that allows root access.
Install System Certificate
If you have a device with root access follow the following steps:
Install the proxy certificate as a regular user certificate
Ensure you are root (
adb root
), and execute the following commands inadb shell
:
Patching Network Security Config with apktool
We have used apktool before to unpack and repack an android app. So let's use it in order to inject a permissive network security config.
Advanced HTTP Interception with VPN
We are going to use an Android VPN service app in order to intercept traffic of apps, even when they ignore proxy settings.
For this purpose we can use the open source rethink app: https://github.com/celzero/rethink-app
Change DNS settings to "System DNS"
Add a HTTP(S) CONNECT proxy
Start the "VPN"
Also make sure you have your proxy certificate installed in the system certs store.
FRIDA:
To inject Frida into an APK we can use objection:
Objection will extract, patch, re-pack, align and sign the application, and so it's a very fast and easy way to get Frida running.
Note that the application will wait on launch for Frida to connect to it, so to start the application we have to run:
The -U
here specifies that we want to connect by USB.
If you have a rooted device, you can also run frida-server instead of patching the APK. You can download frida-server on the Github Releases Page of Frida. Note that it comes xz compressed, so you have to extract it (xz -d
on unixoid systems, 7zip on for example Windows).
To install it in an emulator we can adb push
the server over:
We chose this path because other parts, such as /sdcard
, are commonly mounted no-exec.
Afterwards we want to run adb as root, and also make the server executable:
And then we are ready to go: We can launch the server by running
Now we can connect to the application by running:
The Frida REPL (Read-Eval-Print-Loop) is a JavaScript interpreter, and so we can directly run JavaScript statements:
To create multi-line statements, suffix each line with a \
backslash:
Check-out the full Frida JavaScript API documentation here!
Also you can find the APK we use again here:
We can get JavaScript wrappers for Java classes by using Java.use
:
We can then instantiate those classes by calling $new:
We can dispose of instances (for example to free up memory) using $dispose()
, however this is almost never required, as the Garbage Collector should collect unused instances.
We can also replace the implementation of a method by overwriting it on the class:
In this video we create a script to trace the active Activity: