Malware Analysis Integrations
Overview
mobsf/MalwareAnalyzer/ is a set of malware-intelligence helpers that are called from static and dynamic analyzers rather than a standalone Django app with persistent models. mobsf/…/models.py and mobsf/…/admin.py are empty, so this area does not write its own database records; results are returned to the calling analyzer context and scan status is appended through mobsf.MobSF.utils.append_scan_status.
Bundled intelligence lives under mobsf/signatures/. On startup, mobsf/…/init.py copies that directory into settings.SIGNATURE_DIR under the MobSF home directory when use_home is enabled. Runtime code reads and updates the MobSF-home copies, not the repository files directly. mobsf/…/settings.py defines the feed URLs and feature switches used here: Maltrail, URLhaus domain/IP feeds, Exodus tracker API, VirusTotal API v3 base URL, MOBSF_DOMAIN_MALWARE_SCAN, MOBSF_APKID_ENABLED, MOBSF_VT_ENABLED, and MOBSF_VT_UPLOAD.
Android static APK analysis calls these helpers from mobsf/…/apk.py: manifest permissions are compared with the hard-coded abused-permission lists in mobsf/…/permissions.py; APKiD runs on the uploaded APK through mobsf/…/apkid.py; Exodus tracker detection runs through mobsf/…/Trackers.py; extracted URLs are sent to mobsf/…/MalwareDomainCheck.py. Android code analysis also invokes mobsf/…/behaviour_analysis.py, which applies mobsf/…/behaviour_rules.yaml through the shared SAST engine. Dynamic analysis reuses the same domain checker from mobsf/…/shared.py and resolves runtime tracker evidence from observed domains/dependencies in mobsf/…/report.py.
APKiD is optional and controlled by APKID_ENABLED in mobsf/…/apkid.py. When enabled, it imports the external apkid package, builds scanner options with a 30-second APKiD rule timeout, bounds entry scan size by settings.DATA_UPLOAD_MAX_MEMORY_SIZE, and wraps scanner.scan_file in run_with_timeout using settings.BINARY_ANALYSIS_TIMEOUT. The output is normalized into a dict keyed by the DEX filename inside the APK, with !-separated archive prefixes stripped. Import failures, timeouts, and incompatible APKiD output formatter APIs are converted into scan-status messages and an empty result.
Behavior analysis in mobsf/…/behaviour_analysis.py constructs the rule path from settings.BASE_DIR / MalwareAnalyzer / views / android / rules / behaviour_rules.yaml and calls sast.run_rules(data, rules). The YAML file is a large set of RegexAnd rules with labels such as SMS, location, Wi-Fi, accessibility service, reflection, command execution, network, camera, recording, files, packer, and native library loading. The resulting findings are merged into the Android code-analysis result under behaviour by mobsf/…/code_analysis.py.
Permission malware signals are local and deterministic. mobsf/…/permissions.py keeps two lists: TOP_MALWARE_PERMISSIONS for common malware permissions such as SMS, call-log, contacts, audio, overlay, boot receiver, install-packages, and storage access; and OTHER_PERMISSIONS for other frequently abused Android/Google permissions. check_malware_permission() iterates the manifest permissions supplied by the caller and returns matching lists plus the total size of each reference list, so UI code can show both hits and coverage.
Tracker detection in mobsf/…/Trackers.py uses the Exodus database at settings.SIGNATURE_DIR/exodus_trackers. Trackers.__init__() calls _update_tracker_db(), which checks is_db_update_due(), skips updates without internet, downloads settings.EXODUS_URL/api/trackers with update_local_db(), validates the expected JSON shape (trackers → 1 → code_signature), and only then overwrites the local signature file. load_trackers_signatures() reads the JSON into namedtuples and compiles code_signature and network_signature regexes. Static detection obtains embedded classes from each *.dex in the unpacked app directory by running baksmali (settings.BACKSMALI_BINARY or the bundled baksmali-3.0.8-dev-fat.jar) and matching class names against code signatures. Runtime detection matches observed domains against network signatures and can also expand iOS/framework dependency names into reverse-DNS candidates before applying generalized Exodus code signatures.
Domain and IP malware checks are handled by mobsf/…/MalwareDomainCheck.py. scan(checksum, urls) exits immediately if DOMAIN_MALWARE_SCAN is disabled, lowercases incoming URLs, extracts sanitized hostnames with get_domains(), checks for feed updates, then applies Maltrail, geolocation, and URLhaus in that order. maltrail_check() loads maltrail-malware-domains.txt into a lowercased set and marks exact domain hits as bad: yes with desc: Malicious Domain tagged by Maltrail. gelocation() resolves each domain with resolve_public_ip() so private/internal DNS answers are not fed into subsequent analysis, enriches public IPs with IP2LOCATION-LITE-DB5.IPV6.BIN when available, and tags OFAC-like locations from a hard-coded country/region/city list. urlhaus_check() loads both urlhaus-malware-domains.txt and urlhaus-malware-ips.txt, then flags exact domain hits, raw IP URL hits, or resolved-IP hits; if a domain was already tagged by Maltrail, the description becomes Malicious Domain tagged by Maltrail and URLhaus. mobsf/…/tests.py covers those attribution paths and verifies that combined feed descriptions propagate into common appsec findings.
VirusTotal integration in mobsf/…/VirusTotal.py wraps API v3 and is only invoked by callers when settings.VT_ENABLED is true. VirusTotal.get_result(file_path) first requests an existing file report from settings.VIRUS_TOTAL_BASE_URL/{checksum}. API v3 file objects are normalized into the v2-shaped dictionary expected by existing templates (positives, total, scans, permalink, hashes, verbose_msg). If no report exists and VT_UPLOAD is false, it returns a status-only payload saying upload is disabled. If uploads are allowed, files up to 32 MB are posted to /files; files up to 650 MB first request /files/upload_url; larger files are skipped. Upload and analysis URLs are accepted only when their host is virustotal.com or a subdomain, and polling stops after 12 attempts at 15-second intervals before returning a queued message.
The bundled signature datasets are seed data and fallback data: mobsf/…/maltrail-malware-domains.txt is a very large Maltrail domain list, mobsf/…/urlhaus-malware-domains.txt and mobsf/…/urlhaus-malware-ips.txt are URLhaus-derived DNS/IP blocklists, mobsf/signatures/exodus_trackers is the Exodus tracker JSON, and mobsf/signatures/IP2LOCATION-LITE-DB5.IPV6.BIN is the binary GeoIP database used for enrichment. Feed update cadence is throttled by mobsf/MobSF/utils.py:is_db_update_due(), which touches a .lastcheck marker beside each local feed and skips re-checks until settings.DB_UPDATE_INTERVAL has elapsed.
Coupling
- If mobsf/…/behaviour_rules.yaml changes, verify mobsf/…/code_analysis.py still passes the right source
file_datashape tosast.run_rules(); the rules are raw regex strings and failures surface as missing behavior findings rather than schema errors. - If
mobsf/signatures/exodus_trackersor the Exodus API format changes, update mobsf/…/Trackers.py before replacing the feed;load_trackers_signatures()creates namedtuples directly from JSON keys, while_update_tracker_db()only validates one sentinel path before writing the downloaded file. - If tracker detection output fields change in mobsf/…/Trackers.py, check all static and dynamic callers that render
trackers: static Android APK/JAR/AAR/native analysis, iOS IPA/dylib/static-library analysis, Windows analysis, and dynamic Android/iOS reports callget_trackers()orget_trackers_domains_or_deps()and expectdetected_trackers,total_trackers, and a list of{name, categories, url}. - If mobsf/…/MalwareDomainCheck.py changes result keys or descriptions, update appsec aggregation and templates that consume
domains; mobsf/…/tests.py explicitly checks thatdesc,bad,ip, andgeolocationfeed intomobsf.StaticAnalyzer.views.common.appsec.common_fields(). - If mobsf/…/settings.py changes
SIGNATURE_DIRor the feed URL settings, verify mobsf/…/init.py still seeds the MobSF-home signatures directory and thatMalwareDomainCheckandTrackerscontinue to read/write the same local files. - If VirusTotal response handling in mobsf/…/VirusTotal.py changes, preserve the v2-shaped normalized payload unless all template/API consumers are updated;
_normalize_report()exists because existing callers expectpositives,total,scans,permalink, andverbose_msg, not raw API v3 attributes. - If
resolve_public_ip()behavior changes, re-run the malware-domain tests in mobsf/…/tests.py;MalwareDomainCheck.gelocation()relies on it to avoid internal/private DNS results before URLhaus resolved-IP matching.
Risks
- mobsf/…/MalwareDomainCheck.py has fragile ordering between Maltrail, geolocation, and URLhaus. If
urlhaus_check()stops reusing the IP saved bygelocation()or runs before geolocation, URLhaus resolved-IP hits can be missed or misattributed. Recent history shows a fix-of-fix sequence here:449c2f1added a fallback IP resolution in URLhaus checks and66ee1afthen moved resolution back intogelocation()for reuse. - mobsf/…/MalwareDomainCheck.py performs network-derived domain resolution on untrusted app URLs. If callers bypass
resolve_public_ip()or pass raw resolver output into feed checks, private/internal addresses could influence analysis; this area has prior security-hardening history for DNS rebinding/SSRF (42ee5dc). - mobsf/…/VirusTotal.py follows upload and analysis URLs returned by an external service. If
_is_safe_vt_url()is weakened,upload_file()or_poll_analysis()could send authenticated requests through MobSF's proxy settings to non-VirusTotal hosts. - mobsf/…/Trackers.py compiles third-party Exodus regexes from
mobsf/signatures/exodus_trackersand updated feed content. Bad or unexpectedly expensive regexes can break tracker detection or slow scans;_compile_signatures()only catchesTypeError, not regex compilation failures from malformed patterns. - mobsf/…/apkid.py depends on private/changed APKiD formatter APIs (
_build_json_outputversusbuild_json_output). If APKiD changes output structure again, scans will silently return{}after only status logging, so APKiD upgrades should be tested with real APK samples.