Skip to content

Dynamic Verification

Sam MG Harish edited this page Oct 30, 2026 · 4 revisions

Dynamic verification (phase 2)

Phase 2 does two things on the device, in order:

  1. Finding verification. Each static finding is proven or not proven at runtime, and annotated with a verdict.
  2. An on-device session. Environment checks (root, Frida, HTTPS interception, model vision) followed by a UI exploration loop that exercises the app.

When it runs

Phase 2 starts when all of these hold:

  • The framework is one that has an analyzer (Java/Kotlin, Flutter, React Native, Cordova, or Xamarin/.NET MAUI).
  • Dynamic verification is enabled (dynamic_verification, on by default; set in settings.json or through PUT /api/settings).
  • At least one device is visible to adb. Emulators are preferred over physical devices.
  • Static analysis succeeded.
  • The package name was determined.

The two parts then apply independently:

Part Extra requirement Skipped when
Finding verification Phase 1's decompiled/extracted tree is still on disk and there is at least one finding Reason recorded in dynamic_session.reason or dynamic_session.skipped_reason
On-device session The app installs Reason recorded in dynamic_session.environment.reason

A scan with no static findings still runs the on-device session, since the environment checks and the UI loop do not depend on having something to verify.

Two scans can run at once, and each installs its app, starts and stops frida-server and drives the screen of the device it picked. Phase 2 therefore holds a lock per device serial (analysis_service.hold_device): the static phases still run in parallel, and a scan whose device is busy shows "Waiting for : another scan is using it" until the other finishes. Before the lock, two scans on one emulator both picked it, and one scan's teardown stopped the other's frida-server mid-check. A cancelled scan stops waiting.

Failures inside phase 2 are contained: each part records why it stopped, the other part's results survive, and phase 1's findings stand on their own. A broken device environment degrades the scan rather than failing it.

Sequence

sequenceDiagram
    participant V as verifier
    participant P as AI provider
    participant D as device (adb/Frida)
    V->>P: triage: which findings need runtime proof?
    P-->>V: list of finding ids
    V->>D: install APK unless this build is already there, check root, set up frida-server, launch app
    loop until every finding has a verdict or the budget runs out
        V->>P: context + transcript + verdicts so far + pending ids
        P-->>V: one action JSON
        V->>D: read_source / adb / frida
        D-->>V: observation (bounded, see Tools)
    end
    V->>V: merge verdicts into findings, stop frida-server
    V->>P: proof review: does each verified or refuted verdict's evidence hold?
    P-->>V: holds / set aside, per verdict
    V->>D: environment checks, then drive the UI
    D-->>V: env results, actions, runtime findings
Loading

Triage

Running the device loop on a finding that the source already proves wastes tokens and device time. Before the loop, _classify_needs_verification() asks the model which findings need runtime proof.

The prompt states the split explicitly:

  • Needs runtime proof: SQL injection, exported component and IPC or deep-link abuse, WebView JavaScript bridges, native and JNI memory-safety bugs, TLS and certificate-validation bypass, insecure storage or logging that only happens at runtime.
  • Already conclusive statically: hardcoded secrets and API keys, android:debuggable, android:allowBackup, cleartext-traffic and network-security-config settings, other manifest flags.

Configuration findings never reach triage (configuration_finding): every BUILD class, and the no-network-security-config, backup-enabled and no-FLAG_SECURE notes. The prompt already calls them settled by the manifest, but a model still chose "targetSdkVersion 27 allows implicit component export" in two Ghera runs and spent device steps reading targetSdk out of dumpsys while the planted clipboard leak went unreached.

Findings not selected lose their internal id and get no verification badge, which is correct: absence of a badge means "not applicable", not "failed to prove". If triage fails to parse or the provider errors, everything is verified, which is the safe default.

The prompt names the answer's key ({"need_runtime_verification": [...]}), and an object whose only list sits under another name is read as the answer, because the schema is not enforced on every provider. Until both changes, triage failed on every scan: its 300-token cap truncated twice (thinking counts against it; see AI providers), and the third answer named its list runtime_verification_needed. Every finding then went to the device, and on a Ghera scan the exported activity that most needed the steps was "not reached within the dynamic-verification step budget".

Before the loop, a finding that says it applies to an older Android than the device runs ("possible on Android 10 and lower" on an Android 11 device) is set aside as not verified, with that reason (version_limited): the platform closes it there, so it cannot be shown, and a run once called task hijacking verified on Android 11 because dumpsys showed the app's minSdkVersion. The agent's opening context states the device's Android version and lists the remaining findings most severe first.

