TExcelTAD
Home › Wireless, IoT & Mobile Security › Testing the Course's Sample App: Lab Sessions

Testing the Course's Sample App: Lab Sessions

Static checks of the manifest, the plist and the code find most configuration flaws, but a review isn't finished until the findings are confirmed on a running app: does the exported activity really open without login, does the token really appear in the log, does the release build really refuse a proxy? This lesson walks through a test of the course's sample app as labelled lab sessions: the commands a tester runs and what they show, with a static-analysis report triaged in Python. Android is shown; the iOS workflow is the same with Xcode's console, a test device and the same proxy.

Scope of every session in this lesson. Target: the course's own sample app LabHome 2.3.0 (test.lab.labhome), debug and release builds built by the app team for the test. Device: the Android emulator lab-emu-01 (no personal data), test account tester@lab.test on the lab backend api.lab.test. Authorised by the app owner for the test window. The transcripts are synthetic. Testing apps you don't own or aren't authorised to test, or bypassing protections of third-party apps, is outside this course and may be illegal.

The test plan

Step Tool Confirms MASVS
1. static scan of the APK MobSF (static analysis) manifest, code, network and secret findings to verify all
2. logs during login adb logcat secrets in logs STORAGE-2
3. app storage adb shell run-as (debug build) what is stored and how STORAGE-1
4. exported components adb shell am, content IPC exposure PLATFORM-1
5. network intercepting proxy with its CA on the emulator cleartext, validation, pinning NETWORK-1, -2
6. runtime observation Frida (frida-trace) on the debug build which crypto and storage APIs are actually called CRYPTO, STORAGE

Step 1: static analysis and triage

MobSF (Mobile Security Framework) decompiles the APK and reports manifest settings, risky code patterns, network configuration and embedded secrets. Tools report candidates; the tester confirms or dismisses each one, and the report says which. An excerpt of the JSON export (synthetic; MobSF-style, rule names illustrative), triaged:

python · try it yourself
import json

# Excerpt of a static-analysis report of LabHome 2.3.0 (synthetic; MobSF-style JSON, rule names illustrative)
report = json.loads("""{
 "app_name": "LabHome", "package_name": "test.lab.labhome", "version_name": "2.3.0", "target_sdk": "35",
 "manifest_analysis": [
  {"rule": "android_debuggable", "severity": "high", "component": "application"},
  {"rule": "android_allowbackup", "severity": "warning", "component": "application"},
  {"rule": "exported_activity", "severity": "high", "component": "test.lab.labhome.DeviceAdminActivity"},
  {"rule": "exported_activity", "severity": "high", "component": "test.lab.labhome.PairingLinkActivity"}],
 "code_analysis": [
  {"rule": "android_logging", "severity": "info", "files": ["SessionStore.kt", "third_party/okhttp3/Logger.kt"]},
  {"rule": "cbc_or_ecb", "severity": "high", "files": ["CacheCrypto.kt"]},
  {"rule": "webview_javascript_interface", "severity": "warning", "files": ["HelpScreen.kt"]},
  {"rule": "hardcoded_secret", "severity": "warning", "files": ["CacheCrypto.kt", "res/values/strings.xml"]}],
 "network_security": [{"rule": "cleartext_domain", "severity": "high", "scope": "api.lab.test"},
                      {"rule": "user_certificates_trusted", "severity": "high", "scope": "base-config"}]
}""")

# Triage decisions made by the reviewer after checking each item by hand
TRIAGE = {
    ("exported_activity", "test.lab.labhome.PairingLinkActivity"): "false positive: deep link must be exported; input validated (tested)",
    ("android_logging", "third_party/okhttp3/Logger.kt"): "accepted: library code, no secrets logged (checked in logcat)",
}
MASVS = {"android_debuggable": "RESILIENCE-4", "android_allowbackup": "STORAGE-2", "exported_activity": "PLATFORM-1",
         "android_logging": "STORAGE-2", "cbc_or_ecb": "CRYPTO-1", "webview_javascript_interface": "PLATFORM-2",
         "hardcoded_secret": "CRYPTO-2", "cleartext_domain": "NETWORK-1", "user_certificates_trusted": "NETWORK-1"}
