23 October 2017

Android Emulator Recipe


When security testing an Android application, sometimes you'll want to do so from a PC that doesn't have the full development environment already installed.

Nota bene: if you wish to run the Android emulator within another virtual machine (such as VMware), you must first enable the host VM's option to virtualise VT-x/EPT, plus add an extra 2GB of memory and two more cores to cover the emulator’s requirements.

Install the Android command line tools [1] to C:\Users\%USERNAME%\AppData\Local\Android\Sdk\tools.

Create empty directories so the sdkmanager command line tools work:
mkdir C:\Users\%USERNAME%\AppData\Local\Android\Sdk\platforms
mkdir C:\Users\%USERNAME%\AppData\Local\Android\Sdk\platform-tools


Install the Intel HAXM engine [2].

Update the SDK tools
mkdir C:\Users\%USERNAME%\AppData\Local\Android\Sdk\tools.temp
xcopy /e C:\Users\%USERNAME%\AppData\Local\Android\Sdk\tools C:\Users\%USERNAME%\AppData\Local\Android\Sdk\tools.temp
C:\Users\%USERNAME%\AppData\Local\Android\Sdk\tools.temp\bin\sdkmanager --update
rd /s /q C:\Users\%USERNAME%\AppData\Local\Android\Sdk\tools.temp


Download the emulator system image (adjust version to suit needs):
C:\Users\%USERNAME%\AppData\Local\Android\Sdk\tools\bin\sdkmanager "system-images;android-23;default;x86"

Create the emulator virtual device (AVD):
C:\Users\%USERNAME%\AppData\Local\Android\Sdk\tools\bin\avdmanager --verbose create avd --force --name test --device "7in WSVGA (Tablet)" --package "system-images;android-23;default;x86" -b x86 -c 64M

Edit the AVD configuration file and enable the system keyboard:
notepad C:\Users\%USERNAME%\.android\avd\test.avd\config.ini
hw.keyboard = yes


Start the emulator (in this case routing all outbound web traffic through a proxy):
C:\Users\%USERNAME%\AppData\Local\Android\Sdk\emulator\emulator -avd test -verbose -skin 768x1280 -memory 2048 -netdelay none -netspeed full -gpu angle -no-audio -no-boot-anim -dns-server 8.8.8.8 -http-proxy http://proxy:8080

Install a MITM certificate into the emulator:
C:\Users\%USERNAME%\AppData\Local\Android\Sdk\platform-tools\adb -e root
C:\Users\%USERNAME%\AppData\Local\Android\Sdk\platform-tools\adb -e shell "mkdir -p /sdcard/Certificates/"
C:\Users\%USERNAME%\AppData\Local\Android\Sdk\platform-tools\adb -e push C:\Users\%USERNAME%\Desktop\cacert.cer /sdcard/Certificates/cacert.cer


Import the certificate by selecting settings, security, credentials, then install from SD card.

Install an application package into the emulator:
C:\Users\%USERNAME%\AppData\Local\Android\Sdk\platform-tools\adb -e install -r C:\Users\%USERNAME%\Desktop\application.apk

View the system log:
C:\Users\%USERNAME%\AppData\Local\Android\Sdk\platform-tools\adb logcat

References

  1. https://developer.android.com/studio/index.html
  2. https://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager-intel-haxm


No comments:

Post a Comment