Android Security Research
Android Security Research
0
February 2024
Authors:
We support a diverse portfolio of solutions and services for Defense, Intelligence, and Fortune
500 customers. Our team comprises analysts, support officers, and experienced engineers and
integrators with hands-on expertise across many of the most relevant COTS, GOTS, and open
source technologies. We also regularly compete in premier competitions with an increasing
number of conference wins and placements including IoT, Wireless and OSINT CTFs at DEF
CON, Wireless CTFs at BSides, Splunk Boss of the SOC and the Navy’s HACKtheMACHINE.
The following were awarded to Dark Wolf Solutions in the 2023 DEF CON 31 Capture the Flag
competitions in Las Vegas, Nevada:
We’ve created the Android Security Research Playbook (ASRP) as a getting started guide for
security researchers to follow, equipping them with the tools and processes to conduct their
research successfully. The ASRP isn’t all-inclusive of every tool, approach, or method that can
be employed; but, it provides recommendations for each stage of the process to help security
researchers progress with their research. The stages of the ASRP are summarized below.
Reconnaissance
The Reconnaissance phase consists of gathering information relevant to the target application,
understanding its overall purpose and capabilities, and then mapping out its attack surface.
Static Analysis
The Static Analysis phase allows us to utilize a wide array of open-source tools to dig deeper
into the design and implementation of our target application without the need to execute it. Tools
discussed include Android Studio, JADX, MobSF, and more.
Dynamic Analysis
The Dynamic Analysis phase lets us examine the runtime behavior of the target application.
Tools discussed include Frida, Objection, and more.
Vulnerability Discovery
The Vulnerability Discovery phase explores classes of vulnerabilities that can be found in a
target application, including both zero-day and N-day vulnerabilities.
Fuzzing
The Exploitation phase describes possible cyber effects that can be achieved by exploiting the
vulnerabilities identified, demonstrating the severity and impact of the vulnerabilities.
Hardware Recommendations
We recommend the following hardware for conducting Android security research.
Real Android Device (optional) Samsung or Google Pixel with Android 11+
Some of the Plays and tools described in the ASRP will require a rooted Android device.
Rooting is the process by which users of Android devices can attain privileged control (known
as root access) over various subsystems of the mobile device. Since Android is based on a
modified version of the Linux kernel, rooting an Android device gives similar access to
administrative (superuser) permissions as on Linux or any other Unix-like operating system.
Rooting is often performed to overcome limitations that carriers and hardware manufacturers put
on some devices. Thus, rooting gives the ability to alter or replace system applications and
settings, run specialized applications that require administrator-level permissions, or perform
other operations that are otherwise inaccessible to a standard user. It is worth noting that
rooting is distinct from SIM unlocking and bootloader unlocking. The former allows removing the
SIM card lock on a phone, while the latter allows rewriting the phone's boot partition.
Gaining root on a device is slightly different for each phone manufacturer and even model.
Therefore, when following the ASRP, we recommend using an Android emulator, since their
emulated devices are often rooted by default.
Emulation Software
For emulation, we recommend using Genymotion, Android Studio, or Corellium. All three of
these products provide the most up-to-date and relevant features for Android security research.
Genymotion provides a wide array of emulated sensors and features, as well as a fast startup
time for both booting and running applications on the emulated device. It does require setting
up an account and a license for professional use after a free trial on Linux and Windows.
Genymotion emulated devices are also rooted by default.
Android Studio is the official IDE for Google’s Android OS, but it also has an amazing
emulation feature built into it. This feature allows the user to create an AVD (Android Virtual
Device), and for each AVD the user can specify a hardware profile, system image, and more.
AVD images can be rooted using the following article.
Corellium provides a "Virtual Hardware Platform", which allows its users to emulate primarily
ARM-based devices with very high-fidelity. The interface is easy to use, and provides additional
hardware-specific features and capabilities than Genymotion and Android Studio. Corellium
emulated devices are also rooted by default.
Virtualization Software
VMware Workstation Pro lets you run multiple operating systems as virtual machines (VM) on
a single Windows or Linux computer. A paid license is required after its free trial. Here is a
tutorial on how to create an Ubuntu VM using VMware Workstation Pro.
VirtualBox is a free alternative to VMware Workstation Pro and comes bundled with
Genymotion; however, it does not come with nearly as many features. Here is a tutorial on how
to create an Ubuntu VM using VirtualBox.
Process ● Begin going through the list of compiled resources and summarize
the application’s history
● Make note of why the changes were made or introduced
Result ● An outline of the target’s history and evolution. This can be captured
in a text document, spreadsheet, or wiki page.
Process ● Utilize search engines and explore the Exploits & Advisories
section within the OSINT Framework
● Investigate the target’s bug/security tracking system, if applicable
● Document your findings
Process ● Search for the target APK on either one of the platforms above. This
will allow you to instantly download the latest version of the
application that is available on the Google Play Store.
Unset
$ apkid -r --scan-depth 4 target.apk
● For each classes.dex file, record any compiler, packers, and exploit
mitigations detected by APKiD, including:
○ Compiler Info - “R8 without marker”
○ Anti-Debug - detectDebugger(), isDebuggerConnected()
○ Anti-VM - Build checks, SIM checks, etc.
○ Packers - AppGuard, Dexprotector, etc.
Results ● A list of design decisions that could potentially affect target analysis.
⚠️Important⚠️
Obfuscators and packers used by the APK can prevent or hinder the static analysis process,
including reverse engineering (RE); therefore, we recommend defeating these protections by
completing the Anti-RE bypass play.
Unset
$ apktool d target.apk
Prerequisites ● Install JDK 11+ on your system (check with java -version).
○ Linux: $ sudo apt-get install openjdk-11-jdk
○ Windows: Download here
● Follow the JADX Build From Source instructions.
● Navigate to the /build/jadx/bin directory
Process ● Upload the Gradle project as a new project in Android Studio. Make
sure to account for which language it’s made in (Kotlin or Java), and
download any pertinent SDK files beforehand
● Verify that all of the original APK files are present by comparing the
file structure on the left with the file structure displayed in JADX.
● Open the drop down menu for main/
● Observe the file structure, and then document any useful locations
or patterns that appear to be present:
○ AndroidManifest.xml will likely be placed outside of any
folder structures. Document the activities listed in the file,
including their permissions and related source code folders.
○ res/ contains resource files in a variety of formats like .xml,
.webp, .gif, .json, etc.
○ assets/ can sometimes have the most variance depending
on the app, but will likely contain the visual content displayed
by the app
○ java/ or kotlin/ is where your source code will be, and
JADX will have attempted to deobfuscate any renaming due
to identifier remapping.
○ lib/ will contain any shared object library files, make note of
any file names that stand out or seem unnecessary for the
purposes of the app
○ Look for any classes.dex files floating in the main/
directory folder.
For supplemental analysis, you can use JADX or Ghidra to further review the APK’s file content.
Prerequisites ● Install Docker. For example, run the following Linux commands:
Unset
$ sudo apt install -y docker.io
$ sudo gpasswd -a $USER docker
$ sudo usermod -aG docker $USER
$ sudo reboot
● Pull down the MobSF Docker image per the repo’s instructions.
Unset
$ docker run -it --rm -p 8000:8000
opensecurity/mobile-security-framework-mobsf:latest
● Wait for the output to slow down and then open up the MobSF’s web
interface at http://127.0.0.1:8000 in a web browser.
● Drag the original APK file over to the “Upload & Analyze” screen on
the web page.
● Once MobSF finishes analyzing the application, save a copy of the
PDF report detailing its static analysis results.
Prerequisites ● Install JDK 17 64-bit by either going here or running the commands:
Unset
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install openjdk-17-jdk openjdk-17-jre
Results ● Areas of interest and potential vulnerabilities found within the APK’s
library files to further reverse engineer
⚠️Important⚠️
An APK may include security protections that can prevent or hinder the dynamic analysis
process; therefore, we recommend defeating these protections by completing the following
Plays first: APKiD, Anti-VM, Anti-Debugging, Root Detection, and Anti-RE.
GenyMotion Device:
● Obtain the IP address of your virtual device while it’s running,
● Connect to the emulated device: $ adb connect ip_address:port
● Verify that you are connected to the target device: $ adb devices
Unset
$ adb push frida-server /data/local/tmp
Unset
$ adb shell
$ su
$ setenforce 0
$ /data/local/tmp/frida-server -D &
$ setenforce 1
Unset
$ adb shell
$ /data/local/tmp/frida-server &
Prerequisites ● Frida server installed and running on target device (see this play)
● ADB installed and connected to the target device
● Install dependencies: $ sudo apt install python3 python3-pip
● Install Objection: $ pip3 install objection
Unset
$ sudo apt install npm
$ wget -qO-
https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/in
stall.sh | bash
$ source ~/.bashrc
$ nvm install v20.5.0
$ nvm use v20.5.0
$ npm install -g rms-runtime-mobile-security
Results ● Successfully observe, hook, and modify the apps runtime behavior.
Process ● In Burp Suite, go to the Proxy/Intercept tab. This will allow you to
intercept, modify, and pause any inbound/outbound requests.
● Interact with the target’s web server, its web applications, or a
general webpage to observe the target’s behavior.
○ For example, if the Android app is Chrome, open Chrome and
navigate to a web page.
● Confirm that the Burp Proxy works properly.
Results ● Successfully monitor and intercept web traffic using Burp Proxy
For more information on how to use Burp Proxy, we recommend reviewing its documentation.
The following article further describes how to enumerate applications on web servers.
Unset
$ ./gdbserver :1234 --attach <pid of app> &
Results ● Successfully perform remote debugging using GDB and GDB Server.
Vulnerability research can be performed manually or by using automated analysis tools. There
are different objectives for vulnerability discovery, such as to help make systems and software
more secure, or to develop capabilities in support of offensive cyber operations. This section
details several vulnerability classes to investigate during your security research. While running
through these plays, it is strongly suggested to analyze code for any banned functions.
The following article illustrates buffer overflow vulnerabilities and how they can be exploited.
The following article gives an example of an integer overflow and how it can be exploited.
The following article provides examples of UAF vulnerabilities and how to exploit them.
Process ● Analyze the code's logic, flow, and how it handles user interactions.
● Verify that authentication and authorization checks are correctly
implemented and consistently applied throughout the code.Look for
where access controls can be bypassed or incorrectly enforced.
● Check how user inputs are validated and sanitized to prevent
injection attacks. Examine how the code handles untrusted data.
● Analyze how the code validates and parses data from external
sources, such as files or network requests. Look for improper data
type conversions or assumptions.
● Examine how the application manages state transitions and handles
concurrency. Look for potential race conditions or inconsistencies in
the application's state.
The following article provides examples of logic bugs and their resulting consequences.
Process ● Search for the use of insecure formatting functions (e.g., sprintf)
● Identify user-controlled format strings (e.g., printf(user_input))
● Look for improper validation or sanitization
● Experiment with including format strings in user input (%s, %x, %n)
● Populate buffers with the maximum length of data to prevent null
characters from being appended.
The following article illustrates exploiting format string vulnerabilities in an Android app.
The following article describes abusing dynamic code loading in the Google Play Core Library.
The following article demonstrates improper input handling resulting in a buffer overflow.
Process ● Instrument programs for use with AFL/AFL++ (see their instructions)
● Create a corpus directory that holds the initial “seed” sample inputs
● Run the AFL/AFL++ fuzzer. For example:
Unset
$ ./afl-fuzz -i testcase_dir -o findings_dir --
/path/to/program @@
When source code is not available, AFL/AFL++ provides QEMU support for emulation. To utilize
this feature, run their build_qemu_support.sh script and make sure to export the necessary
Process ● Select your target function or library that you want to fuzz.
● Compile the vulnerable library program using clang and the flag
options –fsanitize=fuzzer,address.
● Develop your fuzzing harness using LLVMFuzzerTestOneInput().
● Compile your fuzzing harness with clang and link it to the object file
of the vulnerable program.
● (Optional) If using QEMU for cross-architecture support, export the
environment variables QEMU_LD_PREFIX and QEMU_SET_ENV.
● (Optional) Create a corpus directory that holds the initial “seed”
sample inputs
● Execute your fuzzer directly or by using QEMU
● Monitor fuzzer’s performance.
● Analyze crash results, if any.
● Tweak the fuzzer as necessary to improve its performance.
If you’re interested in using LibFuzzer, here is a detailed tutorial explaining how to use the tool.
Process There are two popular methods for bypassing stack canaries:
1. Leak the stack canary value
2. Bruteforce the stack canary value
Once obtained, the stack canary value can be incorporated into your exploit
to prevent an exception from occurring.
The following article provides an example of using ROP to bypass the XN mitigation on ARM.
Process ● Use the information leak to collect information about the memory
layout, such as the address of a LIBC function call (e.g., exit).
● Calculate the LIBC offset for the function pointer (e.g., exit)
● Subtract the offset from the function pointer to get the base address
of LIBC
● Identify the offset of another of LIBC function call (e.g., system)
● In your exploit, add this offset to the LIBC base address to
automatically reference the LIBC function call (e.g., system)
● Craft the rest of your exploit accordingly to achieve desired effect(s)
The following article provides an example of how to bypass Anti-VM checks for an Android app.
Prerequisites ● File editing software (An IDE or code editor like VS Code)
● APKiD output (see this play)
● Ability to communicate with the device via ADB (see this play)
● Ability to perform static analysis (e.g., JADX, Ghidra)
● Access to a debugger (e.g., GDB, GDB Server)
● Software that can hook functions running inside of a live Android
app (e.g., Objection, RMS, or Frida)
The following resources provide additional information and examples for deobfuscating and
unpacking Android applications:
● Android Deobfuscation – Part I
● Android Deobfuscation – Part II
● N Ways to Unpack Android Apps
Method #2:
● Analyze the APK in JADX and identify the root detection function.
● Then decompress the APK using APKTool and modify the SMALI
code corresponding to the root detection function accordingly.
The following article walks through different examples for bypassing root detections on Android.
To learn more about SELinux internals and policies, check out the following article.
Unset
$ keytool -genkeypair -v -keystore
your_keystore_name.keystore -keyalg RSA -keysize 2048
-validity 10000 -alias your_key_alias
● Use jarsigner to sign the APK. This command will prompt you to enter
the keystore password.
Unset
$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1
-keystore your_keystore_name.keystore your_app.apk
your_key_alias
● Use jarsigner to verify the signature of the APK. If the APK is signed
correctly, you will see a successful verification output.
Unset
$ jarsigner -verify -verbose -certs your_app.apk
● Note, if you are using Android Studio or another build tool, you may
have built-in options to sign your APK during the build process.
Process Since there are different ways to obtain an LPE effect, below are common
techniques and scenarios to consider for your target:
● DLL Hijacking
● Unpatched system/software
● Abusing named pipes
● Insecure configurations
● Kernel vulnerabilities
● Driver vulnerabilities
● Manipulating services running with higher privileges
● Insecure file permissions
● User input validation vulnerabilities
● Weak authentication mechanisms
● Weak, plaintext, or hard-coded passwords
● Use of Legacy or End-of-Life software
● Other software vulnerabilities
For more information on exploiting an Android vulnerability that can lead to an LPE, check out
this article. In addition, ARM provides documentation regarding Exception Levels that can also
be escalated for consideration.
The following article provides an example of achieving an RCE effect against an Android app.
Process Since there are different ways to obtain to defeat a PIN lock, below are
common techniques and scenarios to consider for your target:
● Brute Force attack
● PIN implementation weaknesses
● Weak, plaintext, or hard-coded PINs
● Directly invoking Activities that don’t require a PIN
Results ● Access to the device or mobile application without the need for a PIN
The following article provides an example of bypassing the lock screen on an Android device.
The following writeup walks through developing a zero-click exploit against an Android app.
Insecure credential management can occur when mobile apps use hardcoded credentials or
when credentials are misused. Supply chain vulnerabilities may arise if mobile applications are
developed by third-party developers or rely on third-party libraries. Insecure authorization can
occur when an organization fails to authenticate an individual before executing a requested API
endpoint from a mobile device. Insufficient validation and sanitization of data from external
sources can introduce severe security vulnerabilities. Insecure communication can allow
attackers to possibly intercept and modify data if it is transmitted in plaintext or using a
deprecated encryption protocol. Insecure privacy controls can lead to the disclosure of
personally identifiable information (PII). Insufficient binary protections make it easier for
attackers to reverse engineer or exploit a mobile app. Improper security configurations,
permissions, and controls can lead to vulnerabilities and unauthorized access. Insecure data
storage can result in potential privacy breaches and unauthorized access to sensitive data.
Insecure cryptography can undermine the confidentiality, integrity, and authenticity of sensitive
information. Keep in mind the OWASP Mobile Top 10 risks throughout the Android security
research process as they will likely be encountered while following and executing the ASRP.