Dynamic common Frida/device layer
Overview
This area holds the reusable pieces that Android and iOS dynamic analysis share: safe extraction and response helpers in mobsf/…/shared.py, device-data file viewing in mobsf/…/device.py, common Frida UI/API endpoints in mobsf/…/views.py, Frida runtime download/update logic in mobsf/…/server_update.py, and Frida 17 bridge injection in mobsf/…/bridge_loader.py. Platform-specific code imports these helpers rather than duplicating response formatting, script loading, Frida binary fetching, and bridge compatibility behavior.
mobsf/…/shared.py provides three kinds of primitives. extract_urls_domains_emails() extracts URLs with the shared URL_REGEX, sends the URL set through MalwareDomainCheck().scan(), and extracts lowercased email addresses while filtering obvious URL/image false positives. untar_files() and get_app_files() unpack device-collected tar archives into the analysis directory’s DYNAMIC_DeviceData tree, classify XML, plist, SQLite, and other files, and avoid pipes/links during enumeration. Extraction uses tarfile.data_filter when available and otherwise manually rejects links and resolved paths outside the destination. send_response() and invalid_params() are the common JSON/API response adapters used by Android and iOS dynamic views.
mobsf/…/device.py is the authenticated viewer for files collected from the target device. view_file() accepts either GET parameters or API POST data, validates the MD5 analysis hash, resolves the requested file beneath <UPLD_DIR>/<hash>/DYNAMIC_DeviceData, rejects traversal and pipe/link targets, and renders XML/plist/text/SQLite output through general/view.html or returns the same context for API callers. It handles binary plists by converting them to XML with plistlib.loads()/dumps() before display.
The common Frida views in mobsf/…/views.py expose shared AJAX/API behavior. list_frida_scripts() chooses TOOLS_DIR/frida_scripts/android/others unless the submitted device is not android, in which case it switches to iOS, then returns sorted script stems. get_script_content() reads selected others/*.js files for the selected platform and rejects path traversal before concatenating their contents. frida_logs() validates the analysis hash, streams <UPLD_DIR>/…/mobsf_frida_out.txt as JSON when requested, or renders the Android live Frida log template for browser streaming.
mobsf/…/server_update.py is the shared Frida runtime fetcher. FridaServerUpdater stores binaries under settings.DWD_DIR, uses settings.FRIDA_SERVER + version to inspect GitHub release assets, honors upstream_proxy('https'), and refuses to download when is_internet_available() is false. Android server and Gadget artifacts are downloaded as .xz, decompressed with LZMAFile, checked for an ELF header, atomically moved into place, and old versioned binaries are removed. iOS server artifacts are .deb files, copied without decompression, and named frida_<version>_<platform>-<arch>.deb. Android environment setup calls FridaServerUpdater('android', frida_version).update_frida_server(...) from mobsf/…/environment.py, iOS setup calls FridaServerUpdater('iphoneos', frida_version).update_frida_server(...) from mobsf/…/environment.py, and Android Gadget APK patching calls update_frida_gadget() through mobsf/…/apk_patcher.py.
mobsf/…/bridge_loader.py adapts script construction for Frida 17+. FridaBridgeLoader detects the installed frida.__version__, checks frida_tools/…/java.js and objc.js, and reports bridge support as required only when the runtime is 17.0.0 or newer and both bridge files are available. inject_bridge_support() prepends the selected bridge file and binds globalThis.Java or globalThis.ObjC to the bridge object before appending the caller’s script. Android and iOS Frida cores obtain this loader through mobsf/…/__init__.py; Android passes java in mobsf/…/frida_core.py, while iOS passes objc in mobsf/…/frida_core.py.
The covered tests define dynamic-analysis expectations around these shared seams. mobsf/…/tests_dex_symbols.py builds in-memory dex files and asserts that GadgetPatcher._parse_dex_symbols() preserves short loader symbols, enforces the 128 UTF-16-unit dex string cap, treats missing terminators and offsets past EOF as truncated data, and does not copy large unreferenced string pools. mobsf/…/tests.py verifies mitmproxy flow path validation, the authenticated HTTP traffic viewer’s JSON shape via Android httptools_start, fuzzer proxy URL validation, and guarded replay startup.
Coupling
- If mobsf/…/shared.py changes the shape of
send_response()orinvalid_params(), verify Android and iOS dynamic endpoints that import those helpers still handle both browser and API modes; callers expect raw dicts whenapi=Trueand a JSONHttpResponseotherwise. - If mobsf/…/shared.py changes
get_app_files()classification keys, update file-view consumers that passtypevalues into mobsf/…/device.py;view_file()only acceptsxml,plist,db, andothers. - If the Frida release asset naming in mobsf/…/server_update.py changes, verify Android
frida-server-<version>-android-<arch>, Androidfrida-gadget-<version>-android-<arch>.so, and iOSfrida_<version>_iphoneos-<arch>.debcallers together. Android setup, iOS setup, and Gadget APK patching all share this downloader but pass different platform strings and artifact expectations. - If mobsf/…/bridge_loader.py changes bridge injection semantics, verify both mobsf/…/frida_core.py and mobsf/…/frida_core.py; Android scripts require
Java, iOS scripts requireObjC, and Frida 17+ fails only at runtime if the bridge global is missing. - If script names or platform directories under
TOOLS_DIR/frida_scriptschange, update mobsf/…/views.py and the platform Frida cores together. The common AJAX endpoints read fromothers, while the cores composedefault,rpc, and auxiliary script categories from the same platform roots. - If dex symbol parsing in mobsf/…/apk_patcher.py changes, keep mobsf/…/tests_dex_symbols.py aligned with the production symbol cap and loader symbols; those tests are the guardrail that Gadget patching does not turn malformed or huge dex string pools into slow or memory-heavy analysis.
Risks
- mobsf/…/shared.py and mobsf/…/device.py sit on archive and path boundaries. If tar extraction or file viewing stops rejecting links, traversal, or unsafe resolved paths, a device-provided archive or file parameter can escape
DYNAMIC_DeviceData; recent history includes hardening commits touching archive parsing and path traversal behavior. - mobsf/…/server_update.py trusts release metadata enough to choose and decompress binaries. If the ELF check, temporary-file replacement, or old-binary cleanup changes incorrectly, Android dynamic analysis or Gadget patching can install a partial or wrong Frida binary and fail later during device setup.
- mobsf/…/tests_dex_symbols.py protects a known dex parser fragility: commit history includes a fix to bound Gadget dex string reads. If those caps are relaxed in mobsf/…/apk_patcher.py, a crafted APK can make Gadget symbol parsing slow or memory-intensive before dynamic analysis starts.
- mobsf/…/tests.py covers mitmproxy replay validation after multiple httptools fixes in recent history. If proxy URL validation or flow filename checks are loosened, replay can target unsupported proxies or unsafe flow paths instead of failing before worker/thread startup.