Lab 04 — CTF: The Deputy in the Browser¶
Difficulty: advanced
Time: 2 hours if labs 01–03 are fresh; 4 if you are reconstructing them
Prerequisites: Lab 01,
Lab 02 and
Lab 03; 43-WebView §3 in full
Artefacts: the apps you built with ../examples/build.sh — nothing new to
download
Everything in this CTF targets an application you built yourself. The listeners are on your own
machine, reached through adb reverse. No third-party software is touched at any point.
The brief¶
A development team has shipped com.pentest.ch43.vuln and their security lead has signed off on it
with this note:
"The WebView is fine. Our network security config is correct — HTTPS only, system anchors, no debug overrides — and it passes our CI gate. The
ContentProviderholding customer notes isandroid:exported="false", so nothing outside the app can reach it. We useaddJavascriptInterfacebut we are on a modern API level, so the oldgetClass()remote code execution is closed. The navigation allow-list restricts the WebView to our own domain."
Every sentence in that paragraph is either false, or true in a way that does not mean what they think it means. One of them is true in a way that will cost you forty minutes if you take it as an invitation rather than as a statement of fact.
Your job: capture five flags, and name the sentence that is the trap.
The confused deputy, since it is the title¶
A confused deputy is a program with more authority than its caller, which can be talked into using that authority on the caller's behalf. That is a WebView exactly:
- The page has no permissions and no UID of its own.
- The app has the INTERNET permission, a Linux UID, a private data directory, a SELinux domain, and a
ContentResolverthat speaks for it. - Every bridge call, every
content://fetch and everyfile://read the page makes is performed by the app, as the app.
The provider is not exported. It never needed to be. The deputy was already inside.
Rules¶
- Reason before you run. Predict the outcome of each flag's step before you take it, and write the prediction down. Where reality disagrees, you have found something worth more than the flag.
- Every answer names a mechanism. "It worked" is not an answer. "The bridge is origin-agnostic
because the injection happens per-
WebView, not per-origin" is. - Two flags are captured strings. Three are constructed from your own measurements, in the format each challenge specifies. No brute force is possible or intended.
- You may not read
LeakyBridge.java,NotesProvider.javaorVulnerableWebViewActivity.javauntil you have all five flags. You have read them in earlier labs; the point is to work from the APK and the device, as you would on a real target. - Only the apps you built. No third-party application is a valid source of any flag.
Setup¶
# host
cd 43-WebView/examples && ./build.sh --install
adb reverse tcp:8000 tcp:8000 # attack page + collector
adb reverse tcp:8443 tcp:8443 # the HTTPS listener from lab 02
adb shell pm list packages | grep ch43
Record the environment. Two of the five flags are only meaningful next to these numbers:
# host
adb shell getprop ro.build.version.release # 11
adb shell getprop ro.build.version.sdk # 30
adb shell dumpsys webviewupdate | grep "Current WebView package"
# (com.google.android.webview, 150.0.7871.181)
adb shell "su -c 'mount'" | grep -i "on /system/etc/security/cacerts"
# APatch on /system/etc/security/cacerts type tmpfs ... <-- read lab 02 Part 0 again
Flag 1 — The deputy is handed its instructions¶
The chain: an exported BROWSABLE deep link reaches an Activity, the Activity puts the Intent's
url query parameter into loadUrl, and a page of your choosing is now running inside the app.
Capture the app's session token from a page served over plain http:// from your own machine, with
no reverse engineering of the bridge.
Constraints that make it a challenge rather than a recipe:
- You must discover the bridge's name and its method list from inside the page, not from the APK and not from this repository's source files. If you already know the answer, prove you could have found it: your write-up must include the enumeration output, not the method names copied from memory.
- The page origin must be
http://, notfile://. That matters for flag 3.
Start here, and go no further into the source than the auditor's own output:
# host
python3 -B 43-WebView/scripts/webview-audit.py "$OUTDIR/vulnerable-webview/vulnerable-webview.apk"
Flag 1 is a literal string of the form CH43{...}, and it is the value the app considers its
session token.
Question to answer alongside it: the page is remote and the bridge answered anyway. State the
mechanism in one sentence — why does a http:// origin get the same bridge as the app's own asset
page?
Flag 2 — The deputy reads the file cabinet¶
NotesProvider is declared android:exported="false". Confirm that yourself from the APK's manifest
before you do anything else:
# host
python3 -B 10-APK-Internals/examples/parse_axml.py \
"$OUTDIR/vulnerable-webview/vulnerable-webview.apk" | grep -i -A4 provider
Then verify what "not exported" actually buys, from outside:
# host — a query from adb's own UID, which is NOT the app
adb shell content query --uri content://com.pentest.ch43.vuln.notes/note
That should fail with a permission denial. Good. The control works — against the thing it was designed to stop.
Now read the note anyway, from a web page, without calling any bridge method.
That last clause is the challenge. There are two routes from a page to a provider and only one of them is in scope for this flag:
| Route | In scope for flag 2? |
|---|---|
A bridge method that calls ContentResolver |
No. That is flag 1's mechanism again |
XMLHttpRequest / fetch directly at content://… with no Java involved |
Yes |
The direct route has a precondition that most write-ups get wrong. Lab 01 Part C measured it. If your
first attempt returns status=0 with an empty body, you have not failed — you have measured the
precondition, and you are one step from flag 3.
Flag 2 is a literal string of the form CH43{...}, and it is the body of the note.
Question to answer alongside it: the provider is not exported and a web page read it. In one sentence, why is that not a contradiction?
Flag 3 — The matrix, constructed¶
Fill in this table from your own runs, both rows, all four cells:
| Page origin | bridge call | XHR content:// |
XHR file:// |
|---|---|---|---|
http://127.0.0.1:8000/evil.html |
|||
file:///…/evil.html |
For the file:// row you need HTML the app will load locally. Model an attacker with any local-write
primitive; lab 01 step 9 shows the exact commands and the ownership fix that goes with them.
Flag 3 is constructed:
CH43{<scheme of the origin from which XHR content:// returns 200>_<the numeric status the OTHER origin got>}
Two fields. Lower case for the scheme, no colon, no slashes. If your two rows are identical you have made an error — most likely the file was planted with the wrong owner and the app could not read it, which produces a failure that looks like the wrong answer.
Question to answer alongside it: the app sets setAllowFileAccess(true),
setAllowFileAccessFromFileURLs(true) and setAllowUniversalAccessFromFileURLs(true), and
setAllowContentAccess is at its default true. All four are on, and one row of your table still
shows failures. Why? And what does that do to how you would write the finding — specifically, what
precondition must appear in it so a developer testing from a remote page does not dispute you?
Flag 4 — The deputy is lied to about who it is talking to¶
The security lead's claim was: "our network security config is correct — HTTPS only, system anchors, no debug overrides — and it passes our CI gate."
Verify the claim, then defeat it.
Part one — verify it, and get the exit code, because that is the part the lead is actually relying on:
# host
PYTHONIOENCODING=utf-8 python3 -B 44-NetworkSecurityConfig/scripts/nsc-audit.py \
43-WebView/examples/vulnerable-webview/network_security_config.xml \
--target-sdk 30 --debuggable false --fail-on HIGH > /dev/null; echo "exit=$?"
Part two — serve the attack page over HTTPS with a certificate self-signed by an issuer in no store anywhere (lab 02 Part D; and re-read lab 02 Part 0 for why it must not be a proxy CA on this device), point the deep link at it, and observe what the app decides.
Flag 4 is constructed:
CH43{<primaryError as an integer>_<the SslError constant with that value>_<the SslErrorHandler method the app called>}
Three fields. The constant in upper case exactly as android.net.http.SslError declares it; the
method name bare, with no parentheses and no class prefix.
You must also produce a control. A flag captured without one is not evidence — "the page loaded" is equally consistent with the certificate having been acceptable. Lab 02 Part E gives you the control and the per-host caching trap that will otherwise make you think your hook broke.
Question to answer alongside it: name the element of the network security config schema that would have prevented this, or state that none exists and say why the schema has nothing to say about it.
Flag 5 — The deputy leaves a door open¶
The app calls WebView.setWebContentsDebuggingEnabled(true) unconditionally, in every build. Find the
consequence on the device, not in the bytecode.
# host
adb shell "su -c 'cat /proc/net/unix'" | grep -i <the right string here>
Choosing the right string to grep for is the challenge. Lab 03 measured 20 static call sites and zero live sockets across a corpus of real apps, because every one of them was guarded — so a grep that finds nothing is a result you must be able to distinguish from a grep that was wrong. Most published guides give a socket name that does not exist on this platform, and a second one that belongs to a different application entirely.
Having found it, prove it is real by listing the DevTools targets:
# host
adb forward tcp:9222 localabstract:<the socket name you found>
curl -s http://127.0.0.1:9222/json/list
Flag 5 is constructed:
CH43{<the socket's name, without the leading @ and without the trailing _<pid>>}
One field. Exactly as it appears in /proc/net/unix, minus the abstract-namespace @ and minus the
process id.
Question to answer alongside it: abstract-namespace unix sockets have no filesystem path. State, in one sentence, what that means for who can attach to this socket — and then say why lab 03 downgraded this same observation to INFO on every real app it examined.
The trap¶
One of the five sentences in the security lead's note is a statement of fact that reads like an invitation. Chasing it is the single most common way to lose an afternoon in this chapter, because the thing it points at is the most famous WebView vulnerability ever published, it is plainly visible in any decompiler, and it has been dead since 2012.
You will know you are in it when a method you can see in the APK is undefined from JavaScript and
you start writing increasingly creative property accessors to reach it.
Name it in your write-up. State what it was, why it does not work here, what exactly closed it, and — the part that matters — what it did not close. A candidate who can explain the difference is worth more than one who found all five flags.
Scoring¶
| Points | |
|---|---|
| Flag 1 | 10 |
| Flag 2 | 15 |
| Flag 3 | 20 |
| Flag 4 | 25, and 0 without the control |
| Flag 5 | 10 |
| The trap, correctly named and explained | 20 |
Full marks require the trap. That is deliberate: it is worth as much as the hardest flag, and it is the only item on the list that is about not reporting something.
Hints¶
Hint 1 — Flag 1, discovering the bridge from the page
A Java bridge is an ordinary JavaScript object hanging off `window`. Every method the developer annotated is one of its enumerable properties. A `for…in` loop over `window`, filtering for objects whose properties are all functions, finds it in one line with no tooling at all. [`../examples/attacker-page/evil.html`](../examples/attacker-page/evil.html) already does this, and reading how it does it is in scope — it is the attacker's code, not the app's.Hint 2 — Flag 2, the direct route returns status 0
That is the correct result *from the origin you are currently on*, and it is the measurement flag 3 asks you to record. The relaxation you need is not a bridge and not a permission; it is a property of the **document**, not of the request. Read [README §3.8 and §3.9](../README.md), then look at which of the app's four file-related settings only take effect for a particular kind of origin.Hint 3 — Flag 3, my two rows are identical
Almost always the plant, not the measurement. After copying the HTML into the app's data directory as root, the file is owned by `root`, and the app's UID cannot read it — so the load fails and you attribute the failure to the origin rules.# host
OWNER=$(adb shell "su -c 'stat -c %u:%g /data/data/com.pentest.ch43.vuln/files'" | tr -d '\r')
adb shell "su -c 'chown $OWNER /data/data/com.pentest.ch43.vuln/files/evil.html'"
adb shell "su -c 'chmod 644 /data/data/com.pentest.ch43.vuln/files/evil.html'"
Hint 4 — Flag 4, the second run produces no SSL callback at all
Chromium **caches the proceed decision per host**. Once the app has proceeded for `127.0.0.1`, later navigations to `127.0.0.1` never re-enter the callback. Change the hostname — `localhost` is already in your certificate's SAN if you followed lab 02 — or `adb shell pm clear` between attempts. This trap has convinced more than one person that their Frida hook broke. It did not.Hint 5 — Flag 5, my grep finds nothing
You are almost certainly grepping for the package name. The socket is **not** named after the package. It is also not the name Chrome uses. Grep for the word `devtools` and read what comes back — the answer is in [README §3.13](../README.md), which measured this precisely because the commonly published name is wrong. If a `devtools` grep genuinely returns nothing, check the app is actually running and that a WebView has been created: force-stop, re-launch with the deep link, and grep again.Hint 6 — the trap
Which sentence in the brief is a *defence* the lead is claiming, rather than a *feature* they are describing? Two are defences. One of those two is genuinely, completely effective — against precisely one attack, which is not any of the five in this CTF. The version number that matters is not 30.Answer key¶
Do not open this until you have five flags and a name for the trap.
Full answers, the flags, and the trap
### Flag 1CH43{bridge_is_the_bug_not_the_annotation}
CH43{content_scheme_resolves_as_the_host_app}
CH43{file_0}
CH43{3_SSL_UNTRUSTED_proceed}
CH43VULN: SSL error ignored: primaryError=3 url=https://127.0.0.1:8443/evil.html
[SSL] --> app called handler.proceed() THE LOAD CONTINUES, certificate error and all
[SSL] --> app called handler.proceed(), forceCancel is ON so cancel() is being sent instead
[SSL] --> app called handler.cancel() the load is refused
CH43{webview_devtools_remote}
typeof AndroidBridge = object
typeof AndroidBridge.deviceInfo = function
typeof AndroidBridge.notExposed = undefined
typeof AndroidBridge.getClass = undefined
CH43{bridge_is_the_bug_not_the_annotation}
CH43{content_scheme_resolves_as_the_host_app}
CH43{file_0}
CH43{3_SSL_UNTRUSTED_proceed}
CH43{webview_devtools_remote}
Success criteria¶
- Five flags, captured or constructed, without opening the answer key.
- You named the trap, said what closed it, and said what it did not close.
- You enumerated the bridge from inside the page and have the output to show for it.
- Flag 4 is accompanied by a control, and you can explain why a flag without one is not evidence.
- You can state, in one sentence each: why a remote page reached the bridge; why an unexported provider answered a web page; why three "all on" settings still produced a blocked request.
- You recorded OS release, API level and WebView provider version — separately — and checked the device's CA store posture before making any claim about trust.
- You ran the
devtoolsgrep and understand why the same observation is a finding here and an INFO on every real app in lab 03's corpus.
Clean up — leave the device as you found it¶
# host
adb shell "su -c 'rm -f /data/data/com.pentest.ch43.vuln/files/evil.html'"
adb shell am force-stop com.pentest.ch43.vuln
adb reverse --remove-all
adb forward --remove-all
rm -f "$OUTDIR/ch43-tls/key.pem" "$OUTDIR/ch43-tls/cert.pem"
cd 43-WebView/examples && ./build.sh --uninstall
adb shell pm list packages | grep ch43 # must be empty
# host — from the repository root: no artefacts, nothing written into the repo
find . -name '__pycache__' -o -name '*.pyc' -o -name '*.apk' | head
Must print nothing. If it prints __pycache__, you ran a script without -B.
Where to go next¶
- README §5.8 — honest severity. Re-read it now that you have five flags and know how little most of them would be worth without their preconditions attached.
- 44-NetworkSecurityConfig — flag 4's other half, and its own CTF, where the configuration is what lies rather than the code.
- 36-CertificatePinning — what pinning that is genuinely live looks like, and why none of your WebView tooling touches it.
- 27-ContentProviders — flag 2's far end. The provider you read was a stub with one row; a real one is a database.
- 26-Intent and 30-Activities — flag 1's near end. The deep link is where a WebView finding usually begins, and it is not this chapter's.