Skip to content

Lab 01 — Attack surface enumeration and target selection

Objective: produce a written attack-surface table for a real Android device, score the candidates against the yield model, and defend one target choice in a paragraph — the two stages of vulnerability research that decide whether the next three weeks are worth anything, and the two nobody practises.

Difficulty: beginner to intermediate Time: 90–120 minutes Prerequisites: 70 §3.2 and §3.3. Helpful: 24-IPC §3.22 (the IPC enumeration methodology this builds on), 32-Manifest (what exported means), 22-SELinux §8.6 (policy diffing).

What you need

A device or emulator Any Android 8 or newer. Root is not required and is not used.
A second device, ideally For the diff. An emulator running a Google APIs image of the same version works and is the cheapest way to get a reference
adb On your PATH
scripts/surface-enum.sh ../scripts/surface-enum.sh

Warning — this lab is read-only, and you should verify that yourself. Every command here runs getprop, pm list, dumpsys, service list, ls or ps. Nothing is installed, nothing is started, no Intent or broadcast is sent, and nothing is written to the device. Read surface-enum.sh before running it. Insisting on that is correct professional behaviour, and the script is deliberately short enough to make it easy.


0. Why this lab is first

Everything else in the chapter is downstream of two decisions: what is reachable, and which of it is worth your time. Get those wrong and you can build a flawless harness, run a perfect campaign, triage impeccably, and produce nothing — because you were fuzzing a component that Google's infrastructure has been fuzzing continuously for six years, or one that no attacker can reach.

The skills here are unglamorous. They are also the ones that separate researchers who find things from researchers who are busy.


Part 1 — Establish the posture before you measure anything

Step 1.1 Identify the device, precisely

# host
adb devices -l
adb shell getprop ro.product.model
adb shell getprop ro.build.version.release
adb shell getprop ro.build.version.sdk
adb shell getprop ro.build.version.security_patch
adb shell getprop ro.build.fingerprint

Write all six down. Every claim you make for the rest of this lab is scoped to that fingerprint, and a claim recorded against the wrong device is worse than no claim.

Warning — devices get swapped. This repository has recorded it happening twice, once mid-session. While this chapter was being written, the attached phone changed from an i9000S (Android 13 / API 33) to a Redmi M2101K6P (Android 11 / API 30) between one command and another. If you have more than one device attached, always pass -s <serial> — and re-check the model before you trust any version-gated result.

Step 1.2 Capture the security posture

# adb shell
getenforce
getconf PAGE_SIZE
getprop ro.product.cpu.abilist
getprop ro.arm64.memtag.bootctl
grep -o mte /proc/cpuinfo | head -1

These are the facts every severity claim later depends on:

Reading Why it matters to a research finding
getenforce A Permissive device tells you nothing about what a domain can actually do in production
PAGE_SIZE 16384 means your NDK must be r27 or newer, or your fuzzer will segfault before it starts (§7.7)
abilist Which ABI you must build harnesses for
memtag.bootctl / mte in cpuinfo MTE turns a large fraction of the memory-safety classes into detected crashes, which changes severity

Step 1.3 Run the collector

# host
../scripts/surface-enum.sh --out /tmp/surface-$(date +%F)

On a device with a couple of hundred packages the exported-component pass takes several minutes, because it is one dumpsys package per package. That is the honest cost of the enumeration and it is why the script prints progress.

Success criterion for Part 1: /tmp/surface-.../posture.txt exists and every field in it is filled in, including the ones that came back empty — an empty ro.arm64.memtag.bootctl is a measurement, not a gap.


Part 2 — The service list, and the diff that makes it useful

Step 2.1 Read the service list yourself first

Before looking at the script's output, run it by hand, because you should know what the script is doing:

# adb shell
service list | head -20
Found 217 services:
0   DockObserver: []
1   MiuiBackup: [miui.app.backup.IBackupManager]
2   MiuiInit: [miui.os.IMiuiInit]
3   MiuiWifiService: [...]
4   ProcessManager: [...]

That is real output from a Redmi M2101K6P on Android 11. Three of the first five services are visibly vendor code — they exist on no AOSP build. You have not run a diff yet and you can already see the shape of the answer.

The bracketed value is the interface descriptor, and it is more useful than the service name: it names the AIDL interface, which tells you what to search for in a decompiled system app, and whether the interface is an AOSP one or the vendor's own.

Step 2.2 Count them, carefully

# adb shell
service list | wc -l
# host -- extract just the names
adb shell "service list" | tr -d '\r' \
  | sed -n 's/^[0-9][0-9]*[[:space:]]*\([^:]*\):.*/\1/p' \
  | sed 's/[[:space:]]*$//' | sort > /tmp/services-a.txt
wc -l /tmp/services-a.txt

