Lab 05 — CTF: One Command, One Flag¶
Difficulty: Advanced Time: 2–3 hours Prerequisites: Labs 01–04, and the whole of Chapter 77
The challenge¶
Twelve questions. Each is answerable with a single command — one line, one invocation, no scripts, no chaining a dozen tools together.
Some are easy if you know the right command and infuriating if you do not. That is the point: this lab tests whether the command surface has become reflex, which is the difference between a tester who takes ten minutes to answer a question and one who takes ten seconds.
Rules:
- One command per question. A pipeline (
cmd | grep) counts as one. Aforloop does not. - No writing files. No Frida. No decompilers.
- You may use
adb shelland anything on the device or in the SDK. - If you need two commands, you have not found the right one — keep looking.
Score yourself honestly. Eight or more without hints is a good result.
Setup¶
Any device with a few third-party apps installed. A deliberately vulnerable app from 80-Appendix makes several questions more interesting.
# host
adb devices -l
adb shell pm list packages -3 | head
Pick one third-party package as $PKG for the questions that need a target.
The questions¶
Q1 — Which screen am I looking at?¶
The device is showing some app. Name the exact Activity class currently in focus.
Answer
adb shell dumpsys window | grep mCurrentFocus
Q2 — Where is this app's APK?¶
Given a package name, print the full path(s) of its APK file(s) on disk.
Answer
adb shell pm path com.example.target
Q3 — Is this app debuggable?¶
Determine whether an installed app has the debuggable flag, without pulling or decoding the APK.
Answer
adb shell dumpsys package com.example.target | grep -i "flags="
adb shell run-as com.example.target id
Q4 — What is this app's UID?¶
Print the Linux UID assigned to a package.
Answer
adb shell dumpsys package com.example.target | grep userId=
Q5 — Show me only this app's log output¶
Filter logcat to a single running app, without knowing its PID in advance.
Answer
adb logcat --pid=$(adb shell pidof -s com.example.target)
Q6 — Which apps on this device can talk to the internet?¶
List every third-party package holding the INTERNET permission.
Answer
adb shell 'for p in $(pm list packages -3 | sed s/package://); do dumpsys package $p | grep -q "android.permission.INTERNET" && echo $p; done'
adb shell dumpsys package | grep -B40 "android.permission.INTERNET: granted=true" | grep "^Package \[" | sort -u
adb shell 'cat /proc/net/xt_qtaguid/stats 2>/dev/null | head'
Q7 — Is there anything listening on localhost?¶
Find TCP services bound to the loopback interface. These are reachable by any app holding
INTERNET and are a recurring real-world finding.
Answer
adb shell netstat -tlnp 2>/dev/null | grep -E '127\.0\.0\.1|::1'
adb shell cat /proc/net/tcp
Q8 — What did this app write when I logged in?¶
Without decompiling, show every file in the app's private storage modified in the last two minutes.
Answer
adb shell "su -c 'find /data/data/com.example.target -type f -mmin -2 -exec ls -la {} \;'"
adb shell run-as com.example.target find . -type f -mmin -2
Q9 — Prove this device's boot chain is intact¶
In one command, print every property that establishes whether Verified Boot and dm-verity are enforcing.
Answer
adb shell getprop | grep -E 'verifiedboot|flash.locked|veritymode|build.tags|debuggable|secure'
Q10 — Read a content provider you were not meant to read¶
Given an app with an exported provider at authority com.example.target.provider, dump the contents of
its users table.
Answer
adb shell content query --uri content://com.example.target.provider/users
adb shell content query --uri content://com.example.target.provider/users --sort "1=(SELECT 1)"
Q11 — Which certificate signed this app?¶
Print the signing certificate's SHA-256 digest for an installed package, without pulling the APK.
Answer
adb shell dumpsys package com.example.target | grep -A3 "signing details\|signatures"
apksigner verify -v --print-certs target.apk
Q12 — Make every method in this app interpreted¶
Put an app into the state where Frida hooks land reliably at every call site.
Answer
adb shell cmd package compile -m verify -f com.example.target
Scoring¶
| Score | Assessment |
|---|---|
| 11–12 | The command surface is reflex. You will not lose time to tooling. |
| 8–10 | Solid. Note which you missed and drill those. |
| 5–7 | Working knowledge with real gaps. Re-read §3 of the chapter. |
| Under 5 | Work through Labs 01–04 first; this one is premature. |
Part 2 — Build your own¶
The real exercise. Write five new questions of the same shape, each answerable in one command, each teaching something the twelve above do not.
Constraints:
- No two may use the same primary tool
- At least one must use
service callor raw Binder - At least one must be about the device, not an app
- At least one must have a trap — an obvious wrong answer that looks right
Write them with answers and hand them to someone else.
Q13. Which was harder: answering the twelve, or writing five good ones? Why?
Debrief¶
Answer in writing:
- For each question you missed, what was the underlying gap — a command you did not know, or a subsystem you did not know existed?
- Three questions have traps (Q2 splits, Q5 multi-process, Q10 shell-vs-app). Did you hit any? What would each have cost you in a real engagement?
- Q12's answer is arguably two commands. Does that matter? What does the ambiguity tell you about how the compiler filter actually takes effect?
- Which of the twelve would you run first on an unfamiliar device, and why that one?
Success criteria¶
- You attempted all twelve before opening any answer
- You scored 8 or above unaided
- For every miss, you identified whether the gap was a command or a subsystem
- You hit — and can explain — the split-APK, multi-process and shell-vs-app traps
- You wrote five original questions meeting all four constraints
- You handed them to someone else and they were solvable
- You answered all four debrief questions in writing
-
dumpsys window | grep mCurrentFocusandcmd package compile -m verify -fare now muscle memory