Skip to main content

mobsfscan

mobsfscan is a static analysis tool that can find insecure code patterns in your Android and iOS source code. Supports Java, Kotlin, Android XML, iOS Info.plist, Swift and Objective C Code. mobsfscan uses MobSF static analysis rules and is powered by semgrep and libsast pattern matcher.

Made with Love in India Tweet

PyPI version License python platform Build

Support mobsfscan

Donate to MobSF

If you liked mobsfscan and find it useful, please consider donating.

e-Learning Courses & Certifications

MobSF Course Automated Mobile Application Security Assessment with MobSF -MAS

Android Security Tools Course Android Security Tools Expert -ATX

Installation

pip install mobsfscan

Requires Python 3.10–3.14

Command Line Options

$ mobsfscan
usage: mobsfscan [-h] [--json] [--sarif] [--sonarqube] [--gitlab-sast] [--html]
                 [--type {android,ios,auto}] [-o OUTPUT] [-c CONFIG]
                 [-mp {default,billiard,thread}] [-w] [--no-fail] [-v]
                 [path ...]

positional arguments:
  path                  Path can be file(s) or directories with source code

options:
  -h, --help            show this help message and exit
  --json                set output format as JSON
  --sarif               set output format as SARIF 2.1.0
  --sonarqube           set output format as SonarQube generic issues (10.3+)
  --gitlab-sast         set output format as GitLab SAST report
  --html                set output format as HTML
  --type {android,ios,auto}
                        optional: force android or ios rules explicitly
  -o OUTPUT, --output OUTPUT
                        output filename to save the result
  -c CONFIG, --config CONFIG
                        location to .mobsf config file
  -mp {default,billiard,thread}, --multiprocessing {default,billiard,thread}
                        optional: specify multiprocessing strategy
  -w, --exit-warning    non zero exit code on warning
  --no-fail             force zero exit code, takes precedence over --exit-warning
  -v, --version         show mobsfscan version

Example Usage

$ mobsfscan tests/assets/src/
- Pattern Match ████████████████████████████████████████████████████████████ 3
- Semantic Grep ██████ 37

