Over the past few weeks, I have been fortunate to attend Cyber Skills Level Up 1 & 2, hosted by @RE:HACK at UIA and also UM. Throughout the event, I learned a lot of new stuff, but what caught my attention the most was Introduction to Android by @Kelvin Teo. Since I have a memory like a goldfish, I think it would be great to start making write-ups/notes for this kind of workshop.

Init

First of there are a couple of initial setups that you need to do in order to run AVD (Android Virtual Device) in your machine and getting full control of your device, which consist of:-

  1. Downloading a new AVD
  2. Rooting AVD
  3. Setting up a proxy on AVD

Downloading AVD

If you have downloaded Android Studio before on your machine, it should come with a tool called Android Emulator. It helps you create your own AVD. Feel free to select the type of phone and system image that you want to use. Personally, I choose Pixel 7 Pro with API 27 as my AVD.

Now that you created one emulator, you can turn it on using Android Studio or just use the command prompt instead. To turn it on using command prompt, follow the steps:-

  1. Go to this path C:/Users/{your username}/AppData/Local/Android/Sdk/emulator
1
cd C:/Users/{your username}/AppData/Local/Android/Sdk/emulator
  1. List all AVD installed on your machine
1
emulator.exe -list-avds
  1. Run your AVD
1
emulator.exe -avd "Name of your AVD"

Rooting AVD

This brings back a lot of memories. When I was a kid, I used to do this all the time in my old tablet to cheat/hack in mobile games. I remember there was a mobile application that was quite similar to cheat engine, forgot what it was called though, but you needed to root your device in order to use the application.

Back then, I didn’t really know what rooting did to your device though. Apparently, it is used to:-

  • Setup proxy
  • Install and execute of custom scripts
  • Test applications

Comparing it to non-rooted devices:-

  • Limited capability to test applications
  • Only trust third-party certificate at a user-level

How to root?

Just use rootAVD, a script that is capable of rooting your AVD using Magisk automatically within seconds.

  1. Clone it on your machine
1
git clone https://github.com/newbit1/rootAVD.git
  1. Get into the rootAVD directory and run rootAVD executables/shell
1
2
cd rootAVD
rootAVD.bat
  1. List all AVDs that can be rooted
1
rootAVD.bat listAllAVDs
  1. Make sure your AVD is running and run the root script by using the ramdisk.img file of your AVD
1
rootAVD.bat {your system-images path}/ramdisk.img
  1. Reboot your AVD

  2. Run Magisk & reboot again

  3. Your device is rooted!

Setting up proxy

Here is the most difficult part for me. I hate setting up proxies.

There are 3 packages that you need to install/import in your AVD

  • MagiskFrida
  • PlayIntegrityFix
  • AlwaysTrustUserCert

After you have installed, every one of the packages, reboot your AVD.

Now it’s time to boot up your BurpSuite and go to Tools > Proxy

After that, add new proxy listeners to your host machine IP, you can find it using ipconfig command in terminal for windows. Also, use any available port; in this case I’m using port 9000

Now you need to manually set up the proxy on AVD, go to wifi settings and choose AndroidWifi > Modify Network

Then add your proxy listeners IP and port

Go to chrome and visit https://burp to download the CA cert, then rename your cert to .cer instead of .der

Now go to Settings > Security > Encryption & Credentials > Install a certificate to download CA cert, then reboot your device

Go back to Chrome and try to browse YouTube and verify the communication can be intercepted by the proxy

Now that everything is perfectly set up, we can use this to learn SSL Bypass

SSL Bypass

Usually, security researchers come across a problem when they are trying to test Android Applications because they can’t bypass SSL Pinning using conventional tools/techniques

What is SSL Pinning?

SSL pinning is a security technique used to prevent man-in-the-middle (MiTM) attacks (such as proxies) by ensuring that an application only trusts a specific certificate or public key, rather than any certificate issued by trusted Certificate Authorities (CAs).

This adds an extra layer of security by binding (“pinning”) the application to a known and trusted certificate or public key.

How to bypass it?

When the client has a 3rd party certificate to perform a MiTM attack, the communication channel will not happen. Therefore in order to bypass it here are the steps:-

  1. Install frida in your host machine
1
2
pip3 install frida
pip3 install frida-tools
  1. Install frida-server in your AVD, and run it
1
2
3
adb.exe push frida-server-16.0.10-android-x86 /data/local/tmp/frida-server
adb.exe shell "chmod 755 /data/local/tmp/frida-server"
adb.exe shell "/data/local/tmp/frida-server &"

Or you can just straight away go to the directory and run ./frida-server

  1. To verify that Frida is working, first check the process that is currently running in AVD
1
frida-ps -U
  1. Finally you can test SSL Pinning bypass by using one of this demo application made by @pimterry

  2. Initially without intercepting the communication using proxy, every pinned request is allowed since there is no suspected MiTM attack

  1. After that, when proxy is turned on, most of the types pinned request got rejected
  1. In order to bypass all this pinned request use one of this script in frida, to run it, in your host machine use this command
1
frida -U --codeshare KaiserBloo/ssl-and-root-bypass -f package_name

the package name can be retrieved by running this command

1
frida-ps -U -a
1
2
3
4
5
6
7
8
9
10
11
12
  PID  Name              Identifier
----- ---------------- ---------------------------------------
13456 Calendar com.google.android.calendar
19294 Chrome com.android.chrome
16371 Clock com.google.android.deskclock
12800 Google com.google.android.googlequicksearchbox
12800 Google com.google.android.googlequicksearchbox
17151 Magisk com.topjohnwu.magisk
18188 Phone com.google.android.dialer
13393 Photos com.google.android.apps.photos
19555 SSL Pinning Demo tech.httptoolkit.pinning_demo
14859 YouTube com.google.android.youtube
1
frida -U --codeshare KaiserBloo/ssl-and-root-bypass -f tech.httptoolkit.pinning_demo

Make sure you add the parameter -U if not this process will not be working since it will run it in your local system instead of your emulator

1
2
3
4
5
6
7
8
9
10
11
12
     ____
/ _ | Frida 16.3.3 - A world-class dynamic instrumentation toolkit
| (_| |
> _ | Commands:
/_/ |_| help -> Displays the help system
. . . . object? -> Display information about 'object'
. . . . exit/quit -> Exit
. . . .
. . . . More info at https://frida.re/docs/home/
. . . .
. . . . Connected to Local System (id=local)
Failed to spawn: unable to find executable at 'tech.httptoolkit.pinning_demo'

As you can see now, there are a couple of pinned request that can be by passed