Lab 04 — CTF: the config that lies¶
Difficulty: advanced
Time: 90 minutes on paper; 3 hours if you build and verify it
Prerequisites: labs 01,
02 and 03;
README §3 in full
Artefacts: ctf-vaultpay-config.xml,
ctf-vaultpay-manifest.xml
The brief¶
VaultPay is a payments application. Their security team has just handed you their network security configuration and a summary of their posture:
All application traffic is HTTPS only. We trust the platform certificate authority store and nothing else. Our payments API is pinned to our issuing intermediate and to a backup key held offline, with an expiry in 2031, so we are covered for the life of the current PKI. Cleartext is permitted only for public marketing assets on the CDN and for one third-party analytics endpoint, both of which carry no user data. Our debug relaxation is inside
<debug-overrides>so it cannot affect production.
Every sentence in that paragraph is either false, or true in a way that does not mean what they think it means.
Your job: find all six defects, and produce the flag.
The artefacts¶
ctf-vaultpay-config.xml— the configuration, with the developers' own ticket comments preserved. Several comments are wrong.ctf-vaultpay-manifest.xml— the manifest. Four attributes in it change what the config means and three of them are easy to read past.
Read both before you run anything. This challenge is solvable entirely on paper, and doing it that way first is the point — the tool is the marking scheme, not the method.
Rules¶
- Reason first, run the tool second. Write your answers down before running
../scripts/nsc-audit.py. The tool agrees with the answer key; if it agrees with you as well, you have learnt something, and if it does not, you have learnt more. - Every answer must name a mechanism, not a feeling. "This looks risky" is not an answer;
"
<domain-config>inheritscleartextTrafficPermittedfrom its enclosing<domain-config>, which declarestrue" is. - You may build it. Instructions at the end. Verifying an answer on a device is worth more than the flag.
The questions¶
Q1 — the base case¶
For the host www.vaultpay.io, state:
- which scope applies,
- the effective
cleartextTrafficPermitted, - the effective trust anchor sources,
- whether pinning applies.
Q2 — the nested config¶
For the host img.cdn.vaultpay.io, state the same four things.
Then answer the developers' claim directly: "img.cdn.vaultpay.io serves user profile pictures, which are not public, so we pin it." Is that claim true of the shipped configuration? Give the mechanism.
Q3 — the date¶
The <pin-set> on img.cdn.vaultpay.io declares expiration="2023-02-29".
- Is that a valid calendar date?
- What date does the platform use? Name the class and the property of it that decides.
- What date does a strict parser report? Why does the difference matter to you?
Q4 — the pinned API¶
For the host api.vaultpay.io, state the four things again.
Then answer the developers' claim: "api.vaultpay.io is pinned … expiry is 2031 so we are covered." Assume you are testing the release build, and that you can install a certificate authority into the device's user store and nothing else. Can you read this host's traffic? Give the mechanism, in one sentence, naming the attribute responsible.
Q5 — the manifest¶
The manifest declares android:usesCleartextTraffic="true".
- What is the effective cleartext policy for a host that no
<domain-config>matches? - Which one wins, and at what point in the app's lifecycle is that decided?
- Construct, in two lines of XML, the opposite trap: a manifest that says
falseand an effective policy oftrue.
Q6 — the debug block¶
<debug-overrides> trusts the user store.
- Is it a finding in the release build described by the manifest? Justify with the exact condition.
- Name the attribute whose default value differs inside
<debug-overrides>from outside it, state both defaults, and say what that difference does to theapi.vaultpay.iopin-set in a build where the block is live.
Q7 — the count¶
Run the effective-policy table for all five scopes in the document — <base-config> plus the four
<domain-config> elements, counting the nested one separately.
How many of the five have an effective cleartextTrafficPermitted of true?
Q8 — severity¶
Rank the six defects you have found from highest to lowest severity for a payments application, and
justify the top one and the bottom one in a sentence each. There is no single right ordering; there
is a wrong one, which is any ordering that puts the <debug-overrides> block above the others.
The flag¶
NSC{<Q7 answer>_<Q3 platform date, yyyy-mm-dd>_<Q4 hostname>}
Three fields, all derivable from the questions above. No brute force is possible or intended — either you read the configuration correctly or you did not.
Marking it yourself¶
# host - from labs/
PYTHONIOENCODING=utf-8 python3 -B ../scripts/nsc-audit.py ctf-vaultpay-config.xml \
--target-sdk 33 --debuggable false
The effective-policy table answers Q1, Q2, Q4 and Q7 directly. The findings list answers Q3, Q5 and Q6. Compare it against what you wrote, line by line.
Try these too, because each one demonstrates a mechanism rather than just a verdict:
# host - what changes if the release build were debuggable?
python3 -B ../scripts/nsc-audit.py ctf-vaultpay-config.xml --target-sdk 33 --debuggable true
# host - what would this config have meant on an app targeting API 23?
python3 -B ../scripts/nsc-audit.py ctf-vaultpay-config.xml --target-sdk 23 --debuggable false
# host - travel forward past the 2031 expiry
python3 -B ../scripts/nsc-audit.py ctf-vaultpay-config.xml --target-sdk 33 \
--debuggable false --now 2031-06-01
The last one is worth doing properly. It shows you the app's posture in five years' time, which is the posture it will actually have, because nobody is going to edit this file again.
Building it, if you want to verify on a device¶
The challenge ships as text XML so that this repository contains no build artefacts. Compiling it is straightforward and turns every answer above into a measurement.
# host - drop the artefacts into the lab-02 project
cp ctf-vaultpay-config.xml <lab02>/app/src/main/res/xml/network_security_config.xml
cp ctf-vaultpay-manifest.xml <lab02>/app/src/main/AndroidManifest.xml
# then restore the <activity> block's real class name if you changed it
Adjust applicationId and namespace in app/build.gradle.kts to com.vaultpay.wallet, set
targetSdk = 33, and build both variants:
# host
./gradlew assembleDebug assembleRelease
python3 -B ../scripts/nsc-audit.py app/build/outputs/apk/release/app-release-unsigned.apk --xml
Install the release build (see lab 02 for the MIUI root-install fallback) and measure:
# host
frida -U -p $(adb shell pidof com.vaultpay.wallet | tr -d '\r') -l ../scripts/nsc-runtime.js
Set CONFIG.hosts in the script to:
hosts: ['www.vaultpay.io', 'img.cdn.vaultpay.io', 'assets.cdn.vaultpay.io',
'api.vaultpay.io', 'v2.api.vaultpay.io', 'telemetry-vaultpay.example']
Then check the two things a static read can never fully settle:
- The real
expirationTimethe platform stored for theimg.cdn.vaultpay.iopin-set, in epoch milliseconds. Convert it. Does it match your Q3 answer? - The anchor sources for
api.vaultpay.io, and whether the user entry carries[overridePins].
Verification checkpoint If
nsc-runtime.jsprints a pin-set expiry forimg.cdn.vaultpay.iothat is not2023-03-01T00:00:00in your device's local time, one of your assumptions about the platform's date parsing is wrong, and finding out which is worth more than the flag.
Hints¶
Read them one at a time, and only when stuck.
Hint 1 — Q2
The nested `Hint 2 — Q3
2023 is not a leap year. The platform parses this with `new SimpleDateFormat("yyyy-MM-dd")`. Look up what `Calendar.setLenient(boolean)` defaults to and what a lenient calendar does with a field that is out of range. It does not throw.Hint 3 — Q4
The pin-set is live — its expiry really is in 2031. So the pins are enforced. Now read `NetworkSecurityTrustManager.isPinningEnforced()` in [README §3.6](../README.md#3-deep-internal-working) again, and confirm that it has **three** exit conditions, not one. Then look at the `Hint 4 — Q6
Two different questions are hiding in Q6. The first is whether the block applies at all, which the manifest settles. The second is what the block would do if it did apply, and that turns on a default value that the developer did not write and probably does not know about. See the attribute reference table in [README §3.2](../README.md#3-deep-internal-working) — one row has two different defaults in the same cell.Hint 5 — Q7
Five scopes: `Answer key¶
Do not read this until you have written your own answers down.
Full answers and the flag
### Q1 — `www.vaultpay.io` No `<application android:usesCleartextTraffic="false" ... >
<base-config cleartextTrafficPermitted="true" />
NSC{3_2023-03-01_api.vaultpay.io}
Success criteria¶
- You produced the flag without reading the answer key.
- Every answer you wrote names a mechanism — an inheritance rule, a class, an attribute default — rather than describing an impression.
- You correctly identified the one scope in the document that is genuinely fine.
- You correctly identified the one "finding" that is not one.
- You can explain why the tool's
NSC-002count and the correct answer to Q7 differ, and why that is not a bug in the tool. - If you built it: the runtime dump's
expirationTimeforimg.cdn.vaultpay.iomatched your Q3 answer, and theapi.vaultpay.ioanchor list showedUserCertificateSource [overridePins].
Where to go next¶
- README §5 — writing each of these up so it survives a developer's response.
- Chapter 36 —
api.vaultpay.io's pin-set is live for every anchor except the one the developers added. Defeating a pin that is genuinely live is a different problem. - 10-APK-Internals lab 04 — a CTF built on the layer below this one, where the decoder is what disagrees rather than the reader.