Chapter 69 — Examples¶
Read this before anything else in this directory.
Nothing here is malware, and nothing here has ever been malware. The
inert-sample/application was written from scratch for this chapter. It contains no payload, no command-and-control client, no exfiltration, no evasion, no privilege escalation and no working persistence. Every code path that would carry a capability has been removed and replaced with a log line; the removals are marked in the source with anINERTconstant that istrue,final, and never set to anything else.Every indicator it carries resolves to nothing. All hostnames are under
.invalid, which RFC 2606 reserves permanently so that no such name can be registered or resolved by anybody, ever. All package names are undercom.example.invalid.*.Do not install it on a phone you use. It is harmless. The habit is not the point of the sample; the habit is the point of the chapter. Samples go on an emulator you can throw away. The build script has deliberately no
--installflag.
What is here¶
| Path | What it is |
|---|---|
inert-sample/ |
The teaching sample. Sources only — the APK is built out of tree. |
triage-writeup-inert-sample.md |
The written triage write-up the sample produces, in the shape a real one takes. This is the deliverable the chapter is teaching you to produce. |
Inside inert-sample/¶
| File | Demonstrates | Where the chapter explains it |
|---|---|---|
AndroidManifest.xml |
Every declaration a triage tool looks for, in one file | §8.2 |
BootstrapProvider.java |
Provider persistence — onCreate() before Application.onCreate() |
§3.6 |
BootReceiver.java |
BOOT_COMPLETED, MY_PACKAGE_REPLACED, the STOPPED-state rule |
§3.7 |
SentinelService.java |
The visible half of a watchdog pair, with the restart removed | §3.8 |
GuardService.java |
The invisible half, in a :guard process |
§3.8 |
InertAccessibilityBridge.java |
The accessibility declaration, with an empty body | §3.2 |
InertNotificationRelay.java |
Notification access, with an empty body | §3.4 |
InertAdminReceiver.java |
Device admin and uninstall resistance | §3.5 |
ConfigVault.java |
Two embedded keys, in the two commonest shapes | §3.10 |
MainActivity.java |
Why a dropper has a launcher Activity at all | §3.9 |
NativeProbe.java |
Static versus dynamic JNI binding | §3.12 |
jni/inert_stub.c |
.init_array running before JNI_OnLoad |
§3.12 |
res/xml/accessibility_config.xml |
The descriptor that carries the real capability | §3.2 |
res/xml/device_admin.xml |
An empty policy list, and why it still matters | §3.5 |
make-config-assets.py |
Generates the two config blobs, and prints their plaintext | §3.10 |
build.sh |
No-Gradle build, entirely out of tree | below |
Building it¶
# host — from this directory
cd inert-sample
ANDROID_HOME=/path/to/Android/Sdk ./build.sh
# host — pick your own output location
OUTDIR=/tmp/ch69 ./build.sh
# host — build and immediately triage
./build.sh --triage
The build needs the Android SDK build-tools (aapt2, d8, zipalign,
apksigner), one platform android.jar, a JDK and python3. An NDK is
optional: without one the native library is skipped, the APK ships with no
lib/ directory, and apk-triage.py reports "no native libraries" — which is
a legitimate triage result and worth seeing.
Nothing is written into the repository. .apk, .dex, .class and .so
are on this repository's artefact blocklist, so the build lands entirely under
$OUTDIR.
Verified build, on the machine this chapter was written on¶
SDK C:/Users/<you>/AppData/Local/Android/Sdk
build-tools 35.0.1
android.jar android-35/android.jar
NDK 25.2.9519653 (aarch64-linux-android21-clang)
classes.dex 11,476 bytes 10 classes, 88 methods, 185 strings
libinertstub.so 6.8 KiB ELF64 aarch64, DT_INIT_ARRAY present
inert-sample.apk 21,308 bytes, 12 zip entries
The APK's SHA-256 will not match that build on your machine, and neither
will the signer hash: build.sh generates a fresh throwaway signing key. That
is deliberate, and it is the subject of
lab 03.
A real measurement this sample produced, worth knowing before you build it¶
aapt2 split the accessibility descriptor into two resource variants,
because android:canPerformGestures was added at API 22:
res/xml/accessibility_config.xml canRetrieveWindowContent=true
(no canPerformGestures)
res/xml-v22/accessibility_config.xml canRetrieveWindowContent=true
canPerformGestures=true
This was not planned. It appeared the first time apk-triage.py walked
res/xml* and printed two descriptors where the source has one file.
It matters, and it generalises: a triage tool that reads only res/xml/
under-reports the capability, because the variant the platform actually uses
on a modern device is the -v22 one. The same applies to -v21, -v24,
-v31 and every other qualifier. Any manifest or resource reading that does
not enumerate every variant is answering a question about an API level it did
not choose.
apk-triage.py enumerates all of them, and prints each separately rather than
merging them, so that the discrepancy is visible instead of silently resolved.
Running the tools against it¶
# host — the full triage report
python3 -B ../../scripts/apk-triage.py "$OUTDIR/inert-sample.apk"
# host — recover both config blobs with no key material at all
python3 -B ../../scripts/config-decrypt.py --apk "$OUTDIR/inert-sample.apk" --auto
# host — what key-shaped strings does the DEX carry?
python3 -B ../../scripts/config-decrypt.py --apk "$OUTDIR/inert-sample.apk" --scan-dex
# host — check the ground truth against what the tool told you
python3 -B make-config-assets.py --show
That last command is the one people skip and should not. A triage tool you
have never watched produce a known answer is a tool you cannot rely on. The
plaintexts are printed in make-config-assets.py; read them, then run the
decryptor, then compare.
Related¶
| File | Why |
|---|---|
../scripts/apk-triage.py |
The one-pass triage tool this sample exists to exercise |
../scripts/config-decrypt.py |
Offline config recovery |
../labs/lab-01-first-triage.md |
Build it, triage it, read the output line by line |
../labs/lab-02-config-and-capability.md |
Recover both configs and adjudicate the capability profile |
../labs/lab-03-attribution-and-its-limits.md |
Full triage ending in a written report |
../labs/lab-04-ctf-the-quiet-sample.md |
CTF |