Lab 01 — Map the IPC Surface¶
Difficulty: Beginner
Time: 90–120 minutes
Prerequisites: Chapter 24 §1–§3.13 and §3.22, 21-App-Sandbox,
23-Permissions, a test device or emulator with adb
Objective¶
Produce a complete, evidence-backed inventory of one application's IPC surface — including the four categories the manifest cannot show you — and then classify every entry as reachable by an ordinary app, reachable only from the shell, or not reachable.
You will finish with two artefacts: an inventory table, and a reachability table. The second one is the one that matters.
Why this matters¶
Ask ten testers to enumerate an app's attack surface and nine will hand you the exported-components
table from dumpsys package or MobSF. That table describes mediated IPC only: Intents, bound
services, broadcasts and providers. It is roughly half the surface.
The other half — abstract-namespace UNIX sockets, localhost listeners, shared memory, and file modes
— appears in no manifest, in no aapt2 dump badging output, and in no manifest-driven scanner. It is
where a large share of the genuinely interesting findings live, precisely because the tooling is
structurally blind to it.
This lab builds the habit of asking, every single time: what channels exist that the manifest cannot tell me about?
It also drills the discipline that the rest of the chapter depends on. Everything you enumerate here
comes from adb shell, which runs as UID 2000 with privileges an app does not have. Enumeration
proves a channel exists. It never proves an attacker can use it.
Setup¶
Choose a target¶
Use a deliberately vulnerable app you are authorised to test — InsecureBankv2, OVAA, DIVA or Injured Android from 80-Appendix are all rich enough. Any app you wrote yourself also works.
Do not use a banking app you did not write, and do not use anything on a device with real data.
# host
export PKG=com.example.target
adb devices
adb shell pm path $PKG
Get the APK and decompile it¶
# host
adb pull "$(adb shell pm path $PKG | head -1 | sed 's/package://' | tr -d '\r')" target.apk
apktool d -f target.apk -o work/ >/dev/null
jadx -d out/ target.apk >/dev/null 2>&1
Launch the app before you enumerate¶
This step is skipped constantly and it invalidates everything after it.
# host
adb shell monkey -p $PKG -c android.intent.category.LAUNCHER 1
sleep 8
Sockets are usually opened lazily — on first playback, first WebView load, first sync. A socket
that has not been created yet does not appear in /proc/net/unix, and you will record "no sockets"
for an app that has three.
Steps¶
Step 1 — Record the ground truth¶
# host
aapt2 dump badging target.apk | grep -E "package:|sdkVersion|targetSdkVersion"
apksigner verify --print-certs target.apk | grep -i "SHA-256"
adb shell getprop ro.build.version.release
adb shell getprop ro.build.version.sdk
adb shell getprop ro.build.version.security_patch
adb shell getprop ro.build.fingerprint
adb shell getenforce
Q1. What is the app's targetSdk? Name three platform mitigations that do not apply to this
app because of that value, and one that does. (Use the version matrix in
§3.2.)
Q2. Why is the device's SDK level the less important of the two numbers you just recorded?
Step 2 — The mediated surface, from the manifest¶
# host
grep -nE "<(activity|activity-alias|service|receiver|provider)" work/AndroidManifest.xml
grep -nE 'android:exported="true"' work/AndroidManifest.xml
grep -nE "<permission |protectionLevel" work/AndroidManifest.xml
grep -nE "grantUriPermissions|path-permission|android:authorities" work/AndroidManifest.xml
grep -n "sharedUserId\|android:process\|taskAffinity\|debuggable" work/AndroidManifest.xml
Cross-check, because a crafted APK can make two parsers disagree:
# host
aapt2 dump xmltree target.apk --file AndroidManifest.xml | grep -B2 -A2 exported
Build inventory table A. One row per component: type, fully-qualified name, exported value
(explicit or inferred), guarding permission, and the protection level of that permission.
# adb shell — resolve a declared permission's protection level on the device
dumpsys package permission com.example.target.permission.INTERNAL | grep -i protection
Q3. How many components are exported? How many of those have no guarding permission, or a
guard whose protection level is normal or dangerous? That second number is your working list.
Q4. Are there components with an <intent-filter> but no explicit android:exported? What is
their effective state, and what does the answer depend on?
Step 3 — The mediated surface, from the live device¶
# host
adb shell dumpsys package $PKG > pkg.txt
grep -n "exported=true" pkg.txt
adb shell dumpsys activity services $PKG | head -60
adb shell service list > services.txt
Q5. Does the live dumpsys view agree with the manifest? If not, which do you trust and why?
Q6. Anything belonging to your target in service list? What does its presence or absence tell
you about how the app's own services are reached?
Step 4 — The channels the manifest cannot show (the point of the lab)¶
Now go looking for direct IPC. Four categories, four commands.
# adb shell — 1. abstract-namespace UNIX sockets
cat /proc/net/unix | grep '@'
# adb shell — 2. listening TCP sockets; st==0A means LISTEN
cat /proc/net/tcp | awk 'NR>1 && $4=="0A" {print $2, $8, $10}'
cat /proc/net/tcp6 | awk 'NR>1 && $4=="0A" {print $2, $8, $10}'
netstat -tulpn 2>/dev/null
# adb shell as root — 3. open file descriptors, and shared memory
PID=$(pidof -s com.example.target)
ls -l /proc/$PID/fd
grep -E "ashmem|memfd|dmabuf" /proc/$PID/maps
# adb shell as root — 4. file modes and SELinux labels
ls -ldZ /data/data/com.example.target
ls -laZ /data/data/com.example.target/shared_prefs
find /data/data/com.example.target -type f -perm -o+r 2>/dev/null
Q7. Decode one line of /proc/net/tcp by hand. The local_address column is IP:PORT with the
IP in little-endian hex. What is 0100007F:1F90? What is 00000000:1F90, and why is the
difference important?
Q8. For each abstract socket you found, what protects it? Answer precisely — name the access control that applies, or state that none does.
Q9. /proc/net/unix does not name the owning process. How do you attribute a socket to one?
Step 5 — Corroborate statically¶
Everything you found at runtime should have a corresponding call in the code. Everything in the code should have appeared at runtime — and if it did not, you did not exercise the right feature.
# host
grep -rn "LocalServerSocket\|LocalSocketAddress\|Namespace.ABSTRACT" out/sources/
grep -rnE "new ServerSocket\(|ServerSocketChannel|NanoHTTPD|MockWebServer" out/sources/
grep -rn "MemoryFile\|SharedMemory\|ashmem\|memfd" out/sources/
grep -rn "MODE_WORLD_READABLE\|MODE_WORLD_WRITEABLE\|setReadable(true, *false)" out/sources/
grep -rn "ClipboardManager\|setPrimaryClip" out/sources/
grep -rn "getCallingUid\|getCallingPid\|clearCallingIdentity" out/sources/
grep -rn "PendingIntent.get\|FLAG_MUTABLE" out/sources/
And the native libraries, because the Java layer can be clean while a bundled .so opens a socket:
# host
for so in $(find work/lib -name '*.so' 2>/dev/null); do
echo "== $so"
strings -a "$so" | grep -aE "^@[A-Za-z0-9._-]{3,}$|127\.0\.0\.1|0\.0\.0\.0|\.sock|/dev/socket"
nm -D --defined-only "$so" 2>/dev/null | grep -iE "socket|bind|listen|accept"
done
Q10. Did the static sweep find any channel the runtime enumeration missed? What would explain that?
Q11. Did the runtime enumeration find any channel the static sweep missed? What would explain that?
Step 6 — Run the scripted version and compare¶
# host
../scripts/enumerate-ipc-surface.sh $PKG ./out-$PKG
python3 ../scripts/ipc-surface-report.py ./out-$PKG/ipc-surface.txt \
--manifest work/AndroidManifest.xml --md ./out-$PKG/report.md
Q12. Did the script find anything you missed by hand? Did you find anything it missed? A script you cannot out-perform on a careful pass is a script you do not understand.
Step 7 — Watch it happen from inside¶
# host
frida -U -f $PKG -l ../scripts/trace-ipc.js
Exercise the app: log in, open a media item, open anything that loads a WebView, trigger a sync. Then in the Frida REPL:
ipc.summary()
Q13. Which channels does the app actually use, as opposed to merely declare? Did anything appear here that neither the static nor the runtime sweep found?
Step 8 — The step that makes it a finding¶
Everything so far ran as shell, UID 2000. Now repeat the key results from an ordinary application.
# host
cd ../examples/attacker-app
# edit AndroidManifest.xml: put the target in <queries>, including provider authorities
gradle assembleDebug
adb install -r build/outputs/apk/debug/attacker-app-debug.apk
adb logcat -c
adb shell am start -n com.attacker.poc/.ProbeActivity --es target $PKG
adb logcat -s poc:I | tee ../../evidence-probe.txt
Build reachability table B:
| Channel | Reachable from adb shell |
Reachable from the probe APK | Verdict |
|---|---|---|---|
Q14. How many entries are reachable from the shell but not from the app? Those are the false positives you would have reported. What is the mechanism that explains the difference?
Q15. Did the probe app report ABSENT for anything you know exists? What is the first thing to
check, before concluding it is unreachable?
Step 9 — Write it up¶
For every channel that is genuinely app-reachable, produce: the channel, the exact command or code
that reaches it, the observable result, the identity you used, the device fingerprint and the app's
targetSdk.
Then, for at least one channel, write the paragraph explaining why it is not a finding.
Hints¶
Hint 1 — /proc/net/unix is empty of `@` entries
Three possibilities, in order of likelihood: 1. The app has not run the code path. Launch it, use it properly for a minute — play something, open a WebView, sign in — and look again. 2. You are grepping for the package name. `/proc/net/unix` shows only the socket *name*, and the name frequently has nothing to do with the package. Grep for `@` alone and read the whole list. 3. There genuinely are none, which is a legitimate result. Record it. A before/after diff is the sharpest technique here:# adb shell
cat /proc/net/unix > /data/local/tmp/before.txt
# ... use the app feature ...
cat /proc/net/unix > /data/local/tmp/after.txt
diff /data/local/tmp/before.txt /data/local/tmp/after.txt
Hint 2 — decoding /proc/net/tcp
The `local_address` field is `IP:PORT`. The port is straightforward big-endian hex. The IP is **little-endian**, so you reverse the byte pairs:0100007F -> 7F 00 00 01 -> 127.0.0.1
00000000 -> 0.0.0.0 -> ALL INTERFACES
1F90 -> 8080
# adb shell
cmd package list packages --uid 10199
Hint 3 — `netstat -tulpn` shows no process names
Process attribution in `netstat` needs privileges that plain `adb shell` may not have on your build. Use the `uid` column of `/proc/net/tcp` and `cmd package list packages --uid` instead — that route works unprivileged and is the one to learn.Hint 4 — the probe APK reports everything ABSENT
Your `<queries>
<package android:name="com.example.target" />
<provider android:authorities="com.example.target.provider" />
</queries>
Hint 5 — `dumpsys package` output is enormous
Slice it by resolver table:# host
sed -n '/Activity Resolver Table:/,/Receiver Resolver Table:/p' pkg.txt > activities.txt
sed -n '/Receiver Resolver Table:/,/Service Resolver Table:/p' pkg.txt > receivers.txt
sed -n '/Service Resolver Table:/,/Provider Resolver Table:/p' pkg.txt > services.txt
sed -n '/Provider Resolver Table:/,/Key Set Manager:/p' pkg.txt > providers.txt
Solution¶
Answers
**Q1–Q2.** The app's `targetSdk` decides which mitigations apply; the device's SDK level only decides which mitigations *exist*. An app targeting API 22 running on Android 14 still gets: implicitly exported components with intent filters, `MODE_WORLD_READABLE` working rather than throwing, implicit broadcasts reaching manifest receivers, mutable `PendingIntent` by default, and no package visibility filtering. Mitigations that apply regardless of `targetSdk` are the ones enforced device-wide, such as the Android 10+ clipboard focus restriction. Record both numbers; judge with the first. **Q3–Q4.** A component with an `Success criteria¶
- You recorded the app's
targetSdk, the device fingerprint, the patch level and the SELinux mode - You produced inventory table A with the protection level of every guarding permission
- You cross-checked the manifest against
aapt2 dump xmltreeanddumpsys package - You enumerated all four direct-IPC categories: abstract sockets, TCP listeners, FDs and shared memory, file modes
- You decoded at least one
/proc/net/tcpline by hand and can explain0100007Fvs00000000 - You attributed at least one socket to a process by matching its inode against
/proc/<pid>/fd - You corroborated the runtime findings against a static sweep, including native libraries, and explained every discrepancy in both directions
- You ran
enumerate-ipc-surface.shandipc-surface-report.pyand compared against your manual work - You ran
trace-ipc.jsand identified at least one channel the app uses that you had not found - You built and ran the unprivileged probe APK and produced reachability table B
- You can state how many shell-only entries would have been false positives
- You wrote at least one paragraph explaining why something is not a finding
- You can answer, in one sentence, why enumeration from
adb shellnever proves reachability