Warning — the off-by-one that will bite you. The first version of surface-enum.sh used [0-9]* rather than [0-9][0-9]* in that sed. [0-9]* matches zero digits, so the header line Found 217 services: matched too and was captured as a service named Found 217 services — giving a count of 218 against 217 actually present. It was found only because the count was compared against the header the device itself printed.

218 looks exactly as plausible as 217. Every count you publish should be reproducible from a command someone else can run, precisely so that this class of error is findable by someone other than you.

Step 2.3 Get a reference device

The diff is the whole point, so you need something to diff against. In descending order of quality:

  1. A Pixel running the same Android version. Closest to AOSP.
  2. An emulator running the AOSP (not Google APIs) system image of the same API level.
  3. An emulator running a Google APIs image. Includes GMS, so your delta will contain GMS services too — annoying but workable once you learn to recognise them.
  4. Another device from a different manufacturer, same version. The delta is then "things unique to each", which is still informative.
# host -- capture the reference
../scripts/surface-enum.sh --out /tmp/surface-reference --serial emulator-5554

Step 2.4 Diff

# host
../scripts/surface-enum.sh --out /tmp/surface-target --serial <target-serial> \
    --compare /tmp/surface-reference
cat /tmp/surface-target/services-only-here.txt

This file is the highest-value artefact in the lab. Every line is a service that exists on your target and not on the reference, which means it is almost certainly vendor code: written by fewer people, reviewed by fewer people, and fuzzed by nobody.

Both 20-Security-Architecture §5.8 and 21-App-Sandbox §5.12 arrive at this independently, and 21 states the method almost word for word: "Enumerate them with service list and dumpsys -l on the target device, diff against a Pixel running the same Android version, and investigate the difference."

Step 2.5 Attribute the delta to packages

A service name is not yet a target; you need the code behind it.

# adb shell -- which process hosts it?
dumpsys -l | grep -i <servicename>
ps -A -o PID,USER,NAME | grep -i <keyword>
# adb shell -- which package declares the interface?
pm list packages -f | grep -i <vendorprefix>
# host -- pull the APK for static analysis
adb shell pm path com.vendor.something
adb pull /system/priv-app/Something/Something.apk .

From here, 56-JADX and 52-StaticAnalysis own what you do with the APK, and 57-Ghidra owns what you do with any .so inside it.

Success criterion for Part 2: a list of at least three vendor services with, for each, the interface descriptor, the hosting process, and the package that implements it.


Part 3 — Exported components

Step 3.1 Read the collector's output

# host
sort -t= -k2 -rn /tmp/surface-target/exported.txt | head -20

Step 3.2 Look at one properly

# adb shell
dumpsys package com.vendor.something | sed -n '/Activity Resolver Table/,/^$/p'
dumpsys package com.vendor.something | grep -n 'exported=true' -B4 -A2

For each exported component, three questions, and only the third one matters:

  1. Is it exported? (exported=true, or an intent filter with no explicit android:exported="false" on older target SDKs.)
  2. Is it guarded by a permission?
  3. Can an ordinary third-party app hold that permission?

Question 3 is the one that turns a list into a finding candidate. A component guarded by a signature-level permission held only by the vendor's own apps is not reachable by you. A component guarded by a normal-level permission is reachable by anything.

# adb shell -- what protection level does the guarding permission have?
dumpsys package permission com.vendor.permission.SOMETHING

Pentester's Note. exported=true is necessary, not sufficient — and the converse trap is worse. Chapter 29 measured that 299 of 431 distinct broadcast actions registered by third-party processes had zero manifest-declared receivers anywhere on the device: 69% of that surface is registered at runtime and is invisible to any package-based enumeration, including this one. If broadcasts are your target, enumerate from the running system (dumpsys activity broadcasts), not from manifests.

Success criterion for Part 3: at least three exported components identified, each with its guarding permission and that permission's protection level recorded.


Part 4 — Native libraries

Step 4.1 Inventory

# host
grep -A40 '### /vendor/lib64' /tmp/surface-target/native-libs.txt

Vendor libraries first, deliberately. /system/lib64 is mostly AOSP and mostly already fuzzed.

Step 4.2 Filter for parsers

# host -- pull a candidate and look at what it offers
adb pull /vendor/lib64/libvendorsomething.so .
llvm-nm --defined-only --demangle libvendorsomething.so \
  | grep -iE ' T .*(parse|decode|read|load|unpack|inflate|deserial|extract)'
# host -- the error strings are the best map in a stripped binary
llvm-strings libvendorsomething.so \
  | grep -iE 'invalid|malformed|unsupported|truncat|magic|version|corrupt'

An error string like "invalid chunk size" sits next to the code that checks the chunk size, and that code is the parser. This is the cheapest possible reconnaissance and it is routinely skipped.

Step 4.3 Check what hardening the shipped build actually has

# host
llvm-readelf --dynamic libvendorsomething.so | grep -E 'BIND_NOW|FLAGS'
llvm-readelf --headers libvendorsomething.so | grep -E 'GNU_RELRO|GNU_STACK'
llvm-nm --undefined-only libvendorsomething.so | grep -E '__stack_chk_fail|_chk$|strcpy|sprintf'

