CobraDroid

Jake Valletta

BruCON 0x05 · Day 1

Overview

In this talk from BruCON, Jake Valletta introduces CobraDroid, a custom-built Android emulator image designed to significantly enhance dynamic analysis capabilities for Android applications. Recognizing a gap in robust tools for dynamic analysis compared to the mature landscape of static analysis, Valletta developed CobraDroid to provide security researchers, malware analysts, and curious users with a powerful platform to inspect, manipulate, and understand application behavior in a controlled environment. The project aims to overcome common hurdles encountered during mobile application assessments, such as device identification checks, SSL certificate pinning, and the overwhelming noise of untargeted network traffic.

Watch on YouTube

Visual summary for CobraDroid by Jake Valletta
Visual summary for CobraDroid by Jake Valletta

Key moments

  1. 2:00 Introduction to CobraDroid and dynamic analysis needs
  2. 8:00 CobraDroid: A modified Android emulator environment
  3. 12:00 Faking device identifiers and build properties
  4. 17:00 Bypassing SSL pinning for traffic analysis
  5. 20:00 Isolating and capturing specific application network traffic
  6. 21:00 Dalvik method hooking for runtime analysis
  7. 32:00 Live demo: Bypassing app checks and analyzing traffic
  8. 46:00 Future plans and audience Q&A

CobraDroid

Speakers: Jake Valletta

Conference: BruCON

YouTube: https://www.youtube.com/watch?v=ZcupwSdKNss

Overview

In this talk from BruCON, Jake Valletta introduces CobraDroid, a custom-built Android emulator image designed to significantly enhance dynamic analysis capabilities for Android applications. Recognizing a gap in robust tools for dynamic analysis compared to the mature landscape of static analysis, Valletta developed CobraDroid to provide security researchers, malware analysts, and curious users with a powerful platform to inspect, manipulate, and understand application behavior in a controlled environment. The project aims to overcome common hurdles encountered during mobile application assessments, such as device identification checks, SSL certificate pinning, and the overwhelming noise of untargeted network traffic.

CobraDroid operates by providing a modified Android build that integrates several key features: an upgraded kernel, a more functional user-space shell, spoofing mechanisms for device properties, sophisticated SSL bypass capabilities, targeted network traffic capture, and, most notably, a novel Dalvik method hooking framework. These features collectively enable a deeper and more precise understanding of how Android applications interact with the system, network, and user data. The talk emphasizes how CobraDroid transforms the often-tedious process of dynamic analysis into a more efficient and insightful exercise, allowing testers to focus on critical application logic rather than wrestling with environmental constraints.

Background

▶ Watch: Introduction to CobraDroid and dynamic analysis needs (2:00)

The landscape of Android application security analysis typically involves two primary phases: static and dynamic. Static analysis involves examining an application's code without executing it, for which a plethora of robust tools exist—disassemblers, decompilers, and code review platforms. This allows analysts to understand an application's structure, identify potential vulnerabilities, and reverse-engineer obfuscated logic. However, static analysis often falls short in revealing runtime behavior, interactions with the operating system, or network communications under specific conditions.

Dynamic analysis, on the other hand, involves observing an application as it executes. While crucial for a comprehensive security assessment, dynamic analysis for Android has historically lacked the sophisticated tooling available for static analysis. Existing solutions often involve generic sandboxes that provide high-level summaries but lack the granular control and flexibility needed for in-depth investigations. Furthermore, standard Android emulators present several limitations for security testing: they run on an outdated kernel (Goldfish 2.6.29 from 2008), offer a highly restricted shell (a subset of k-shell with no history, completion, or editors), and lack features necessary for advanced network manipulation. Applications often implement checks for device properties (e.g., model, manufacturer, IMEI, IMSI) or enforce SSL certificate pinning to prevent man-in-the-middle attacks, rendering standard proxying ineffective. These challenges necessitate manual, often time-consuming, modifications to applications or the testing environment, hindering efficient dynamic analysis. CobraDroid was conceived to directly address these pain points, providing a purpose-built platform that streamlines and enhances the dynamic analysis workflow.

