AVD - Android Virtual Device
Last updated
Last updated
Thank you very much to @offsecjay for his help while creating this content.
Android Studio allows to run virtual machines of Android that you can use to test APKs. In order to use them you will need:
The Android SDK tools - Download here.
Or Android Studio (with Android SDK tools) - Download here.
In Windows (in my case) after installing Android Studio I had the SDK Tools installed in: C:\Users\<UserName>\AppData\Local\Android\Sdk\tools
For MacOS machines I recommend you to install the following version to be able to use the CLI commands mentioned in the following sections:
If you installed Android Studio, you can just open the main project view and access: Tools --> AVD Manager.
Then, click on Create Virtual Device, select the phone you want to use and click on Next. In the current view you are going to be able to select and download the Android image that the phone is going to run:
So, select it and click on Download (now wait until the image is downloaded). Once the image is downloaded, just select Next and Finish.
The virtual machine will be created. Now every time that you access AVD manager it will be present.
In order to run it just press the Start button.
In MacOS systems the executable is located in /Users/<username>/Library/Android/sdk/tools/bin
First of all you need to decide which phone you want to use, in order to see the list of possible phones execute:
Once you have decide the name of the device you want to use, you need to decide which Android image you want to run in this device.
You can list all the options using sdkmanager
:
And download the one (or all) you want to use with:
Once you have downloaded the Android image you want to use you can list all the downloaded Android images with:
At this moment you have decided the device you want to use and you have downloaded the Android image, so you can create the virtual machine using:
In the last command I created a VM named "AVD9" using the device "Nexus 5X" and the Android image "system-images;android-28;google_apis;x86_64". Now you can list the virtual machines you have created with:
We have already seen how you can list the created virtual machines, but you can also list them using:
You can simply run any virtual machine created using:
Or using more advance options you can run a virtual machine like:
However there are a lot of different command line useful options that you can use to initiate a virtual machine. Below you can find some interesting options but can **[find a complete list here**](https://developer.android.com/studio/run/emulator-commandline)
-snapshot name
: Start VM snapshot
-snapshot-list -snapstorage ~/.android/avd/Nexus_5X_API_23.avd/snapshots-test.img
: List all the snapshots recorded
-dns-server 192.0.2.0, 192.0.2.255
: Allow to indicate comma separated the DNS servers to the VM.
-http-proxy 192.168.1.12:8080
: Allow to indicate an HTTP proxy to use (very useful to capture the traffic using Burp)
-port 5556
: Set the TCP port number that's used for the console and adb.
-ports 5556,5559
: Set the TCP ports used for the console and adb.
-tcpdump /path/dumpfile.cap
: Capture all the traffic in a file
-selinux {disabled|permissive}
: Set the Security-Enhanced Linux security module to either disabled or permissive mode on a Linux operating system.
-timezone Europe/Paris
: Set the timezone for the virtual device
-screen {touch(default)|multi-touch|o-touch}
: Set emulated touch screen mode.
-writable-system
: Use this option to have a writable system image during your emulation session. You will need also to run adb root; adb remount
. This is very useful to install a new certificate in the system.
First of all you need to download the Der certificate from Burp. You can do this in Proxy --> Options --> Import / Export CA certificate
Export the certificate in Der format and lets transform it to a form that Android is going to be able to understand. Note that in order to configure the burp certificate on the Android machine in AVD you need to run this machine with the -writable-system
option.
For example you can run it like:
Then, to configure burps certificate do:
Once the machine finish rebooting the burp certificate will be in use by it!
You can use the GUI to take a snapshot of the VM at any time: