This guide shows how to setup an Android VM in order to intercept all HTTPS requests. This was originally intended to reverse PlayServices but should work with any app that does not use certificate pinning (i.e. every app that relies on the system certificate authorities).
Inspired by this guide how to install Android x86 in VirtualBox, this guide how to install a system certificate on Android and this guide how to use mitmproxy with VirtualBox.
-
Download a recent Android x86 ISO from here.
-
Download a recent Kali Linux VirtualBox Image from here. (You can also use an other distribution, but Kali comes pre-installed with the tools we need)
-
Install VirtualBox and create a new VM:
-
Set Type to
Linuxand Version toLinux 2.6 / 3.x / 4.x (64-bit)(Linux 2.6 / 3.x / 4.x (2-bit)if you are using a 32-bit image). -
Select a reasonable amount of RAM (e.g. 3GB) and create a disk with enough space (e.g. 8GB).
-
Open the settings of your newly created VM.
-
Under
System>Processorincrease the number of CPUs to at least 2. -
Under
Display>Screenset the Graphics Controller toVBoxVGA. (You may also increase the Video Memory) -
Under
Network>Adapter 1select Attached toInternal Networkand enter a Name for the internal network (e.g.android).
-
-
Start the VM and install Android:
-
Select the android image you downloaded as your start-up disk
-
Choose
Installation. (Live CDwon't work for this tutorial as you cannot add a root certificate) -
Select
Create/Modify partitions. -
If you are asked if you want to use GPT, choose
No. -
Create a new partition by selecting
NewthenPrimaryand confirm the default size. -
Select
Bootableto mark the partition as bootable. -
Select
Writeto save the partition table thenQuitthe partitioning tool. -
Choose the newly created partition to install to.
-
Choose
ext4as filesystem and confirm withYes. -
Confirm installing the bootloader with
Yes. -
Install the /system directory as read-write by choosing
Yes. -
Reboot or start android. Make sure to disconnect the installation image.
-
-
Setup the VM for Kali Linux:
-
Import the Kali Linux OVA file (or your distribution of choice) into VirtualBox.
-
Open the settings of the imported VM and go to
Network. -
Under
Adapter 1choose attached toNAT. (Should be the default) -
Under
Adapter 2checkEnable Network Adapterand enter the same options as on the Android VM (e.g. Attached to:Internal Networkand Name:android). -
Start the VM and login with username
rootand passwordtoor. -
Install adb by running
apt install adbfrom command line. -
If you are not using Kali you may have to install
dnsmasqandmitmproxy, too.
-
-
Setup network forwarding in the Kali VM:
-
Run
nm-connection-editorfrom command line. -
Click on the
+at the bottom to add a connection and chooseEthernetas type. -
In the
Ethernettab set Device toeth1. -
In the
IPv4 Settingstab selectShared to other computersas Method. -
Click
Saveand close the connection editor.
-
-
Connect the Android VM:
-
Click
Start, thenSee all Wi-Fi networksand select theVirtWifinetwork. -
Once connected click the back arrow. You will be at the Wi-Fi selection screen again, where you can see the IP address.
-
Inside the Kali VM connect adb with
adb connect <IP>.
-
-
Install the SSL certificate in the Android VM:
-
Run
mitmproxyfrom command line and then quit it withq. This will generate a root certificate under~/.mitmproxy/. -
Calculate the hash of the certificate with
openssl x509 -in .mitmproxy/mitmproxy-ca.pem -subject_hash_old -nooutto use in the following commands. (This is most likelyc8750f0dfor this certificate) -
Convert it to the Android format:
cp .mitmproxy/mitmproxy-ca.pem c8750f0d.0 openssl x509 -text -in .mitmproxy/mitmproxy-ca.pem -text -noout >>c8750f0d.0 -
Copy the certificate to Android with
adb push c8750f0d.0 /data/local/tmp. -
Install it in the system and reboot:
adb shell su mv /data/local/tmp/c8750f0d.0 /system/etc/security/cacerts/ chown root:root /system/etc/security/cacerts/c8750f0d.0 chmod 644 /system/etc/security/cacerts/c8750f0d.0 reboot
-
-
Setup transparent proxying rules in iptables so every connection is forwarded to mitmproxy (you may need to adapt the interface name on other distributions):
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 8080 iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 443 -j REDIRECT --to-port 8080 -
Run
mitmproxy --mode transparent -w <name>.dumpto open an interactive session as well as write save the session into a dumpfile. -
You should now see every request made from the android device.
Perfect !