Key Findings

▶ Watch: Faking device identifiers and build properties (12:00)

CobraDroid's core contribution lies in its comprehensive approach to dynamic Android application analysis, integrating several key modifications into a custom emulator image. The project successfully demonstrates:

  • Enhanced Emulator Base: By building upon Android 2.3 (Gingerbread) and upgrading the kernel to Linux 3.0 (Honeycomb-era), CobraDroid provides a more modern and feature-rich foundation. This kernel upgrade specifically enables crucial netfilter extensions, which are foundational for advanced network manipulation.
  • Improved User Experience for Analysts: The integration of BusyBox and Bash significantly elevates the emulator's command-line interface, providing essential tools like vi/emacs, colorized output, command history, and tab completion. This transforms the previously restrictive shell into a powerful environment for on-device analysis.
  • Robust Device Property Spoofing: CobraDroid implements novel techniques to spoof critical device identifiers and build properties. By rewriting the TelephonyManager class and manipulating the loading of build.prop values, applications can be made to believe they are running on a specific device model, carrier, or with arbitrary device IDs, bypassing common anti-tampering checks.
  • Seamless SSL Pinning Bypass: A major finding is the ability to bypass most forms of SSL pinning and hostname verification by modifying the core SSL libraries. CobraDroid alters the constructors and setHostnameVerifier methods of these libraries, effectively disabling security checks without the application's knowledge. This allows for transparent proxying of encrypted traffic, even when applications use strict pinning.
  • Granular Network Traffic Capture: Leveraging the upgraded kernel's netfilter capabilities, CobraDroid enables the capture of network traffic only from specified applications. This significantly reduces noise in packet captures, allowing analysts to focus precisely on the communications relevant to the target application.
  • Advanced Dalvik Method Hooking: The most significant technical contribution is a sophisticated method hooking framework that instruments Dalvik bytecode during class loading. This allows analysts to define specific methods (system or application-specific) to monitor. When a hooked method is called, CobraDroid can trigger custom actions, such as logging detailed information, even for obfuscated method names, providing deep insight into application behavior at a bytecode level.

These findings collectively establish CobraDroid as a powerful, integrated platform that addresses critical shortcomings in existing Android dynamic analysis tools, enabling more efficient and in-depth security assessments.

Technical Deep Dive

▶ Watch: Isolating and capturing specific application network traffic (20:00)

CobraDroid is fundamentally a modified Android emulator image, built from the Android Open Source Project (AOSP) to incorporate several critical enhancements. The base system uses Android 2.3 Gingerbread, chosen because it was prevalent for malware analysis at the time of development, though future plans include upgrading to newer versions like Ice Cream Sandwich or Jelly Bean.

Kernel and User Space Enhancements

At the lowest level, the stock Android emulator ships with a very old Goldfish kernel (Linux 2.6.29), dating back to 2008. CobraDroid upgrades this to Linux 3.0, which aligns with Android 3.0 Honeycomb. This upgrade was crucial for enabling specific kernel features, particularly xtables extensions for netfilter, which are essential for advanced network traffic manipulation. The kernel configuration was also tweaked to enable multiple kernel modules and additional netfilter states.

In user space, the default Android shell is notoriously limited. CobraDroid addresses this by porting BusyBox and Bash to the emulator. BusyBox provides a suite of common Unix utilities in a compact form, while Bash offers a fully featured shell experience with command history, tab completion, colorized output, and support for pipes and redirection. This significantly improves the analyst's ability to interact with the device and perform on-device forensics or scripting.

Device Property Spoofing

