Lab 03 — Full triage, ending in a written analysis¶
Difficulty: Intermediate–Advanced Time: 3–4 hours Prerequisites: Lab 01, Lab 02, README §3.14–§3.16, README §5.11
SAFETY. The target is the inert sample from lab 01. No payload, no C2 client, no working capability, all indicators under RFC 2606
.invalid. Nothing is installed or executed on any device in this lab. The deliverable is a document, not a capability.
Objective¶
Produce a complete, defensible written analysis of a sample, from scratch, without copying the model.
That is the whole lab. Labs 01 and 02 taught you to operate the tools; this one
teaches you to write the thing that other people actually consume. The model is
../examples/triage-writeup-inert-sample.md
and you should not read it until Part F.
The secondary objective is attribution: three exercises that make the limits of signer-based, string-based and infrastructure-based linking concrete rather than theoretical.
Part A — Set up a corpus of one, then three¶
A single sample teaches you nothing about attribution. Build three.
# host
cd 69-MalwareAnalysis/examples/inert-sample
# Build A: the sample as shipped
OUTDIR=/tmp/ch69/A ./build.sh
# Build B: identical sources, a DIFFERENT throwaway key
OUTDIR=/tmp/ch69/B ./build.sh
# Build C: same key as A, but a changed string
cp ConfigVault.java /tmp/ConfigVault.java.bak
sed -i 's/CH69-INERT-DEMO/CH69-INERT-DEMO-2/' make-config-assets.py
OUTDIR=/tmp/ch69/A2 ./build.sh
cp /tmp/ch69/A/throwaway.ks /tmp/ch69/A2/throwaway.ks # reuse A's key
rm -rf /tmp/ch69/A2/work && OUTDIR=/tmp/ch69/A2 ./build.sh
git checkout make-config-assets.py 2>/dev/null || \
sed -i 's/CH69-INERT-DEMO-2/CH69-INERT-DEMO/' make-config-assets.py
Note on the third build. Copying the keystore before the second run makes A2 share A's signing key while carrying different content. If your shell makes that awkward, do it by hand: build A, copy
throwaway.ksinto a fresh$OUTDIR, change the string, build again. The point is one key, two files.
Confirm what you have:
# host
cd ..
python3 -B ../scripts/apk-triage.py /tmp/ch69/*/inert-sample.apk --quiet
<sha256-A> com.pentest.ch69.inert signer=<key1> signals=8/4
<sha256-A2> com.pentest.ch69.inert signer=<key1> signals=8/4
<sha256-B> com.pentest.ch69.inert signer=<key2> signals=8/4
Three different file hashes. Two different signer hashes. One shared key across A and A2.
Part B — Attribution exercise 1: the signer¶
B.1 — What the shared key establishes¶
Question. A and A2 share a certificate SHA-256. Write the strongest true sentence you can about that, and then the weakest false one somebody might write.
Answer
**Strongest true:** "Samples A and A2 carry the same signing certificate (SHA-256 `…`), so both were signed by whoever held the corresponding private key." **Weakest false:** "Samples A and A2 were produced by the same actor." The gap between those two sentences is the whole of signer-based attribution. Everything that can break the second while leaving the first intact: | Mechanism | Effect | |---|---| | A private key leaks or is dumped from a build server | Two actors, one key | | A key is sold | Same | | Shared build infrastructure signs for many customers | Many actors, one key | | `CN=Android Debug` | Millions of unrelated apps, one key | | An actor deliberately reuses a leaked key | A false flag that costs nothing | **In your write-up, state the certificate fact and let the reader draw the inference.** That is what "publish the chain" means in practice.B.2 — What the different key does not establish¶
B has a different signing key but byte-identical source code to A.
Question. If you had only the two APKs, how would you establish that they are the same code?
Answer
Compare the DEX, not the container.# host
for d in A B; do
python3 -B -c "
import hashlib, zipfile, sys
z = zipfile.ZipFile('/tmp/ch69/$d/inert-sample.apk')
print('$d', hashlib.sha256(z.read('classes.dex')).hexdigest())
"
done
python3 ../../12-DEX-Internals/scripts/dex-diff.py \
/tmp/A/classes.dex /tmp/B/classes.dex
B.3 — The pivot that matters at scale¶
Question. You have forty thousand samples. What do you cluster on, in what order, and why?
Answer
1. **File SHA-256** — deduplicate. This is free and removes most of the volume. 2. **`classes.dex` SHA-256** — collapses re-signing. Different container, same code. 3. **Signing certificate SHA-256** — the cheapest strong link across *different* code. This is the one that finds campaigns. 4. **Capability vector** — a fixed-width boolean vector (accessibility declared, notification listener declared, overlay requested, provider count, process count, …). This is the only thing that clusters *behaviourally* at low cost. What you do **not** cluster on first: strings, permission sets or packer identity. Chapter 42 measured why the first fails — 1,393 `@kotlin.Metadata` grep hits on one app, every one an empty shell, every one a false positive. `apk-triage.py --json` exists for step 4: it emits every section plus the signal list, so a pipeline can compute over structure rather than scraping text. **And the discipline that keeps it honest:** version every detector, store the version with every result, and hand-sample the output weekly. Chapter 38's mapper once reported a self-signature check in **18 of 18 APKs**; splitting patterns into STRONG and WEAK brought it to a defensible 13 of 18. *If a detector agrees with you about every sample, suspect the detector.*Part C — Attribution exercise 2: strings¶
C.1 — The shared-SDK problem, constructed¶
You do not need a real SDK to see this. Extract the string pools of all three builds and compare:
# host
cd /tmp/ch69
for d in A A2 B; do
python3 -B -c "
import zipfile, sys
sys.path.insert(0, '.')
z = zipfile.ZipFile('$d/inert-sample.apk')
open('$d.dex','wb').write(z.read('classes.dex'))
"
done
python3 -B /path/to/69-MalwareAnalysis/scripts/config-decrypt.py \
--apk A/inert-sample.apk --scan-dex | head -30
Question. Of the 185 strings in this sample's pool, how many are specific to this sample rather than to the Android platform or the toolchain?
Answer and the exercise
Count them by hand. You will find that the great majority are: - type descriptors from `android.*` and `java.*` - method names the compiler emitted - the `TAG` constant and the log messages A real app with a hundred SDKs has a pool where **the overwhelming majority of strings belong to code the author did not write.** That is the shared-SDK problem, and it is why "sample X and sample Y share 40 strings" means almost nothing until you have subtracted the framework and the common SDKs. The way to do that subtraction, if you must use strings for linking: 1. Build a baseline of strings that appear in a large sample of *known-benign* apps. 2. Subtract it. 3. What remains is a candidate fingerprint — and it will be small. Even then, a distinctive string is weak evidence. **Distinctive *structure* is strong**: an unusual class layout, a bespoke protocol, a hand-rolled crypto construction with a specific quirk. Structure is expensive to copy; strings are free.C.2 — The false-flag exercise¶
Question. You find a sample whose log messages are in Russian, whose
timestamps are UTC+3, and which contains the string Мы не спим. What can you
conclude?
Answer
**Nothing.** Every one of those is free to fabricate: - Strings are typed by whoever typed them, in whatever language they chose. - Build timestamps come from the build machine's clock and timezone, both of which are settings. - A distinctive phrase copied from a published report is the *cheapest possible* false flag, because it costs one line and it lands in every automated correlation. The professional formulation is: *"The sample contains Cyrillic log strings and build timestamps consistent with UTC+3. These are trivially forgeable and are recorded for completeness only; no attribution inference is drawn from them."* Recording them is right. Inferring from them is not.Part D — Attribution exercise 3: infrastructure¶
D.1 — What a config hostname is worth¶
Both your recovered configs name hosts under c2-example.invalid.
Question. Write a sentence about gate.c2-example.invalid that would
survive review, and one that would not.
Answer
**Survives:** "The decrypted configuration names `hxxps://gate[.]c2-example[.]invalid/v1/beacon` as its primary endpoint, with two fallbacks. Whether any of these was ever reachable is outside the scope of this static analysis.`.invalid` is reserved by RFC 2606 and cannot resolve." **Does not survive:** "C2 server: gate.c2-example.invalid." Three problems with the second. It is undefanged. It asserts a *role* ("C2 server") that was not observed. And it presents a build-time intention as a present-tense fact. **The general rule: an indicator is a claim about the past.** A hostname in a config is what the author intended when they built it. Whether it ever served anything, whether it still does, and who controls it now are three separate questions that static analysis cannot answer. Passive DNS and public reporting answer them. A blocklist entry produced without that caveat may be a parked domain, a sinkhole, or a shared CDN — and blocking a shared CDN is how a detection team takes down its own company's traffic.D.2 — The pin¶
The stage-two config contains "pin_sha256": "AAAA…".
Question. What does the presence of a pin tell you, and what does it change about your analysis plan?
Answer
**What it tells you:** the author expected interception and defended against it. That is a small signal about sophistication and a large signal about *your next step*. **What it changes:** if you ever run this in an isolated environment and want to see the traffic, your proxy will be refused. Chapter 36 and chapter 67 own the techniques; the order that works is: 1. **Decrypt the config first.** You may not need the traffic at all — the hostnames, the poll interval and the target list are already in it. That is exactly what happened in this lab. 2. Try the universal unpinning scripts. Malware pins badly: a hardcoded SPKI hash checked by a hand-rolled `TrustManager` is the norm. 3. **Check your own environment before believing a success.** Chapter 44 recorded a device where an APatch `trustusercerts` module had promoted the interception CA into the *system* store — 139 certificates in a tmpfs over `/system/etc/security/cacerts`. A successful intercept there proves nothing about the app's trust configuration. Always:adb shell mount | grep cacerts
Part E — Write the analysis¶
This is the deliverable. Budget ninety minutes for it.
E.1 — Rules¶
- Do not open the model. Write yours first.
- Every claim carries its source.
- Every claim carries its confidence: declared, observed, inferred.
- Include a section listing what you did not do, and why.
- End with exactly one of: close, escalate, hand over.
- Defang every indicator.
- No sentence contains the words "clearly", "obviously" or "sophisticated".
E.2 — The skeleton¶
0 Metadata analyst, date, sha256, source of the sample,
analysis type (static/dynamic/both), tooling + versions
1 Identity hashes, package, versions, DEX facts, code fraction
2 Provenance signing schemes, certificates, AND what each is not worth
3 Capability the model, every res/xml variant read
4 Persistence every hook, with the mechanism named
5 Native the four facts, and what each changes about your method
6 Configuration decrypted, indicators DEFANGED, with the method used
7 NOT DONE the section reviewers read first
8 Conclusion close | escalate | hand over, with the reasoning
E.3 — Gather the raw material¶
# host — everything you need, in four commands
python3 -B ../scripts/apk-triage.py /tmp/ch69/A/inert-sample.apk \
> /tmp/ch69/triage-A.txt
python3 -B ../scripts/config-decrypt.py --apk /tmp/ch69/A/inert-sample.apk \
--auto > /tmp/ch69/config-A.txt
"$ANDROID_HOME"/build-tools/*/apksigner verify -v --print-certs \
/tmp/ch69/A/inert-sample.apk > /tmp/ch69/signer-A.txt
python3 -B ../scripts/apk-triage.py /tmp/ch69/A/inert-sample.apk --json \
> /tmp/ch69/triage-A.json
E.4 — The three hard sections¶
Most people can write sections 1–6 by transcribing tool output. These three are where the work is.
Section 2 must contain a "what this is not worth" paragraph. Not a disclaimer at the end — a paragraph in the provenance section, immediately after the certificate. If a reader can quote your certificate block without also seeing its limits, you have written a trap.
Section 7 must be specific. "Dynamic analysis was not performed" is not enough. For each omission: what it was, why, and what it would have added.
| Not done | Why | What it would have added |
|---|---|---|
| Execution | No isolated environment was available | Runtime behaviour, network traffic, the runtime-registered receiver surface, whether the watchdog restarts |
| Signature verification | (you did do this — so it does not belong here) | |
| Full manifest audit | Owned by 32-Manifest/scripts/manifest-audit.py; not run |
Exported-component posture, provider grant flags, permission protection levels |
| Container audit | Not run | Duplicate entries, LFH/CDFH divergence, trailing bytes, signing-block smuggling |
| Decompilation | 88 methods were readable from the string pool | On a real sample, always |
| Corpus pivot | No corpus available | Whether the signer or DEX hash appears elsewhere — usually the single highest-value step |
| Splits | Single APK | On a real target, run everything against every path pm path returns |
Section 8 must pick one outcome. Not "further analysis may be warranted", which is a way of not deciding. Write "escalate" and then the five numbered reasons, or write "close" and then the reasoning that makes closing safe.
Part F — Compare and critique¶
Only now, open
../examples/triage-writeup-inert-sample.md.
F.1 — Diff your document against the model¶
For each section, answer:
- What did the model include that you omitted?
- What did you include that the model omitted?
- Where do you and the model disagree about severity or confidence?
Question 3 is the valuable one. There is no authority here — the model is one analyst's judgement and yours is another's. Disagreements about weighting are normal and should be argued, not resolved by deferring.
F.2 — Specific checks¶
Go through this list against your own document.
- Did you write the sentence "the sample was not executed" explicitly, or did you leave it implied?
- Did you defang every indicator, including in tables and code blocks?
- Did you say what a certificate SHA-256 does not establish?
- Did you mention that installer attribution is absent from the file?
- Did you read both
res/xmlvariants, or only one? - Did you use the word "privilege" anywhere near the second process?
- Did you rate the empty device-admin policy list as harmless?
- Did you say
DT_INIT_ARRAYchanges your instrumentation technique? - Did you name the
RegisterNativesblind spot? - Does your "not done" section say what each omission would have added?
- Does your conclusion pick exactly one of the three outcomes?
- Is there any sentence that would embarrass you if the sample turned out to be a legitimate accessibility tool?
That last one is the real test. Read your document as though you have just been told the app is a screen reader for a visually impaired user. Which sentences survive?
F.3 — The reversal¶
Rewrite your conclusion only, on the assumption that the sample is a legitimate assistive-technology application from a small vendor.
What this exercise teaches
You will find that most of sections 1–6 survive unchanged, because they are *observations*. What changes is the interpretation, and it changes in exactly three places: 1. The accessibility descriptor's breadth becomes an **over-broad capability request** — a Medium finding against a legitimate app, not evidence of malice. 2. The persistence stack becomes **poor engineering** — an app fighting the platform's lifecycle instead of using WorkManager. 3. The encrypted config naming other packages becomes **the hardest thing to explain benignly**, and stays the strongest signal. **If your document could not survive that reversal, it was an argument disguised as an analysis.** A good write-up separates the observation from the interpretation so precisely that a reader who disagrees with your conclusion can still use your evidence.Part G — The corpus write-up¶
One more, shorter document. Using all three builds:
python3 -B ../scripts/apk-triage.py /tmp/ch69/*/inert-sample.apk --quiet
Write a one-page relationship note that states:
- how many distinct files, distinct DEX hashes and distinct signers you have
- which samples are linked, by what evidence, at what strength
- what the linkage does not establish
Model, abbreviated
> **Three files, one distinct code hash, two distinct signing certificates.** > > Samples A and A2 carry certificate SHA-256 `Success criteria¶
- Three builds with two distinct signers and one shared key.
- Explain what a shared certificate does and does not establish, in one sentence each.
- Demonstrate that A and B share a DEX hash under different signers.
- State the four-step clustering order for a large corpus, with reasons.
- Explain why string overlap is weak and structural overlap is strong.
- Explain why Cyrillic strings and a UTC+3 timestamp establish nothing.
- Write the surviving and non-surviving sentences about a config hostname.
- Produce a complete written analysis covering sections 0–8.
- Its section 7 says what each omission would have added.
- Its section 8 picks exactly one of close / escalate / hand over.
- Every indicator in it is defanged.
- It survives the "what if it is a screen reader" reversal.
- Produce the one-page corpus relationship note.
Hints¶
Reusing a keystore across builds
`build.sh` generates `$OUTDIR/throwaway.ks` only if it does not already exist. So: build into `$OUTDIR`, then copy that `.ks` into a fresh directory before building there, and the second build reuses it.OUTDIR=/tmp/ch69/A ./build.sh
mkdir -p /tmp/ch69/A2 && cp /tmp/ch69/A/throwaway.ks /tmp/ch69/A2/
# now change something, then:
OUTDIR=/tmp/ch69/A2 ./build.sh
My three builds all have the same file hash
Then nothing changed. `build.sh` is deterministic apart from the signing key and the certificate's validity timestamps — and those timestamps come from `keytool` at generation time, so reusing a keystore reproduces them exactly. Change a string in `make-config-assets.py` or in a `.java` file to get a different DEX.I cannot decide between "escalate" and "hand over"
**Escalate** means *you* will do more work on it. **Hand over** means somebody with a capability you lack must — a sandbox you do not have, a corpus you cannot query, a native reverser. For this sample, with no isolated environment available, "hand over for dynamic analysis in an isolated environment" is a perfectly good and honest conclusion.Next¶
- Lab 04 — CTF: the quiet sample
- README §5.11 — report structure
- 80-Appendix — the repository's templates and severity rubric