15-Native-Code §8.2's checker automates all of this and is the right tool for real work; doing it by hand once is how you learn what it is telling you.

Record what you find. It is not a finding — absence of a mitigation is a fact, and whether it matters depends on a bug you do not have yet — but it is an input to the severity assessment you will make later, and vendor builds routinely differ from AOSP builds.

Success criterion for Part 4: three native libraries identified as parser candidates, with their suspicious exports and their hardening state recorded.


Part 5 — Score, and choose

Step 5.1 Build the surface table

Open /tmp/surface-target/SUMMARY.md and fill in the table. Actually write it; the discipline is the point.

Entry point Format / protocol Who can reach it User interaction? Harnessable? Yield score
com.vendor.assist/.CmdReceiver Intent extras Any installed app No Yes, via an attacker app ?
libvendorimg.so:vimg_decode Proprietary image container Any app that can get a file rendered Yes — user opens it Yes, direct harness ?
IVendorTelemetry txn 7 Parcel Any app; no permission found No Yes, via a Binder client ?
Boot config /vendor/etc/x.cfg Custom TLV Nobody without root No Yes, but pointless ?

Include the last row's kind of entry. The value of an enumeration is partly the things you can rule out with a reason rather than forget about.

Step 5.2 Score each candidate

Five factors from §3.3. Score each 1 to 5, and write the reason next to the number — a score without a reason is a guess wearing a suit.

Factor 5 means 1 means
Eyes on it Vendor code, no public source, no known fuzzing AOSP media stack, OpenSSL, libpng
Language C or C++ Rust, or pure Java/Kotlin
Age Very new, or very old and unmaintained Actively maintained and mature
Input complexity Nested, length-prefixed, self-describing A fixed-size struct
Reachability Any app, or no app at all Requires root or a signature permission

Step 5.3 Write the paragraph

This is the deliverable of the lab. One paragraph, defending your choice, that answers:

  • What is the target, precisely — which function in which library, or which transaction on which service?
  • Who can reach it, and what evidence do you have for that beyond "it is exported"?
  • Why is it more promising than the second-best candidate on your list?
  • Who else has probably fuzzed it, and how do you know?
  • What is your budget, in hours, and what will make you stop?

A researcher who cannot write that paragraph is choosing at random. Target selection dominates every other decision in the method, and it is the cheapest one to get right.


Part 6 — What you cannot see from here

Finish by writing down the limits of what you just produced. This is the coverage statement for stage 1, and 51-DynamicAnalysis §7.7 owns the discipline.

At minimum, record:

  • Runtime-registered broadcast receivers. 69% of that surface, per chapter 29's measurement, is invisible to package enumeration.
  • Services registered by processes that were not running when you looked. service list is a snapshot; chapter 29 measured three snapshots of the same idle device giving 1,151 / 1,281 / 1,290 registrations.
  • Native code reached only through JNI from managed code, where the export list tells you nothing about who calls it.
  • Anything behind a signature permission you cannot hold, which you can see but not test.
  • Whatever the device does not do while sitting on your desk. Components that only start during a call, a camera session, or an NFC tap never appeared in your snapshot.

Success criteria

You have completed this lab when:

  1. posture.txt records the model, API level, patch level, fingerprint, SELinux mode, page size and MTE state, with no blank fields left unexplained.
  2. You have a service diff against a reference device, and can name at least three vendor services with their interface descriptors and hosting packages.
  3. You have three exported components with their guarding permissions and protection levels.
  4. You have three native libraries with parser-shaped exports and their hardening state.
  5. Your surface table has at least eight rows, including at least one you ruled out with a reason.
  6. Every candidate is scored on all five factors, with reasons written next to the scores.
  7. You have written the defence paragraph, and it names a stopping condition.
  8. You have written the limits section — what your enumeration cannot see.

Extension exercises

  1. Diff two firmware versions of the same device. Which services appeared, which disappeared, which changed? A service that appeared in a minor update is new code that nobody has looked at.
  2. Diff SELinux policy against AOSP. 22-SELinux §8.6 owns the method. A vendor domain more permissive than its AOSP peer is a finding class in its own right, and it is found by diffing rather than by exploitation.
  3. Enumerate the runtime broadcast surface and quantify how much of it your manifest-based enumeration missed on your device. Chapter 29 got 69%; see whether you can reproduce the order of magnitude.
  4. Take your top candidate and establish reachability at level 2 — find a static call path from an exported component to the function you want to fuzz. You will need 56-JADX and 57-Ghidra. Most paths that look plausible turn out to be dead, and finding that out now is much cheaper than finding it out after a three-week campaign.

Where to go next

Lab 02 — Write a bug, harness it, fuzz it, triage it takes the next four stages end to end, entirely on the host, against a target you own.