Applications often perform checks based on device properties to determine if they are running on a legitimate device or to tailor functionality. CobraDroid implements two key mechanisms for spoofing these:

  1. Telephony Manager Spoofing: The android.telephony.TelephonyManager class is responsible for querying radio-related information like device ID (IMEI), subscriber ID (IMSI), and line one number. CobraDroid modifies this class to read these values from a user-controlled file instead of querying the actual radio interface. This allows analysts to define arbitrary values for these identifiers.
  2. Build Properties Spoofing: Device build properties (e.g., ro.product.model, ro.product.manufacturer) are stored in /etc/build.prop, a read-only file read at boot. CobraDroid employs a clever trick: it removes the library initialization for build.prop from the zygote process. The zygote is the main process from which all Android applications fork. By delaying this initialization, the SystemProperties class (which holds these values) is not populated until each application starts. At this point, CobraDroid hooks the SystemProperties class to return arbitrary, user-defined values from a custom build.prop file, effectively spoofing the device model, manufacturer, and other parameters on an application-specific basis.

SSL Bypass

SSL certificate pinning and strict hostname verification are common security measures that prevent man-in-the-middle attacks by ensuring applications only trust specific server certificates or hostnames. These mechanisms typically break standard proxying tools like Burp Suite. CobraDroid bypasses these protections by directly modifying the SSL libraries within the Android framework.

The approach involves changing the constructors of SSL-related classes and rewriting methods like setHostnameVerifier. When an application calls setHostnameVerifier to set a secure verifier, CobraDroid's modified library intercepts this call and effectively turns it into a void method, doing nothing. Similarly, when an SSLContext is initialized, CobraDroid ensures it's configured in the most insecure way possible (e.g., trusting all certificates). From the application's perspective, it believes it has successfully set up a secure SSL connection, but in reality, all security checks have been disabled, allowing a proxy to intercept and decrypt traffic without triggering errors. This works for standard SSL libraries in Android 2.3 but would require updates for newer Android versions or applications using custom SSL implementations.

Targeted Network Traffic Capture

To address the problem of noisy packet captures, CobraDroid leverages the netfilter rules enabled by the kernel upgrade. It provides an interface to select specific applications by their package name. When activated, CobraDroid configures netfilter to capture all incoming and outgoing network traffic only from the selected applications. This traffic is then saved to a PCAP file on the SD card, which can be pulled off the emulator and analyzed with tools like Wireshark. This highly targeted capture eliminates irrelevant background traffic from other applications or the host system, significantly streamlining network analysis.

Dalvik Method Hooking

The most technically intricate feature is the Dalvik method hooking framework, designed to alert analysts whenever a specific method is called. This provides a granular view of application behavior at runtime. The core concept is instrumenting the method bytecode during class loading.