rows = []
for section in ("manifest_analysis", "code_analysis", "network_security"):
    for f in report[section]:
        for where in f.get("files", [f.get("component") or f.get("scope")]):
            decision = TRIAGE.get((f["rule"], where), "confirmed")
            rows.append((f["severity"], f["rule"], where.replace("test.lab.labhome.", "."), MASVS[f["rule"]], decision))
order = {"high": 0, "warning": 1, "info": 2}
print(f"{report['app_name']} {report['version_name']} ({report['package_name']}), target SDK {report['target_sdk']}")
for sev, rule, where, ctrl, decision in sorted(rows, key=lambda r: order[r[0]]):
    print(f"{sev:7} {rule:28} {where:30} {ctrl:12} {decision}")
confirmed = sum(r[4] == "confirmed" for r in rows)
print(f"{len(rows)} tool findings -> {confirmed} confirmed, {len(rows) - confirmed} triaged out")
LabHome 2.3.0 (test.lab.labhome), target SDK 35
high    android_debuggable           application                    RESILIENCE-4 confirmed
high    exported_activity            .DeviceAdminActivity           PLATFORM-1   confirmed
high    exported_activity            .PairingLinkActivity           PLATFORM-1   false positive: deep link must be exported; input validated (tested)
high    cbc_or_ecb                   CacheCrypto.kt                 CRYPTO-1     confirmed
high    cleartext_domain             api.lab.test                   NETWORK-1    confirmed
high    user_certificates_trusted    base-config                    NETWORK-1    confirmed
warning android_allowbackup          application                    STORAGE-2    confirmed
warning webview_javascript_interface HelpScreen.kt                  PLATFORM-2   confirmed
warning hardcoded_secret             CacheCrypto.kt                 CRYPTO-2     confirmed
warning hardcoded_secret             res/values/strings.xml         CRYPTO-2     confirmed
info    android_logging              SessionStore.kt                STORAGE-2    confirmed
info    android_logging              third_party/okhttp3/Logger.kt  STORAGE-2    accepted: library code, no secrets logged (checked in logcat)
12 tool findings -> 10 confirmed, 2 triaged out

The two dismissed items show why triage matters: the deep-link activity must be exported (its risk is input validation, tested separately), and the logging call in a library writes no secrets. A report that lists raw tool output wastes the developers' time and buries the real problems.

Step 2: secrets in the log

Lab session, debug build, logging in with the test account:

console
tester@bench:~$ adb -s lab-emu-01 logcat -c
tester@bench:~$ adb -s lab-emu-01 logcat --pid="$(adb -s lab-emu-01 shell pidof test.lab.labhome)" | grep -i token
01-15 10:00:03.412  4321  4321 D LabHome : login ok, token=lab-test-token-1f2e3d

Confirmed (SessionStore.kt line 3 from the code-flaws lesson). Repeat with the release build: if the line appears there too, the finding is high; logs are readable through adb and collected in bug reports.

Step 3: what the app stores

run-as runs a shell as the app's user, which works only for debuggable builds:

console
tester@bench:~$ adb -s lab-emu-01 shell run-as test.lab.labhome cat shared_prefs/session.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <string name="access_token">lab-test-token-1f2e3d</string>
</map>
tester@bench:~$ adb -s lab-emu-01 install -r labhome-2.3.0-release.apk && adb -s lab-emu-01 shell run-as test.lab.labhome ls
Success
cache
code_cache
files
shared_prefs

