Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Mobile

Lab · Medium · 1.5 hoursFree account

Analyze an Android APK Statically

Decode an APK, review its manifest, then search the source for secrets and weak code.

  • android
  • static-analysis
  • apk
  • jadx
  • apktool
  • manifest-review
On this page 16 sections
  1. ·What is static analysis?
  2. ·Prerequisites
  3. ·Lab setup
  4. 1Create a work folder and hash the APK
  5. 2Look inside the APK as a ZIP file
  6. Locked: Read the app identity, permissions and signature
  7. Locked: Decode the manifest and resources with apktool
  8. Locked: Review the manifest for attack surface
  9. Locked: Decompile the code to Java with jadx
  10. Locked: Search for secrets, insecure storage and weak crypto
  11. Locked: Trace one finding from the manifest to the code
  12. Locked: Record your findings and map the attack surface
  13. Locked: Check
  14. Locked: Clean-up
  15. Locked: Defender notes
  16. Locked: Command reference

An APK is a ZIP with a binary manifest, compiled DEX code and resources. Many flaws of a mobile app live in those files and never at run time: a hardcoded key, an exported component with no caller check, a backup flag that lets anyone copy the data, a password sent in clear text. Unpack the APK with apktool, decompile the code with jadx, search for secrets with grep, then record each finding with its file, its risk and its fix.

Lab Objectives

  • Explain what static analysis finds in an Android app and what it cannot find
  • Unpack an APK and name its main parts (manifest, classes.dex, resources, signature)
  • Decode the manifest with apktool and list the exported components, permissions and risky flags
  • Decompile the app to Java with jadx and search the source for hardcoded secrets and insecure code
  • Trace one finding from the manifest to the code that handles it
  • Record each finding with its file path, risk and fix

What is static analysis?

Static analysis means you study an app without running it. You read its files, its manifest and its decompiled code. You do not need a phone or an emulator.

This method is fast and safe. It also shows you the whole app, not only the screens you tap. It cannot show runtime values, server replies or code that the app downloads later. The Android Dynamic Analysis lab covers those.

An Android app ships as an APK (Android Package). An APK is a ZIP file. Inside it are the compiled code, the resources and a binary manifest. Tools turn this back into readable text and Java.

Terms that this lab uses:

  • Manifest: the file AndroidManifest.xml. It declares the components, the permissions and the app settings.
  • Activity: one screen of the app.
  • Service: code that runs in the background and has no screen.
  • Broadcast receiver: code that reacts to a message from the system or from another app.
  • Content provider: a component that shares app data through a URI.
  • Intent: a message that starts a component or sends data to it. An intent-filter in the manifest lists the intents that a component accepts.
  • Exported component: a component that other apps can start. It is exported when it sets android:exported="true". It is also exported by default when it has an intent-filter and the app targets Android 11 or lower.
  • DEX: the compiled code format of Android. The file is classes.dex.
  • Smali: a readable text form of DEX code.

Prerequisites

Lab setup

You need one Kali Linux machine with internet access for the first download. You do not need an Android device.

ItemPurpose
unzipLists and extracts the APK as a ZIP file
aaptReads the package name, SDK levels and permissions
apksignerShows the signing certificate
apktoolDecodes the manifest and resources to text, and the code to smali
jadxDecompiles the code to Java

Install the tools:

sudo apt update
sudo apt install -y unzip aapt apksigner apktool jadx

Check the tool versions:

apktool --version
jadx --version
aapt version
apksigner --version

Record the versions in your notes. Flags can differ between versions. Run a tool with --help if a flag in this lab fails.

Legal note. Analyse only apps you built, apps you have written permission to test, or training apps such as DIVA. An APK from a store is still someone else's software. Check its licence and terms before you decompile it. Do not upload a client's APK to an online scanner, because that shares their code with a third party. This lab never installs or runs the app. Never install DIVA on a personal phone.

Target. This lab uses DIVA (Damn Insecure and Vulnerable App). DIVA is an Android app that its authors built to be insecure, for training. Download the APK only from the link in the README of the payatu/diva-android project on GitHub. Save it as diva-beta.apk. Step 1 records its hash.

Step 1: Create a work folder and hash the APK

A hash proves which file you analysed. Record it first. A report that lacks the hash cannot be checked later.

1

Create a folder. Move the APK into it. Run sha256sum and keep the result.

The mv command below assumes that you saved the APK in ~/Downloads. Use the folder where you saved the file if it is not there.

bashwork folder and hash
mkdir -p ~/android-static-lab
cd ~/android-static-lab
mv ~/Downloads/diva-beta.apk .
sha256sum diva-beta.apk
ls -l diva-beta.apk

Example output:

3f9a...e1c2  diva-beta.apk
-rw-r--r-- 1 kali kali 1494872 Nov 18 09:12 diva-beta.apk

Your hash and file size can differ. The hash must stay the same each time you run the command on this file.

Why it matters. The hash is your evidence. If the hash changes, the file changed.

Step 2: Look inside the APK as a ZIP file

An APK is a ZIP archive. Listing it shows the parts before you decode anything.

2

List the APK contents

Run unzip -l on the APK. Do not extract it yet.

bashAPK structure
unzip -l diva-beta.apk | head -n 20

Example output:

Archive:  diva-beta.apk
  Length      Date    Time    Name
---------  ---------- -----   ----
     5712  2016-01-01 00:00   AndroidManifest.xml
  1076228  2016-01-01 00:00   classes.dex
   ...
    38208  2016-01-01 00:00   resources.arsc
   ...
     1385  2016-01-01 00:00   META-INF/MANIFEST.MF
     1438  2016-01-01 00:00   META-INF/CERT.SF
     1007  2016-01-01 00:00   META-INF/CERT.RSA

Find these entries in your output.

EntryMeaning
AndroidManifest.xmlThe app declaration. It is binary XML, so a text editor cannot read it.
classes.dexThe compiled code (Dalvik bytecode). Large apps have classes2.dex and more.
resources.arscThe compiled resource table, which includes strings.
res/ and assets/Layouts, images and raw files. Look here for config files and keys.
lib/Native libraries (.so files). jadx cannot decompile these.
META-INF/The signature files.

Why it matters. Native libraries and extra .dex files are extra places to search. Note which ones exist.

Sign in to continue

11 more sections are for signed-in members. It is free: sign in with Google.

Related