Skip to content
NovaDen
Go back

Android Pentesting

Note: These are working notes and still in progress.

Introduction

Every Android application has an AndroidManifest.xml. The entry point of the application is the component declared with the android.intent.action.MAIN action in the manifest.

The canonical reference for developing Android applications is developer.android.com. Understanding how an app is meant to be built is what tells you where to push on it when pentesting.

App Components

An Android app is built from four kinds of components: activities, intents, services, and broadcasts. Each is a place where the app receives input, which makes each one a place worth looking at when pentesting.

Activity

An activity is a single, focused thing the user can do. It is what the user interacts with: the UI.

When a new activity is started, it is usually placed on top of the current activity stack. The previous activity stays below it in the stack and does not come back to the foreground until the new activity exits.

An activity moves through four states:

Intents

An intent is a messaging object you use to request an action from another app component. There are three fundamental use cases:

Intents come in two types:

Example of an intent that opens a URL:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://hextree.io/"));
startActivity(browserIntent);

To receive an intent, you set up the AndroidManifest.xml to accept it (via an intent filter), and the receiving activity must be exported so other apps can reach it.

Services

A service is a component that performs an action in the background, without a user interface.

Broadcast

A broadcast is a message that any application can receive.

Attack Surface

Exported activities are part of the attack surface: any app on the device can interact with the exported parts of an application. Exported services and broadcast receivers are reachable the same way. When mapping an app, the exported components are the first thing to enumerate, because they are what an attacker can touch without any privilege on the app itself.

Reverse Engineering Methodology

How an APK is built

An Android application is written in Java or Kotlin. It is compiled into class files (regular Java bytecode), and a compiler then converts that into DEX code (Dalvik bytecode).

An APK is a ZIP archive containing:

Some applications will not let you pull their APK off the device. In those cases, search for the APK online, but verify the signature and scan it for malware before trusting it.

Define the goal first

Always define the goal of your reverse engineering before you start. The goal shapes your strategy. For example, if you just want to find where the data comes from (the backend APIs) or to understand the overall app flow, you take a different path than if you are hunting for one specific value, where you may not need to walk the whole app at all.

Comparing app versions

To compare an updated app against an old one, decompile both APKs with jadx into separate folders, then diff the two folders (a VS Code extension works well for this).

Keys hidden in native libraries

Sometimes an app hides keys inside a native library (for example, System.loadLibrary("native-lib")). Native code cannot be decompiled with jadx, so there are three approaches:

Tooling

The tools you reach for during Android pentesting, and what each is for:

Quick reference: for the actual commands, see the Android Cheat Sheet.


Share this post on:

Next Post
Android Pentesting Cheat Sheet