Step budget

max_steps = clamp(2 * findings_needing_proof + 6, 20, 60)

A flat budget could not reach a verdict for every finding once there were more than a handful; a 19-finding run concluded only 4. Batched verdicts (one action closing several findings that share the same evidence) usually keep the real turn count well under the ceiling.

Device setup

  1. Install only when needed (ADBManager.installed_copy_matches). The device is asked first: pm path <package> (not installed, or a split install, means install), dumpsys package <package> for versionCode/versionName compared with the local APK's manifest, then sha256sum of the installed base.apk compared with the local file's SHA-256. The same version with the same hash is reused as it is - reinstalling the same build cost a minute per scan and reset nothing the run needs - and the session records Already installed: version … and SHA-256 match. Any difference, including a rebuilt APK that kept its version, or a check that cannot be completed (no sha256sum, an unusable path), installs. The package name is validated before it reaches the device shell, and the installed path the device reports is validated against a strict pattern before it is hashed.
  2. Before installing, the APK's native ABIs are checked against the device's ro.product.cpu.abilist (ADBManager.abi_mismatch). An APK whose native code targets none of them (typically one pulled from an x86_64 emulator, tested on an arm64 one) is not sent, and install.message says which ABIs each side has, instead of adb's bare INSTALL_FAILED_NO_MATCHING_ABIS. An APK with no native code, or a device that will not report its list, goes on to the install.
  3. When an install is needed: adb install -r -g -t <apk>. -r reinstalls over an existing copy so app data survives; -g grants runtime permissions up front, since the loop cannot dismiss permission dialogs. An install refused by the package verifier (INSTALL_FAILED_VERIFICATION_FAILURE/_TIMEOUT), or one that hangs until adb times out, is retried once with package verification switched off, and the device's previous settings are restored afterwards whether the retry succeeds or not. A hang counts because the "verify apps over USB" consent dialog waits for a tap and adb prints nothing meanwhile: the first install of each Ghera app hung for the full three minutes, and the same APK installed in under a second once the device had decided. An install refused because the device holds the same package signed with another key (INSTALL_FAILED_UPDATE_INCOMPATIBLE) uninstalls that copy, with its data, and installs once more: Android cannot update across signing keys, every Ghera app is edu.ksu.cs.benign, and one built with a different key lost its whole device phase. Any other failed install ends phase 2 and marks every selected finding not verified, with the install error as the reason.
  4. Root check, via su -c id looking for uid=0.
  5. FridaManager.setup_and_verify(). Without root this returns immediately and verification continues adb-only. frida-ps is looked up on PATH and then beside the running interpreter (utils.system.find_tool), since a pip-installed tool lands in the virtual environment's bin directory, which is on PATH only while the venv is activated. Running the venv's python or entry point by its full path used to report frida-tools not available on PATH with frida-ps installed right there, and every hook-based check fell back to adb; the demo's published scans all ran that way. mitmdump is found the same way.
  6. adb shell monkey -p <package> -c android.intent.category.LAUNCHER 1 to launch the app.

Tools

Action Arguments Behaviour
read_source path or paths, optional start_line Same paged reader as phase 1, over the same artifact tree phase 1 produced (JADX/Blutter output, the decompiled bundle, the extracted assets/www tree, or the recovered assemblies). Up to 6 files per batch
adb command Runs a validated, package-scoped shell command
frida script, optional trigger Injects a JavaScript snippet into the target app and collects send() output; trigger is an adb command, held to the same allowlist, run once the hooks are installed
note text Records an observation with no side effect
verdict finding_id or finding_ids, status, evidence or reason Concludes one or several findings

adb and frida output is truncated to 4,000 characters. read_source pages exactly like phase 1's reader, 12,000 characters a page, and every observation is capped at 15,000 characters when it is added to the transcript.

The adb allowlist

VerifyTools does not pass strings to a shell. It parses the requested command with shlex, strips any leading adb, -s <serial> and shell tokens, then dispatches on the verb through an allowlist. Every verb is constrained to the app under test.