mobsfscan: v0.3.0 | Ajin Abraham | opensecurity.in
╒══════════════╤════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╕
│ RULE ID       android_webview_ignore_ssl                                                                                                                             │
├──────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ DESCRIPTION   Insecure WebView Implementation. WebView ignores SSL Certificate errors and accept any SSL Certificate. This application is vulnerable to MITM attacks │
├──────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ TYPE          RegexAnd                                                                                                                                               │
├──────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ PATTERN       ['onReceivedSslError\\(WebView', '\\.proceed\\(\\);']                                                                                                  │
├──────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ SEVERITY      ERROR                                                                                                                                                   │
├──────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ INPUTCASE     exact                                                                                                                                                  │
├──────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ CVSS          7.4                                                                                                                                                    │
├──────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ CWE           CWE-295 Improper Certificate Validation                                                                                                                │
├──────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ OWASP-MOBILE  M3: Insecure Communication                                                                                                                             │
├──────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ MASVS         MSTG-NETWORK-3                                                                                                                                         │
├──────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ REF           https://github.com/MobSF/owasp-mstg/blob/master/Document/0x05g-Testing-Network-Communication.md#webview-server-certificate-verification                │
├──────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ FILES         ╒════════════════╤═════════════════════════════════════════════════════════════════════════════════════════════╕                                       │
│                File            ../test_files/android_src/app/src/main/java/opensecurity/webviewignoressl/MainActivity.java                                        │
│               ├────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────┤                                       │
│                Match Position  1480 - 1491                                                                                                                        │
│               ├────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────┤                                       │
│                Line Number(s)  50                                                                                                                                 │
│               ├────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────┤                                       │
│                Match String    .proceed();                                                                                                                        │
│               ├────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────┤                                       │
│                File            ../test_files/android_src/app/src/main/java/opensecurity/webviewignoressl/MainActivity.java                                        │
│               ├────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────┤                                       │
│                Match Position  1331 - 1357                                                                                                                        │
│               ├────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────┤                                       │
│                Line Number(s)  46                                                                                                                                 │
│               ├────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────┤                                       │
│                Match String    onReceivedSslError(WebView                                                                                                         │
│               ╘════════════════╧═════════════════════════════════════════════════════════════════════════════════════════════╛                                       │
╘══════════════╧════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╛

Python API

>>> from mobsfscan.mobsfscan import MobSFScan
>>> src = 'tests/assets/src/java/java_vuln.java'
>>> scanner = MobSFScan([src], json=True)
>>> scanner.scan()
{
    'results': {
        'android_logging': {
            'files': [{
                'file_path': 'tests/assets/src/java/java_vuln.java',
                'match_position': (13, 73),
                'match_lines': (19, 19),
                'match_string': '            Log.d("htbridge", "getAllRecords(): " + records.toString());'
            }],
            'metadata': {
                'cwe': 'CWE-532 Insertion of Sensitive Information into Log File',
                'owasp-mobile': 'M1: Improper Platform Usage',
                'masvs': 'MSTG-STORAGE-3',
                'reference': 'https://github.com/MobSF/owasp-mstg/blob/master/Document/0x05d-Testing-Data-Storage.md#logs',
                'description': 'The App logs information. Please ensure that sensitive information is never logged.',
                'severity': 'INFO'
            }
        },
        'android_certificate_pinning': {
            'metadata': {
                'cwe': 'CWE-295 Improper Certificate Validation',
                'owasp-mobile': 'M3: Insecure Communication',
                'masvs': 'MSTG-NETWORK-4',
                'reference': 'https://github.com/MobSF/owasp-mstg/blob/master/Document/0x05g-Testing-Network-Communication.md#testing-custom-certificate-stores-and-certificate-pinning-mstg-network-4',
                'description': 'This App does not use TLS/SSL certificate or public key pinning to detect or prevent MITM attacks in secure communication channel.',
                'severity': 'INFO'
            }
        },
        'android_root_detection': {
            'metadata': {
                'cwe': 'CWE-919 - Weaknesses in Mobile Applications',
                'owasp-mobile': 'M8: Code Tampering',
                'masvs': 'MSTG-RESILIENCE-1',
                'reference': 'https://github.com/MobSF/owasp-mstg/blob/master/Document/0x05j-Testing-Resiliency-Against-Reverse-Engineering.md#testing-root-detection-mstg-resilience-1',
                'description': 'This App does not have root detection capabilities. Running a sensitive application on a rooted device questions the device integrity and affects users data.',
                'severity': 'INFO'
            }
        },
        'android_prevent_screenshot': {
            'metadata': {
                'cwe': 'CWE-200 Information Exposure',
                'owasp-mobile': 'M2: Insecure Data Storage',
                'masvs': 'MSTG-STORAGE-9',
                'reference': 'https://github.com/MobSF/owasp-mstg/blob/master/Document/0x05d-Testing-Data-Storage.md#finding-sensitive-information-in-auto-generated-screenshots-mstg-storage-9',
                'description': 'This App does not have capabilities to prevent against Screenshots from Recent Task History/ Now On Tap etc.',
                'severity': 'INFO'
            }
        },
        'android_safetynet_api': {
            'metadata': {
                'cwe': 'CWE-353 Missing Support for Integrity Check',
                'owasp-mobile': 'M8: Code Tampering',
                'masvs': 'MSTG-RESILIENCE-1',
                'reference': 'https://github.com/MobSF/owasp-mstg/blob/master/Document/0x05j-Testing-Resiliency-Against-Reverse-Engineering.md#testing-root-detection-mstg-resilience-1',
                'description': "This App does not uses SafetyNet Attestation API that provides cryptographically-signed attestation, assessing the device's integrity. This check helps to ensure that the servers are interacting with the genuine app running on a genuine Android device. ",
                'severity': 'INFO'
            }
        },
        'android_detect_tapjacking': {
            'metadata': {
                'cwe': 'CWE-200 Information Exposure',
                'owasp-mobile': 'M1: Improper Platform Usage',
                'masvs': 'MSTG-PLATFORM-9',
                'reference': 'https://github.com/MobSF/owasp-mstg/blob/master/Document/0x05h-Testing-Platform-Interaction.md#testing-for-overlay-attacks-mstg-platform-9',
                'description': "This app does not has capabilities to prevent tapjacking attacks. An attacker can hijack the user's taps and tricks him into performing some critical operations that he did not intend to.",
                'severity': 'INFO'
            }
        }
    },
    'errors': []
}

Configure mobsfscan

A .mobsf file in the root of the source code directory allows you to configure mobsfscan. You can also use a custom .mobsf file using --config argument.

---
- ignore-filenames:
  - skip.java

  ignore-paths:
  - __MACOSX
  - skip_dir

  ignore-rules:
  - android_kotlin_logging
  - android_safetynet_api
  - android_prevent_screenshot
  - android_detect_tapjacking
  - android_certificate_pinning
  - android_root_detection
  - android_certificate_transparency

  severity-filter:
  - WARNING
  - ERROR

  severity-overrides:
    ios_log: ERROR
    android_logging: WARNING

severity-overrides changes the reported severity for specific rule IDs (INFO, WARNING, or ERROR). Overrides are applied before severity-filter and affect CLI output, exit codes, and report formats (SARIF, SonarQube, GitLab SAST).

Suppress Findings

You can suppress findings from source files by adding the comment // mobsf-ignore: rule_id1, rule_id2 on the line that triggers the finding. Only that match is suppressed; other matches of the same rule in the file still report.

Example:

String password = "strong password"; // mobsf-ignore: hardcoded_password

CI/CD Integrations

You can enable mobsfscan in your CI/CD or DevSecOps pipelines.

Github Action

Add the following to the file .github/workflows/mobsfscan.yml.

name: mobsfscan

on:
  push:
    branches: [ master, main ]
  pull_request:
    branches: [ master, main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - uses: actions/setup-python@v6
      with:
        python-version: '3.12'
    - name: mobsfscan
      uses: MobSF/mobsfscan@main
      with:
        args: '. --json'

Example: pivaa with mobsfscan github action

Github Code Scanning Integration

Add the following to the file .github/workflows/mobsfscan_sarif.yml.

name: mobsfscan sarif
on:
  push:
    branches: [ master, main ]
  pull_request:
    branches: [ master, main ]

jobs:
  mobsfscan:
    runs-on: ubuntu-latest
    name: mobsfscan code scanning
    permissions:
      security-events: write
      actions: read
      contents: read
    steps:
    - name: Checkout the code
      uses: actions/checkout@v5
    - uses: actions/setup-python@v6
      with:
        python-version: '3.12'
    - name: mobsfscan
      uses: MobSF/mobsfscan@main
      with:
        args: '. --sarif --output results.sarif || true'
    - name: Upload mobsfscan report
      uses: github/codeql-action/upload-sarif@v4
      with:
        sarif_file: results.sarif

mobsfscan github code scanning

Gitlab CI/CD

Add the following to the file .gitlab-ci.yml.

stages:
  - test

mobsfscan:
  image: python:3.12
  stage: test
  before_script:
    - pip3 install --upgrade mobsfscan
  script:
    - mobsfscan . --gitlab-sast -o gl-sast-report.json
  artifacts:
    reports:
      sast: gl-sast-report.json

Example command (local):

mobsfscan . --gitlab-sast -o gl-sast-report.json

This writes a native GitLab SAST report so findings appear in the Vulnerability Report / MR security widget without a SARIF converter.

SonarQube / SonarCloud

--sonarqube writes the generic issue format (SonarQube 10.3+ / SonarCloud), with separate rules and issues arrays:

mobsfscan . --sonarqube -o mobsfscan-sonar.json

Import with sonar.externalIssuesReportPaths=mobsfscan-sonar.json.

Travis CI

Add the following to the file .travis.yml.

language: python
install:
    - pip3 install --upgrade mobsfscan
script:
    - mobsfscan .

Circle CI

Add the following to the file .circleci/config.yaml

version: 2.1
jobs:
  mobsfscan:
    docker:
      - image: cimg/python:3.12
    steps:
      - checkout
      - run:
          name: Install mobsfscan
          command: pip install --upgrade mobsfscan
      - run:
           name: mobsfscan check
           command: mobsfscan .

Bitrise

Add the following to the file bitrise.yml

security_audit:
  steps:
  - activate-ssh-key@4:
      run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
  - git-clone@8.4: {}
  - mobsfscan@1: {}
  - deploy-to-bitrise-io@2: {}

Docker

Prebuilt image from DockerHub

docker pull opensecurity/mobsfscan
docker run -v /path-to-source-dir:/src opensecurity/mobsfscan /src

Build Locally

docker build -t mobsfscan .
docker run -v /path-to-source-dir:/src mobsfscan /src

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mobsfscan-1.0.0.tar.gz (61.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mobsfscan-1.0.0-py3-none-any.whl (91.5 kB view details)

Uploaded Python 3

File details

Details for the file mobsfscan-1.0.0.tar.gz.

File metadata

  • Download URL: mobsfscan-1.0.0.tar.gz
  • Upload date:
  • Size: 61.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.20

File hashes

Hashes for mobsfscan-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ab989a8defbc6f2d3b5633bbb5e1c3c5d90f3f45fd0de2cb60fa611f45101f27
MD5 2b714539f5c406a0c832c029806fbf5c
BLAKE2b-256 67813d484897ed52542b4dcb95a725e56e29dac34bbdc959383039020132729a

See more details on using hashes here.

File details

Details for the file mobsfscan-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mobsfscan-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 91.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.20

File hashes

Hashes for mobsfscan-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a3fd488a275382efdbf94942208a471a039c4b2ff557f4a3577a512f7e8e4b8
MD5 87f002cd190efc4462427c0223aa5d1e
BLAKE2b-256 3de7609af9a249f2d3626fb6df91824899f316e9ba1d489fae26bf22b6cdd18e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page