Two findings in one session: the token is stored in plain SharedPreferences, and run-as works on the release build (it lists the app's private directories), which confirms android:debuggable="true" in release (manifest review). After the fix, the second command must fail with a "package not debuggable" error.

Step 4: exported components

console
tester@bench:~$ adb -s lab-emu-01 shell am start -n test.lab.labhome/.DeviceAdminActivity
Starting: Intent { cmp=test.lab.labhome/.DeviceAdminActivity }
tester@bench:~$ adb -s lab-emu-01 shell content query --uri content://test.lab.labhome.devices/devices
Row: 0 id=1, name=Living room plug, ble=c2:00:00:b1:e0:07, owner=tester@lab.test

The admin screen opened without login and the device list came back to the shell user, which stands in for "any other app". After the fix (exported="false"), both commands must end in a SecurityException naming the component as not exported.

Step 5: the network

The proxy's CA is installed as a user CA on the emulator, and the emulator's traffic goes through the proxy on the tester's machine.

console
proxy flows (debug build)
  GET  http://api.lab.test/v1/devices           200   <- cleartext: visible and changeable
  POST https://api.lab.test/v1/login            200   <- TLS, but the proxy's CA is trusted
proxy flows (release build 2.3.1, after the fixes)
  CONNECT api.lab.test:443                       client closed the connection
app log (release 2.3.1)
  javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

In 2.3.0 every request is readable; in the fixed release the app trusts only system CAs, so the handshake with the proxy fails before the pins are even checked; the pins are what would stop a proxy whose CA is trusted (with OkHttp's CertificatePinner that failure reads Certificate pinning failure!). Testers keep working with the debug build, whose debug-overrides trust the proxy CA.

Step 6: observing the running app with Frida

Frida injects a JavaScript engine into a process so a tester can watch and trace function calls at runtime. Used on your own debug build, it answers questions the source code leaves open: which cipher does the app actually request after all the library layers? Lab session, tracing one Java method in the sample app:

console
tester@bench:~$ frida-trace -D lab-emu-01 -f test.lab.labhome -j 'javax.crypto.Cipher!getInstance'
Instrumenting...
Started tracing 3 functions. Press Ctrl+C to stop.
  1204 ms  Cipher.getInstance("AES/ECB/PKCS5Padding")
  1211 ms  <= javax.crypto.Cipher@6d1b2a
  1630 ms  Cipher.getInstance("AES/GCM/NoPadding")

The trace confirms the ECB finding at runtime (the local cache) and shows that the network layer uses GCM. This course stops at observation of its own app: scripts that bypass pinning, root detection or other protections of apps are not part of it, and using them against apps you don't own breaks both laws and app-store terms. For your own app, the right fix for a protection you need to test around is a test build with that protection configured off.

How the test is reported

Each confirmed finding gets the evidence (the session lines above), the MASVS control, a severity, the fix and a retest result; dismissed tool findings are listed with the reason. The mini project has a report template.

Pitfalls

  • Testing only the debug build: the release build is what users run, and the two can differ in exactly the settings that matter.
  • Reporting tool output without confirming it.
  • Installing test CAs or instrumentation on personal phones, or testing with real user accounts.

Practice

1. In the triage program, add a decision dismissing hardcoded_secret in res/values/strings.xml because "it is only the maps key". Is that a good decision?

No, not without checks: a maps key is still usable by anyone who extracts it. It can be accepted only if the provider restricts it to the app's package and signing certificate and to the maps API, with quotas; record that evidence in the triage note.

2. Why does run-as working on the release build prove a finding?

run-as works only for debuggable packages. Success on the release APK proves that the release is debuggable, which also lets anyone with USB access read the app's private data.

3. The fixed app refuses the proxy. How does QA keep testing the API traffic?

With the debug build, whose network security configuration trusts user CAs inside debug-overrides (and which may have pinning configured off for the test environment), never by weakening the release build.

Test yourself

What should a test report do with static-analysis findings?

  1. Copy them unchanged
  2. Confirm or dismiss each one, with evidence and reasons
  3. Delete warnings
  4. Only keep high findings

Which command confirmed that a component is reachable by other apps?

  1. adb logcat
  2. adb shell am start -n test.lab.labhome/.DeviceAdminActivity
  3. frida-trace
  4. adb install

What did the frida-trace session show?

  1. The Wi-Fi password
  2. Which cipher modes the app requests at runtime
  3. The server's private key
  4. The user's location

Why does the fixed release refuse the proxy even though its CA is installed?

  1. The proxy is offline
  2. Release trusts only system CAs and checks its pins
  3. TLS is disabled
  4. The emulator blocks it