The process involves several steps:

  1. Configuration: Analysts define methods to hook in a hooks.conf file. This file specifies the class (e.g., android.telephony.TelephonyManager), the method (e.g., getDeviceId), an action (currently alert), and a custom payload string (e.g., "Application accessed device ID"). This allows for monitoring both system library calls and application-specific methods, even if obfuscated.
  2. Zygote Initialization: When the zygote process starts, CobraDroid inserts its first hook. It loads the hooks.conf details into global data structures and over-allocates the dvm_dex structure, which holds information about classes, methods, and strings. This over-allocation is crucial because injected code will require additional space for new methods and strings.
  3. Class and Method Loading: As the zygote loads all Android framework classes, CobraDroid iterates through them. If a class matches an entry in hooks.conf, a flag is set. Subsequently, for each method within a matching class, its name is checked against the configuration.
  4. Bytecode Injection: If a method is slated for hooking, CobraDroid allocates new memory for its dex_code structure (which contains the method's bytecode instructions). This new allocation is larger than the original to accommodate injected instructions. The original bytecode is copied, and then a call to a custom method, ClassEventNotifier.notifyEvent, is inserted at the beginning of the method's insns array (the array of 16-bit bytecode instructions). This notifyEvent method is responsible for logging the application name and the custom payload string defined in hooks.conf. After injection, the remaining dex_code (including try/catch blocks and exception handlers) must be carefully re-aligned to ensure correct execution flow.
  5. Resolver Hooking: A critical challenge is how the injected code can call a new method (notifyEvent) or use new strings (the payload string) that are not part of the original application's dex file. This is solved by hooking the Dalvik VM's resolver. The resolver is responsible for mapping string and method IDs (offsets) to their actual values or addresses during runtime. CobraDroid modifies the resolver to catch "out-of-bounds" lookups. For example, if there are 32 strings in the original dex file, the injected code might try to resolve string ID 33. The modified resolver catches this "error condition" and instead manually returns the custom injected string or the address of the notifyEvent method, making it appear to the Dalvik VM as a legitimate resolution. This allows the injected code to execute seamlessly.

This sophisticated hooking mechanism provides unparalleled visibility into application execution, allowing analysts to monitor specific behaviors, even within obfuscated code, and understand the context of sensitive API calls.

Demo / Proof of Concept

▶ Watch: Dalvik method hooking for runtime analysis (21:00)

Jake Valletta’s demonstration of CobraDroid involved analyzing a "mystery" application named testappone. The demo highlighted CobraDroid's ability to overcome common anti-analysis techniques and provide deep insights into application behavior.

  1. Initial Application Launch: The testappone application was launched on CobraDroid. Immediately, it presented an error message: "This app isn't supported on this device." This indicated that the application was performing a device check.
  2. Static Analysis and Device Spoofing: To identify the check, static analysis was performed using apktool to disassemble the application's dex file into smali code. A grep for "build" revealed a check against Build.MODEL for the string "razor" within the MainActivity file. Instead of modifying the application code, Valletta used CobraDroid's Property Editor interface. He changed the ro.product.model property from the default "cobrajoint" to "razor" and enabled the custom build properties. Relaunching the application, the device check was bypassed, and the app proceeded to a blank screen with a "Connect" button.
  3. SSL Pinning Bypass and Network Traffic: Clicking the "Connect" button resulted in another error: "There was an issue connecting to the server. Certificate not trusted." This confirmed that the application was performing SSL certificate pinning or strict hostname verification, preventing Burp Suite (which was running and proxying traffic) from intercepting the encrypted communication. Valletta then enabled CobraDroid's SSL Validation Bypass with a single click. Rerunning the application and hitting "Connect" again, the connection succeeded, and Burp Suite captured the traffic. The captured data revealed a POST request containing the phone number, subscriber ID, and device ID as parameters.
  4. Dalvik Method Hooking in Action: While the network traffic was insightful, Valletta demonstrated how CobraDroid's method hooking provides deeper visibility. He showed the logcat output for CobraDroid's custom security log. Initially, it already showed alerts for calls to getDeviceId, getSubscriberId, and getLine1Number from the TelephonyManager class, indicating the application was querying these details.
  • To demonstrate custom hooking, Valletta performed further static analysis, identifying an obfuscated method com.jp.testappone.b.a that was responsible for making these TelephonyManager calls.
  • He then edited the hooks.conf file, adding an entry for com.jp.testappone.b.a with an alert action and a custom string: "Application accessed our device IDs."
  • Finally, he enabled the Telephony Manager spoofing and changed the phone number in CobraDroid's interface to an arbitrary value.
  • Upon relaunching the app and connecting, the security log now displayed the custom message "Application accessed our device IDs" whenever the com.jp.testappone.b.a method was called, along with the class and method name. This highlighted how analysts can gain clear, contextual information even from obfuscated code.
  1. Targeted Application Traffic Capture: To showcase the specialized network capture, Valletta enabled the "Application Capture" feature, selecting only the testappone application. He then connected the app again, generating traffic. Following this, he opened the browser within the emulator and performed a Google search. After stopping the capture, he pulled the generated PCAP file (brucon.pcap) from the SD card to his workstation and opened it in Wireshark. The Wireshark analysis clearly showed only the SSL traffic from testappone, and notably, no traffic from the browser (e.g., the Google search query), confirming the efficacy of the targeted capture.

The demo effectively illustrated how CobraDroid integrates various functionalities to provide a powerful and streamlined platform for dynamic Android application analysis, enabling researchers to bypass common security measures and gain unprecedented insight into application behavior.

Defensive Implications

▶ Watch: Future plans and audience Q&A (46:00)

CobraDroid’s capabilities highlight several critical areas for Android application developers and defenders to consider:

  • Robust Device Integrity Checks: Applications relying solely on TelephonyManager or build.prop values for device identification or integrity checks are vulnerable to spoofing. Developers should implement more sophisticated device fingerprinting techniques, combining multiple, less easily spoofable identifiers, and potentially leveraging hardware-backed attestation where available. However, even these can be bypassed with root access and advanced hooking.
  • Advanced SSL Pinning Implementation: While CobraDroid can bypass basic SSL pinning, more robust implementations can mitigate some risks. This includes pinning multiple certificates (e.g., leaf and intermediate CAs), rotating pins regularly, and performing pinning checks in native code or using custom, harder-to-hook SSL libraries. However, it's crucial to acknowledge that with sufficient access to the device (as an emulator provides), any in-app pinning can eventually be circumvented.
  • Application-Level Traffic Monitoring: The targeted traffic capture feature underscores the need for organizations to implement application-specific network monitoring. This means not just looking at overall network egress but correlating traffic with specific application processes to identify anomalous behavior or data exfiltration.
  • Awareness of Method Hooking Techniques: The Dalvik method hooking demonstrated by CobraDroid reveals how attackers or researchers can gain deep insight into application runtime. Developers should be aware that their application's internal logic, including calls to sensitive APIs, can be observed. While obfuscation helps, it doesn't prevent monitoring of method calls. Security-critical logic might benefit from being implemented in native code (JNI) to make hooking more challenging, though not impossible.
  • Secure Coding Practices Beyond Environmental Checks: CobraDroid illustrates that relying on environmental checks (device model, SSL trust) as a primary security control is insufficient. Core security logic, such as data validation, authorization, and cryptographic operations, must be inherently secure, regardless of the perceived integrity of the execution environment.

In essence, CobraDroid serves as a powerful reminder that if an attacker has control over the execution environment, most client-side security mechanisms can be bypassed. Defenders should focus on server-side validation, robust API security, and assume that the client environment is untrusted.

Key Takeaways

  • Dynamic Analysis Gap: Dynamic analysis for Android applications historically lacked sophisticated tools compared to static analysis, leading to tedious manual processes.
  • CobraDroid's Integrated Approach: The tool provides a comprehensive platform for dynamic analysis by integrating kernel, user space, device property, SSL, network, and Dalvik VM modifications into a single custom emulator image.
  • Spoofing and Bypass Capabilities: CobraDroid effectively bypasses common anti-analysis techniques such as device identification checks (e.g., Build.MODEL, TelephonyManager queries) and SSL certificate pinning, enabling transparent proxying of encrypted traffic.
  • Granular Runtime Visibility: The Dalvik method hooking framework allows for unprecedented insight into application behavior at a bytecode level, enabling analysts to monitor specific method calls (even obfuscated ones) and understand their context.
  • Targeted Network Analysis: The ability to capture network traffic only from selected applications significantly reduces noise, allowing security researchers to focus precisely on the communications relevant to the target application.
  • Defender's Perspective: The demonstrated capabilities highlight the need for robust, multi-layered security controls that go beyond client-side environmental checks, emphasizing server-side validation and the assumption of an untrusted client environment.

About the Speaker(s)

Jake Valletta was a consultant at Mandiant (a leading cybersecurity firm) at the time of this talk. His work primarily focused on various aspects of cybersecurity, including forensics, penetration testing, and application security. He expressed a particular passion for mobile security, which led him to develop CobraDroid. Valletta also maintained a blog at blog.comerden.com where he shared his research and insights.

Reviews

→ Top-rated talks at BruCON 0x05

All talks from BruCON 0x05