Verb Accepted form
logcat Fixed: last 200 lines filtered to the target app's pid
run-as run-as <package> <ls|cat|find> <path...>, .. rejected, arguments shell-quoted
dumpsys Exactly dumpsys package <package>
pm Exactly pm path <package> or pm dump <package>
am am start or am broadcast, and the arguments must name the package via -n <package>/<Component> or -p <package>
input input tap <int> <int>, input text <text> (quoted), input keyevent <int>
screencap Fixed path on the device; returns a note, not image bytes
getprop Exactly one property name, shell-quoted
pidof Exactly pidof <package>
content content query|read|insert|update|delete|call --uri content://<authority>/..., where the authority must be one the app declares, read once from dumpsys package <package>; arguments shell-quoted. It runs as the shell user, which reaches a provider much as another installed app does
sleep sleep <1-10>, a pause on the host between chained steps; nothing is sent to the device
uiautomator Exactly uiautomator dump: the app's own on-screen elements, one line each with class, id, text and the centre to tap, read from the dump with a regular expression (the dump is untrusted, so no XML parser resolves it). Elements of other packages, the system UI among them, are left out, and at most 60 are listed. Without it, an agent typed a payload and tapped guessed coordinates until its budget ran out. A uiautomator2 server left by an earlier scan's UI exploration holds the device's one UI-automation connection and makes the dump hang, so it is stopped first, and the UI exploration now stops its own server when it finishes (UIAutomator.close)

