Introducing a new way to review your PRs.

Read the announcement

mobsf / mobile-security-framework-mobsf

Mobile Security Framework (MobSF) is an automated, all-in-one mobile application (Android/iOS/Windows) pen-testing, malware analysis and security assessment framework capable of performing static and dynamic analysis.

View on GitHub

13 documents · Updated Nov 16, 2026

docs / windows-static-analysis

Windows Static Analysis

Overview

Windows static analysis is entered through mobsf/…/windows.py. staticanalyzer_windows(request, checksum, api=False) is the web and REST entry point: mobsf/…/urls.py routes /static_analyzer_windows/<checksum>/ to it, and mobsf/…/api_static_analysis.py calls the same function for uploaded files whose scan type is in settings.WINDOWS_EXTS (appx, msix, appxbundle, msixbundle). The view validates that the checksum is an MD5, verifies the upload exists in RecentScansDB, rejects unsupported file types, and then either reuses an existing StaticAnalyzerWindows row or runs a fresh scan when there is no row or rescan=1/re_scan=1 is set. Web requests render static_analysis/windows_binary_analysis.html; API requests return the same context dictionary.

analyze_package() in mobsf/…/windows.py builds the persisted analysis. It hashes the uploaded package with hash_gen(), extracts the archive with the shared unzip() helper into settings.UPLD_DIR/<md5>, and keeps a shared uncompressed-byte budget so an outer bundle and its selected inner package are capped together. For appxbundle and msixbundle, _select_bundle_package() parses AppxMetadata/AppxBundleManifest.xml, keeps only application packages, prefers architectures in x64, arm64, x86, neutral, arm order, rejects traversal/links with _safe_child(), then extracts the selected .appx/.msix into bundle_package after _reset_dir() removes anything previously planted there. The file list stored in analysis['files'] comes from the extracted archive entries and excludes directory entries.

Manifest and package-signature analysis live in mobsf/…/manifest.py. parse_manifest(root / 'AppxManifest.xml') parses XML with defusedxml, rejects pipes/links and files over MAX_MANIFEST_BYTES, and returns a fixed manifest shape even when parsing fails. It extracts identity, publisher, version, architecture, display metadata, minimum OS version, build metadata, application executable paths, capabilities, package dependencies, and security findings. Findings include full-trust applications, cleartext ApplicationContentUriRules, remote content with WinRT access, known sensitive extension categories such as protocol handlers, full-trust processes, COM servers, services, firewall rules, loader search path overrides, and debug runtime dependencies. analyze_signature(app_dir, manifest['publisher']) inspects the outer package's AppxSignature.p7x, strips the optional PKCX prefix, parses PKCS#7 signer information with asn1crypto/cryptography, and reports signer, issuer, expiry, and digest algorithm. Its findings cover unsigned packages, unparsable signatures, signer/publisher DN mismatches, self-signed certificates, weak hash algorithms, and expired certificates. analyze_package() merges manifest findings, signature findings, and _package_file_findings() output for packaged .pdb files into manifest_analysis.

PE hardening and string extraction are driven by _analyze_binaries() in mobsf/…/windows.py. _iter_pe_files() walks the extracted app root, only considers known PE suffixes (.exe, .dll, .sys, .ocx, .cpl, .scr, .pyd, .node), skips pipes/links, validates safe relative paths, ignores files larger than MAX_PE_SIZE, and checks the MZ magic before analysis. Main executables declared by the manifest are sorted first, and the scan is capped at MAX_PE_FILES. Each candidate is analyzed by PEChecksec in mobsf/…/pe.py, which parses the binary through lief.PE.parse under settings.BINARY_ANALYSIS_TIMEOUT. The result records binary name, architecture, PE32/PE32+ format, EXE/DLL type, runtime (Native, .NET (mixed mode), or .NET (IL only)), and checks for ASLR, high-entropy VA, DEP/NX, Control Flow Guard, SafeSEH, /GS stack cookies, RWX sections, Authenticode digest validity, and Microsoft SDL banned imports. IL-only .NET assemblies return Not Applicable for native-only checks instead of false failures.

mobsf/…/strings.py provides bounded printable string extraction for the PE pass. extract_strings() reads at most MAX_READ_BYTES from each file in 1 MiB chunks, matches ASCII and UTF-16LE printable runs of at least six characters, keeps overlap so chunk boundaries do not split strings, truncates individual strings to MAX_STRING_LEN, and returns unique sorted values up to the per-file cap passed by _analyze_binaries(). analyze_package() also enforces MAX_STRINGS_TOTAL across files and persists only the first MAX_STORED_STRINGS. Extracted strings are passed to the shared url_n_email_extract() helper for per-file URL/email tables, to get_secrets() for hardcoded-secret findings, to MalwareDomainCheck().scan() for domain reputation, and to Trackers.Trackers(...).get_trackers_domains_or_deps() for tracker attribution.

Persistence and report context conversion are centralized in mobsf/…/db_interaction.py. get_context_from_analysis() converts the in-memory result into the template/API schema, using _display_name() to fall back from unresolved ms-resource: display names to the package name and stripping findings out of the package_signature object before display. save_or_update() writes the context into StaticAnalyzerWindows fields and updates RecentScansDB.APP_NAME, PACKAGE_NAME, and VERSION_NAME; failures are logged into scan status rather than raised. get_context_from_db_entry() reverses the stored TextField values with python_list()/python_dict() and appends get_scan_logs() so cached reports and freshly generated reports expose the same keys. The model fields backing this schema are in mobsf/…/models.py on StaticAnalyzerWindows, including manifest metadata, FILES, STRINGS, PE_ANALYSIS, MANIFEST_ANALYSIS, CAPABILITIES, PACKAGE_SIGNATURE, URLS, EMAILS, DOMAINS, SECRETS, and TRACKERS.

The web report at mobsf/…/windows_binary_analysis.html consumes that context directly. It presents package/app/build metadata, scan actions, package signature details, manifest findings, capability rows, PE hardening rows, malware lookup links, optional VirusTotal results, domain malware checks, extracted URLs and emails, trackers, possible hardcoded secrets, stored strings, and the extracted file list. The PE table expects the PEChecksec.checksec() key names and renders each check via static_analysis/windows_pe_cell.html; older rows with binary_analysis/binary_warnings still display a legacy table with a prompt to rescan.

Coupling

Risks

  • mobsf/…/windows.py limits PE analysis to MAX_PE_FILES after sorting manifest executables first. If a malicious package contains many decoy PE files and important binaries are not listed in AppxManifest.xml, those later binaries are skipped, so PE hardening findings, strings, URLs, secrets, malware domains, and trackers can be incomplete.
  • mobsf/…/strings.py reads only the first MAX_READ_BYTES from each binary and mobsf/…/windows.py stops collecting new strings after MAX_STRINGS_TOTAL and stores only MAX_STORED_STRINGS. If indicators are embedded beyond those caps, the report will omit the corresponding URL, email, secret, domain, and tracker evidence.
  • mobsf/…/manifest.py treats an unreadable, overlarge, linked, or invalid AppxManifest.xml as empty_manifest(). That keeps the scan alive, but it also means package identity, capabilities, executable prioritization, and manifest findings are absent rather than surfaced as a dedicated manifest-parse failure.
  • mobsf/…/manifest.py verifies the package signature metadata and compares signer DN to the manifest publisher, but it does not validate certificate trust chains or timestamp semantics. A report can mark a package as signed while the signer is untrusted outside the local package context.