A Beginners guide for Android Penetration Testing

Himanshu sharma
5 min readMar 13, 2024

--

In the expansive realm of cybersecurity, Android Penetration Testing stands out as a crucial endeavor. This detailed manual, titled “Exploring the Depths,” is divided into six key sections, each shedding light on different aspects of Android security. Join us on this expedition as we delve into the complexities, uncover vulnerabilities, and equip you with the knowledge to fortify your digital defenses. From fundamental principles to advanced methodologies, let’s embark together on this journey through the intricacies of Android’s security domain, ensuring you emerge prepared and empowered.

Are you prepared to plunge into the intricacies of Android Penetration Testing? Let the adventure commence.

Introduction to mobile penetration testing

Mobile penetration testing involves a comprehensive evaluation of mobile devices, applications, and systems to pinpoint vulnerabilities that malicious actors could exploit. Ethical hackers, or penetration testers, employ real attack methods to discover and take advantage of security weaknesses.

The main goal of mobile penetration testing is to reveal security risks and vulnerabilities, providing recommendations on how to mitigate them. This procedure assists organizations in bolstering the security of their mobile resources, reduces the risk of security breaches, damage to reputation, and financial losses.

Mobile Penetration Testing Process

Static Analysis: Static analysis, a critical software evaluation technique, examines code without execution. It is essential for developers and security professionals to uncover vulnerabilities in code prior to deployment, improving software security. Consistent static analysis ensures software dependability and pinpoints issues within third-party libraries.

Dynamic Analysis: Dynamic analysis, a vital software evaluation approach, observes code behavior in real-time during execution. It supplements static analysis by uncovering concealed vulnerabilities and weaknesses. Developers and security professionals frequently utilize dynamic analysis to boost software security and dependability, encompassing assessments of third-party libraries.

Getting Started with Android

When examining the Android architecture depicted in the figure, we notice it is segmented into four distinct layers. At the base lies the Linux kernel, tailored for enhanced mobile performance. This kernel interfaces with all hardware components, housing most of the hardware drivers.

Android Structure

‎The libraries in Android are written in C and C++, most of which are ported from Linux. All the applications in Android run under a virtual environment, which is called Dalvik Virtual Machine (DVM).

Each application that runs will run under its own instance of Dalvik Virtual Machine. So, if we are running three different applications, there will be three different virtual instances.

Android Architecture

·Application Layer: The applications are at the topmost layer of the Android stack. An average user of the Android device would mostly interact with this layer.

· Application Framework Layer: Our applications directly interact with these blocks of the Android architecture. These programs manage the basic functions of phone like resource management, voice call management etc.

· Native Libraries Layer: The next layer in the Android architecture includes Android’s native libraries. Libraries carry a set of instructions to guide the device in handling different types of data. For instance, the playback and recording of various audio and video formats is guided by the Media Framework Library.

· Kernel Layer: At the bottom of the Android stack is the Linux Kernel. It never really interacts with the users and developers but is at the heart of the whole system.

Android Components

· Activity: An Activity provides a screen with which users can interact to do something. Users can perform operations such as making a call, sending an SMS, etc. Example: Login screen of your Facebook app.

· Intent: Used to launch an Activities, trigger Broadcast Receivers or communication with services.eg. Click on the button.

· Services: Runs in background to perform long operations. Don’t have a user interface.

· Broadcast Receivers: Respond to announcements broadcasted by system or apps. Originate from systems or apps. Don’t have a user interface. Gateway to other apps.eg. Battery Low, boot completed, headset plug etc.

· Content Providers: Allow applications to have centralized data and modify it. (It’s like a DB) E.g. Contacts, calendar, system dictionary, photos etc.

Android file system

The Android file system is organized into various partitions, each serving a specific purpose. Here’s a brief overview of the provided directories:

/boot: Contains the bootloader and kernel, essential for the initial stages of the device boot process.

/system: Holds the Android operating system and system-related files. This partition is read-only to ensure the integrity of the OS.

/cache: Stores temporary files and cached data from apps. Clearing this partition can help resolve certain performance issues.

/misc: Contains miscellaneous system-related files.

/data/data: This is where individual app data is stored, including user settings, databases, and other application-specific information.

/data/app: Holds the APK (Android Package) files of installed apps.

/data/system: Stores system-related data, including system settings and preferences.

/data/local/tmp: Temporary directory for storing files during app installation and system updates.

What is an APK file

APK stands for Android Package Kit (also Android Application Package) and is the file format that Android uses to distribute and install apps. It contains all the elements that an app needs to install correctly on your device.

What Does APK File Contains

An APK (Android Package) file is the package format used by the Android operating system to distribute and install applications. It typically contains the following components:

· Classes.dex: The classes.dex file in an APK is the heart of Android app code, containing bytecode that’s optimized for the device’s runtime. It’s created by converting Java bytecode using the dx tool during the build process. This compact file enables efficient execution on the Android Runtime, whether it’s Dalvik or ART. The dex format includes optimizations for size and performance, making it a crucial component for app installation and execution on Android devices.

· Application Code: This includes the compiled code and resources required for the app to function, such as Java or Kotlin code, XML layouts, and image and sound files.

· Manifest File: The AndroidManifest.xml file describes the app’s structure, permissions, components (activities, services, receivers), and other essential information.

· Assets: These are files that the app can use, such as additional media, configuration files, or data files.

· Libraries: APKs may include shared libraries or dependencies required by the app.

· Resources: This folder contains non-code resources like images, icons, and localized strings, which are essential for the app’s user interface and functionality.

Feel free to connect with me on LinkedIn for more discussions and insights related to Android Penetration Testing.
You can find me on LinkedIn at @Himanshu Sharma.

--

--