am and content are the attacker's commands, so they run as the attacker would. On many emulators and userdebug images adb's shell is root, and root passes every check another app fails: it sends protected broadcasts, starts unexported components and skips signature permissions. When the shell is root, VerifyTools._as_other_app runs them as the shell user, uid 2000, through whichever su form the device accepts (su 2000 cmd, or Magisk's su 2000 -c cmd, found once and kept); where neither works, the output says the command ran as root. Before this, a Ghera fixed app's receiver, which acts only on DEVICE_STORAGE_LOW, was "triggered" with that protected broadcast from a root shell, confirming a false positive instead of refuting it. As uid 2000 the same command gets "Permission Denial: not allowed to send broadcast".

Commands joined with && or ; run in order, each held to the allowlist on its own, and the chain stops at the first refusal; at most six per step. Pipes, redirection and background jobs are refused whole. Driving a screen needs am start, a pause, input text and input tap in sequence: before chaining existed, an agent re-sent am start ... '&&' input text ... for most of a DIVA run, its && reaching the device as a quoted argument, and a High SQL injection was never reached. content was missing too, though the prompt already pointed the agent at content query for exported providers.

Anything else is refused with a message listing what is allowed. The package name itself is validated against ^[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)+$ when VerifyTools is constructed.

Frida scripts

FridaManager.run_script() connects through the same adb forward tunnel used for verification, attaches to the running package (spawning and resuming it if it is not running), loads the script, runs the action's trigger if it has one, collects send() messages for a bounded window (20 seconds), then unloads, detaches, removes the remote device and drops the forward. Output is capped at 8000 characters. message.type == "error" frames are surfaced as ERROR: ... lines rather than being dropped.

A hook sees only the calls made while its script is loaded, so the code it watches has to run inside that window. Without trigger the only way to make the app act was a separate adb step, which ran after the script had been unloaded: a Ghera scan installed hooks on Log.d and TextView.setText, opened the activity in the next step, saw nothing, and spent its whole 20-step budget repeating the pair without a verdict. The trigger's output comes back first (trigger ->), then the script's; a script that emitted nothing says whether a trigger ran, and suggests one when none did.

Scripts typically use Java.perform and Interceptor.attach. The Frida binding is pinned to 16.x because Frida 17 removed the built-in Java global from raw create_script scripts, which these hooks depend on.

Loop control

  • Deduplication. Read-only calls (read_source, and adb commands starting with dumpsys, run-as, getprop, pm, logcat, cat, ls) are cached by argument. A repeat returns the cached output prefixed with a reminder to record a verdict or move on. Side-effecting and nondeterministic calls (am start, input, frida) are never cached.
  • Repeated-error abort. Three identical tool errors in a row end the loop. The abort reason becomes the not_verified reason for every finding still pending, and it says what failed rather than blaming the finding.
  • Unknown actions get a corrective message. inspect_native in particular gets a specific reply pointing at the Frida equivalent, because the model tends to reach for the phase-1 tool.

Verdicts

Each selected finding ends with a dynamic_verification block:

{"status": "verified", "evidence": "dumpsys shows the provider exported with no permission; content query returned rows"}
{"status": "refuted", "evidence": "'am broadcast -n app/.LowMemoryReceiver' as uid 2000 ran the receiver; 'run-as app ls files' still lists myfile"}
{"status": "not_verified", "reason": "Activity is exported but requires a signature permission this device cannot hold."}

refuted means the agent exercised the finding the way its attacker would and the device showed the claimed harm does not happen: the platform refused the action, or the effect the finding claims was absent. Like verified it needs evidence naming a device action, or it is recorded as not verified. Grading then sets the finding to Informational with that evidence as the reason (check_device_refutation, see Validation and chains); it stays in the report. Before refuted existed a device verdict was a badge only, and a Ghera fixed app's receiver, which is reachable but deletes nothing for any Intent another app can send, kept its Medium marked "verified". The agent is told to refute only on an attempt that should have worked were the finding true; one it simply could not get to run is not_verified.

A finding with no verdict at the end gets not_verified with either the abort reason or "Not reached within the dynamic-verification step budget."

A verdict can close several findings at once, and the agent is asked to label its evidence per finding ("F1: … F2: …"). Each finding gets only its own part (_evidence_for): its labelled segment; or, when the agent wrote a numbered list instead and named the findings inside it ("1. dumpsys confirms … (proving F35). 2. am start … (proving F6 and F27)"), the items that name it plus any item that names none. A single sentence, or text naming only one finding, is shared by the whole batch, since one sentence often covers several findings while naming one. A finding recorded as verified with a batch whose evidence has no part for it becomes not_verified: "Recorded as verified together with other findings, but the evidence given did not cover this one." Attaching the whole text to every member once showed a missing-FLAG_SECURE note as verified by evidence about an exported content provider. A verified verdict whose own evidence names no device action - no adb or shell command, Frida hook, logcat, intercepted request or UI action - is recorded as not_verified: "Only the decompiled source was read again for this finding; nothing was shown on the device." The verifier's read_source tool reads the same tree phase 1 read, and verdicts resting on it alone were published as verified (shown_on_device). A session that stops early because one tool failed the same way three times quotes that tool's error as the reason for the findings it had not reached (abort_reason), instead of guessing at a cause. The F identifiers are positional within one session and are removed from what a reader sees (_clean_ids), including list forms such as "(F3, F5)" and "(proving F6 and F27)", and leftover list numbers at either end of a segment.

The prompt is explicit that not_verified is a legitimate outcome for a real code-level issue that cannot be reached at runtime, and that evidence must never be invented. It also says how a proof must be made: the way the finding's attacker would make it. For another app, that is an am or content command carrying that app's input (extras, a data URI, a provider query), observed through logcat, the screen, the app's files or a Frida hook that only reads; a hook that rewrites the app's own return values shows what root can do, not another app, and once "proved" an exported activity's PIN bypass by forcing getBooleanExtra to return false. Package metadata (dumpsys package, pm, getprop) settles configuration findings but is never proof that something happens at runtime. A screen other apps cannot open is reached as its user reaches it, by launching the app and tapping through with uiautomator dump. Calling the app's own methods from Frida shows the code exists, not that an attacker reaches it, so hooks only watch while the real entry point is driven; a memory-safety finding is proven by its crash, not by a hook firing (a DIVA run once "verified" a JNI overflow by calling the method itself with 100 characters). Proofs are read-only where they can be: a provider injection is shown by a crafted content query, not by a content delete that empties the table (which another run did).

Proof review

After the loop, every verified and refuted verdict is read again with its evidence by a separate request (review_proofs, on the triage provider, eight verdicts per batch). It holds the evidence to the proof rules: it shows the claim itself rather than a neighbouring fact; the app was driven the way the finding's attacker would drive it, with Frida hooks only watching; package metadata settles only configuration claims; a refutation was a real attempt and the claimed effect was absent. A verdict that fails becomes not_verified, with "The device evidence was set aside on review: ..." as its reason and the evidence kept beside it under rejected_evidence. A batch whose answer cannot be read keeps its verdicts. Each entry is matched to its verdict whether the label comes back as P3, [P3] or 3: one DIVA answer wrote [P0] throughout and the whole batch went unreviewed until that was accepted. Reviewed again, that run set aside 3 of 17 device verdicts, among them an exported-activity bypass whose evidence launched a different activity. The agent is given the same rules and still broke them: one DIVA run "proved" a credit-card log leak with a Frida script that called Log.e itself, and a provider SQL injection with content delete --where "1=1", which is an ordinary selection.

Session summary

run_dynamic_verification returns a session dict stored as dynamic_session in the result:

Key Meaning
device, package What was targeted
install {ok, message}: Already installed: … when the device's copy was reused, otherwise the outcome of adb install
frida {ok, message} from Frida setup
total_count Findings selected by triage
android_version The device's Android release, read before the loop; findings limited to an older Android are set aside against it
verified_count How many reached verified
refuted_count How many reached refuted
proof_review {reviewed, rejected}: verdicts the proof review read, and how many it set aside
attempted Whether anything ran on the device
skipped_reason, reason Present when verification did not run
environment The on-device session's own summary (see below)

Frida server lifecycle

Step Detail
Version Derived from the installed frida Python binding, falling back to 16.7.19. Server and binding versions must match
Architecture From getprop ro.product.cpu.abi, mapped to a Frida arch. arm64-v8a, armeabi-v7a, x86_64 and x86 are supported
Download GitHub release asset, XZ-decompressed, cached under the platform cache directory (.../lu77U-MobileSec/frida/)
Push To /data/local/tmp/frida-server, made executable
Tunnel adb forward tcp:<28000 + crc32(serial) % 1000> tcp:27042, so concurrent sessions against different devices do not collide
Verification frida-ps against the tunnel; the process count is reported back
Teardown stop_server runs in a finally block, including on cancellation. A stop that itself fails is logged and appended to the readiness result's message, rather than left silent - a stray frida-server keeps running as root on the device otherwise

HTTPS interception check

It needs mitmproxy, an optional extra (pip install "lu77U-MobileSec[mitmproxy]", or any mitmdump on PATH); without it the check stops at once with that install hint and the rest of the session continues. MitmproxyManager.run_https_check() performs a full round trip rather than a presence check:

  1. On macOS, try to add an Application Firewall exception for the running interpreter. macOS silently drops inbound connections from non-loopback sources, such as an emulator's virtual network, to binaries with no explicit rule.
  2. Install mitmproxy's CA into the device's system trust store, under the Android hash name. This needs root and a writable /system.
  3. Start mitmdump on port 8080 with a flow-capture addon.
  4. Point the device at the proxy: adb reverse tcp:8080 tcp:8080, then settings put global http_proxy 127.0.0.1:8080. Routing through the device's own loopback replaced an earlier approach using the 10.0.2.2 emulator alias, which only works on emulators.
  5. Open https://www.google.com/ on the device and wait up to 6 seconds for a decrypted flow.
  6. Clear the device proxy configuration in a finally block.

Success means the app's traffic can be read in the clear through a CA the device merely trusts, which is what makes "no certificate pinning" a defensible finding. Failure messages distinguish the firewall case, the CA case, and the general routing case, because those need different fixes.

On-device session

DynamicAnalyzer (dynamic_analysis/dynamic_analyzer.py) runs after finding verification, against the same device and the app the verifier already installed. It performs, in order:

  1. Root check.
  2. Frida setup and verification.
  3. The HTTPS interception check described below.
  4. A visual check: open a known page on the device, screenshot it, and ask a vision-capable model whether the expected page rendered. This confirms the provider can actually see the device screen before anything relies on screenshots. Providers without vision support skip it.
  5. Launch the app and drive its UI. UIAutomator connects with uiautomator2, dumps the UI hierarchy, detects login screens by keyword and by password="true" fields, and asks the model for the next tap or text input.

Two parameters differ from a standalone session, because a scan has already spent budget on static analysis:

Parameter Value in a scan Why
ui_steps 8 (standalone default is 20) Each iteration costs a UI dump plus a model call
skip_app_info true The APK was already pulled and detected during phase 1, so re-pulling it from the device adds nothing

The session reports progress 0 to 100 for itself; AnalysisService remaps that into the 88 to 91 band of the scan-level bar.

Runtime findings

runtime_findings is appended to the same list the static findings live in, so anything the session establishes about the app appears in result.json, the reports and the severity counts alongside everything else. It is empty today. A working HTTPS interception check is an environment result, not a finding: the check proves the proxy and CA by opening a probe URL in the device's browser, and the proxy is stopped before the app is exercised, so nothing it captured came from the app. It used to be reported as "Interceptable HTTPS Traffic (No Certificate Pinning)" on every app it ran against, including Ghera apps that open no network connection at all. Missing pinning is still reported statically (NETWORK-03).

Session block

{"attempted": true,
 "device": {"serial": "emulator-5554", "model": "sdk_gphone64_arm64",
            "android_version": "13", "is_emulator": true},
 "env_checks": {"root": true,
                "frida": {"ok": true, "message": "..."},
                "https_intercept": {"ok": true, "message": "..."},
                "ai_visual_check": {"ok": true, "message": "..."}},
 "actions": [{"iteration": 1, "action": "tap", "x": 540, "y": 1200,
              "reason": "open the notes screen", "success": true}],
 "runtime_findings": []}

When the session cannot run, the block is {"attempted": false, "reason": "..."} instead.

Clone this wiki locally