Lab 02 — The sheet lies: six commands that answer confidently and wrongly¶
Difficulty: Intermediate Time: 90 minutes. Prerequisites: Lab 01. An Android device or emulator with
adb. Root helps but is not required — rounds 3, 4 and 5 work without it, and round 1 is more instructive if you have root and think you might not. Constraint: for each round, you must state how you knew the answer was wrong before you are allowed to look at the reveal.
1. The challenge¶
Every command in this lab is real, appears in published Android security cheat sheets, and runs cleanly. Every one of them returns an answer that is plausible, confidently formatted, and wrong — on the device in front of you, right now.
None of them errors. That is the entire point.
Mental Model A command that fails loudly costs you five seconds. A command that returns a plausible wrong answer costs you an hour, and sometimes costs you a report. The skill this lab builds is not knowing these six specific commands — it is the reflex of asking "what would this print if it were lying to me?" before you write the answer down.
Six rounds. For each one:
- Run the obvious command exactly as printed.
- Write down the answer it gives.
- Before reading the reveal, write down at least one way you could check it independently.
- Run your check.
- Then open the reveal.
Keep a log. The log is the deliverable.
ROUND n
obvious command :
answer it gave :
my cross-check :
what it showed :
verdict : TRUE / FALSE / UNDETERMINED
how I could have known without the cross-check :
2. Setup¶
# host — from 76-CheatSheets/
bash examples/03-session-preflight.sh --pkg <a debuggable package>
Record the output. Several rounds depend on knowing the build type and page size, and one of the lies is only visible because you know which device you are on.
If you have no debuggable package to hand, build a one-activity "hello world" and install it with
adb install -t. Rounds 3 and 4 need an app vantage.
3. Round 1 — "Is this device rooted?"¶
The obvious command¶
# host — the form that appears in dozens of published sheets
adb shell "su -c id" # lint:allow -- this IS the round
Run it. Write down what it printed and what you would conclude.
Your cross-check goes here¶
Before reading on: what else could tell you whether this device has root? Think of at least two answers and run them.
Reveal — Round 1
On the AVD used to write this chapter (`sdk_gphone16k_x86_64`, Android 15 / API 35, `userdebug`), that command prints:su: invalid uid/gid '-c'
$ adb shell "su 0 id"
uid=0(root) gid=0(root) groups=0(root),1004(input),... context=u:r:su:s0
# host
adb shell 'grep -c magisk /proc/self/mountinfo' # returned 3
adb shell 'ls -l /debug_ramdisk/magisk' # -rwxr-xr-x root root 428416
| `adb shell "su 0 id"` | `root` | `all` | AOSP su: every userdebug build, every AVD |
| `adb shell "su -c id"` | `root` | `phys` | Magisk su on a phone. FAILS on AOSP su, in the shape of "not rooted" |
4. Round 2 — "What version of Magisk is installed?"¶
Skip this round if the device is not rooted; go to Round 3.
The obvious commands¶
# host — two published forms, run both
adb shell "su -c 'magisk -v'" # lint:allow -- this IS the round
adb shell "su 0 magisk -v"
Your cross-check¶
How would you get a version number you can actually trust?
Reveal — Round 2
$ adb shell "su -c 'magisk -v'"
su: invalid uid/gid '-c'
$ adb shell "su 0 magisk -v"
su: failed to exec magisk: No such file or directory
$ adb shell "su 0 /debug_ramdisk/magisk -v"
30.7:MAGISK:R
$ adb shell "su 0 sh -c 'echo $PATH'"
/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin
5. Round 3 — "Is Frida working on this device?"¶
This is the best round in the lab, because the misleading output is long, detailed, and completely genuine.
The obvious command¶
# host
frida-ps -U
Run it. Do you have working instrumentation?
Your cross-check¶
Reveal — Round 3
On the AVD, `frida-ps -U` returns a full, correct process list — dozens of rows, real PIDs, real process names, `zygote64` at the bottom. There is **no `frida-server` running.** Checked from both vantages:$ adb shell 'ps -A' | grep -i frida
$ echo $?
1
$ adb shell 'su 0 ps -A' | grep -i frida
$ echo $?
1
$ frida -U -n zygote64 -e 'console.log("HOOKED")' -q
Failed to attach: unable to connect to remote frida-server: closed
$ echo $?
1
$ adb shell "su 0 /data/local/tmp/frida-server --version"
CANNOT LINK EXECUTABLE "/data/local/tmp/frida-server": empty/missing DT_HASH/DT_GNU_HASH in
"/data/local/tmp/frida-server" (new hash type from the future?)
$ adb shell "su 0 sh -c '/data/local/tmp/frida-server --version >/dev/null 2>&1; echo devrc=$?'"
devrc=1
# host
frida -U -n <any running process> -e 'console.log("ok")' -q
6. Round 4 — "Does /system/xbin/su exist?"¶
The obvious commands¶
# host
adb shell 'ls -l /system/xbin/su'
adb shell "run-as <your-debuggable-pkg> sh -c 'test -e /system/xbin/su && echo EXISTS || echo NO'"
Two commands, one question. Run both.
Your cross-check¶
Reveal — Round 4
$ adb shell 'ls -l /system/xbin/su'
-rwsr-x--- 1 root shell 51224 2025-01-23 23:03 /system/xbin/su
$ adb shell "run-as com.example.debuggable sh -c 'test -e /system/xbin/su && echo EXISTS || echo NO'"
NO
$ adb shell 'ls -l /system/bin/su /debug_ramdisk/su'
ls: /system/bin/su: No such file or directory
lrwxrwxrwx 1 root root 8 ... /debug_ramdisk/su -> ./magisk
# host — from 76-CheatSheets/
bash scripts/vantage.sh --file /system/xbin/su --pkg <your-debuggable-pkg>
7. Round 5 — "Did the pipeline succeed?"¶
No device needed. Run this on your host.
The obvious script¶
# host — careful, idiomatic shell
bash -c '
set -euo pipefail
seq 1 5000000 | head -3 > /dev/null || echo "no output — the producer failed"
echo "reached the end"
'
Does it print the fallback? Should it?
Your cross-check¶
Reveal — Round 5
Measured:$ bash -c 'set -o pipefail; yes | head -3 >/dev/null; echo $?'
141
$ bash -c 'set -o pipefail; seq 1 100000 | grep -q 5; echo $?'
141
$ bash -c 'set -o pipefail; seq 1 100000 | grep -c 5 >/dev/null; echo $?'
0
$ bash -c 'set -o pipefail; seq 1 10000 | head -3 >/dev/null; echo $?'
0
# host
n=$(readelf --dyn-syms lib.so | grep -c '^Java_') # grep -c reads ALL its input
if [ "$n" -eq 0 ]; then
echo "no statically-registered JNI symbols (RegisterNatives is still possible)"
fi
8. Round 6 — "Is this an emulator?"¶
The obvious check¶
Here is the most-copied isEmulator() on the internet, reduced to the two lines that do the work:
// The shape that appears in thousands of apps.
boolean isEmulator() {
return Build.FINGERPRINT.startsWith("generic")
|| new java.io.File("/dev/qemu_pipe").exists();
}
Evaluate both halves from the shell:
# host
adb shell getprop ro.build.fingerprint
adb shell 'ls /dev/qemu_pipe'
Your cross-check¶
Reveal — Round 6
On a stock current AVD:$ adb shell getprop ro.build.fingerprint
google/sdk_gphone16k_x86_64/emu64xa16k:15/AE3A.240806.043/12960925:userdebug/dev-keys
$ adb shell 'ls /dev/qemu_pipe'
ls: /dev/qemu_pipe: No such file or directory
$ adb shell 'ls /dev/goldfish_pipe_dprctd'
/dev/goldfish_pipe_dprctd
$ adb shell getprop ro.kernel.qemu
1
9. Review¶
9.1 Score your own detection, not your knowledge¶
For each round, one of three:
| Meaning | |
|---|---|
| Caught it | You wrote a cross-check that would have exposed the lie, before the reveal |
| Suspected it | You felt something was off but could not name the check |
| Believed it | You wrote the answer down |
Most people believe rounds 3 and 5 the first time. Round 3 in particular, because the output is so detailed and so genuine.
9.2 The pattern behind all six¶
Write it out yourself before reading this.
What the six have in common
Every one of them **answers a narrower question than the one you asked**, and reports the answer in the vocabulary of the wider one. | You asked | It actually answered | |---|---| | Is this rooted? | Does this `su` accept `-c`? | | What Magisk version? | What version does the binary that got the `-v` flag report? | | Can Frida instrument? | Can adb enumerate processes? | | Does the file exist? | Can *this uid* see the file? | | Did the pipeline succeed? | What status did the writer exit with? | | Is this an emulator? | Does this specific 2014-era artefact exist? | That is also, precisely, the shape of the link-checker defect this repository recorded against itself — a check reporting "no broken links" that meant "no broken links outside an excused category nobody had audited", which hid 1,512 of them. And it is the shape of this repository's first `su -c` detector, which found 79 of 376 occurrences because its pattern could not see the double-quoted form. **A detector's blind spot is invisible in its output.** The only defence is to ask what narrower question the command is really answering, and then to close the arithmetic — explain every hit, and go looking for the ones you did not get.9.3 Turn each round into a row¶
Six rounds, six rows, to the standard in
../examples/01-anatomy-of-a-sheet-row.md: the broken
form marked broken, the working form with its Needs and Device, and the failure shape stated.
Then lint your own file:
# host — from 76-CheatSheets/
python3 -B scripts/lint-commands.py --path /path/to/your-rows.md --no-fail
If you wrote the broken forms as counter-examples on purpose, mark them:
adb shell su -c 'id' # lint:allow SU-DASH-C SU-DASH-C-BARE
Rule ids match exactly — lint:allow SU-DASH-C does not also silence SU-DASH-C-BARE. Use a
bare lint:allow when you mean the whole line, and a marker on the line above a fence to cover a
whole block.
10. Success criteria¶
- A log for all six rounds with a cross-check written before each reveal.
- Each round scored caught it / suspected it / believed it, honestly.
- The common pattern in §9.2 written in your own words before reading it.
- Six sheet rows produced, each naming the broken form as well as the working one.
- Your rows pass
lint-commands.py, or every finding is a marked counter-example. - One sentence in your notes naming a command you rely on outside this lab that might be answering a narrower question than you think.
That last one is the whole lab.
11. Extension — find a seventh¶
Somewhere in the sheets you use daily is a command with this shape. Candidates, all of which this repository has measured:
| Candidate | The narrower question it really answers |
|---|---|
pm list instrumentation |
Which packages declare instrumentation — blind to residue. A stock 247-package device reported zero rows; a 38-APK structural scan of the same device found 1 declared and 1 residue |
A grep over APKs for a short token |
Does this byte sequence occur? grep -i xposed matched 1,141 times across 237 APKs, all of them the word "exposed" |
jadx's finished with errors, count: N |
How many errors did the console summariser count? The output tree held 2,104 refused methods against a console figure of 61 |
ls -l *.apk after enabling shrinking |
How big is the padded file? Three APKs were byte-identical at 12,757 B with DEX sizes of 7,384 / 2,920 / 7,180 |
| A key attestation chain that verifies | Is the chain well-formed? On an emulator every key is SOFTWARE and the chain still verifies perfectly |
ro.boot.verifiedbootstate |
What string did a property whose value is attacker-controllable return? One device read green while a TEE-signed attestation from the same device said Unverified |
Pick one you actually use. Reproduce it. Write the row.
See also¶
lab-01-sixty-minute-triage.md— where the sheets are enoughlab-03-build-your-own-sheet.md— writing rows that do not lielab-04-ctf-the-stale-sheet.md— the same skill, adversarial../README.md§6 — thirty-three more of these../examples/02-vantage-transcript.md— the raw session behind rounds 1, 3 and 4