> For the complete documentation index, see [llms.txt](https://bradsen.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bradsen.gitbook.io/docs/mobile-pentesting/tools/mobsf.md).

# MobSF

MobSF (Mobile Security Framework) is an open-source automated security testing tool for mobile applications.

## Setup

Prerequisite : Install Android Studio & Docker

{% embed url="<https://developer.android.com/studio>" %}

{% embed url="<https://docs.docker.com/desktop/setup/install/windows-install/>" %}

In Android studio, create virtual device

<img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FMygitvYsjakgaYDXmmSx%2Funknown.png?alt=media&amp;token=f256162c-a5bd-42c6-aad0-1f55baf24278" alt="" width="563">

Create a device with the following specs.

<img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FEfbPVRaIxeDEPudX1Z82%2Funknown.png?alt=media&amp;token=8071347f-0d6d-44aa-b70e-738091421ce5" alt="" width="563">

The recommended specs work for me when running MobSF. Otherwise, you can refer to MobSF's recommended system requirements.&#x20;

{% embed url="<https://mobsf.github.io/docs/#/dynamic_analyzer_docker?id=android-studio-emulator>" %}

List all available Android Virtual Devices (AVDs)

```
emulator -list-avds
```

Start the AVD

-writable-system (Makes the /system partition writable)

-no-snapshot-load (Prevents the emulator from loading a previously saved snapshot)

```
emulator -avd Pixel_3_XL -writable-system -no-snapshot-load
```

Wait until AVD fully boots. In a new terminal, check the device loaded.

```
adb devices
```

Expected output.

> emulator-5554 device

On Windows, MobSF in Docker cannot see emulator-5554 directly. We must expose the emulator via ADB over TCP, then tell MobSF to use that TCP endpoint.

Enable ADB over TCP. (Docker on Windows cannot access ADB pipes, so TCP is required)

```
adb tcpip 5555
adb connect 127.0.0.1:5555
adb devices
```

Expected output.

> List of devices attached
>
> 127.0.0.1:5555 device\
> emulator-5554 device

Make sure docker desktop (In Windows) is running. Start MobSF.

```
docker run -it --rm -p 8000:8000 -p 1337:1337 --add-host=host.docker.internal:host-gateway -e MOBSF_ANALYZER_IDENTIFIER=host.docker.internal:5555 opensecurity/mobile-security-framework-mobsf:latest
```

Expected output.

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FFhFCOBiMqYLygn3GHQQP%2Fimage.png?alt=media&amp;token=5cf72f88-6c0c-4caa-97e1-0a990963b3cf" alt=""><figcaption></figcaption></figure>

Go to `http://localhost:8000`. Username/password: `mobsf/mobsf`

<div align="center"><figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FY53xIeAy4J0daYBgkGfX%2Fimage.png?alt=media&amp;token=a0279922-fb4c-4727-9000-2709f7aebecc" alt="" width="185"><figcaption></figcaption></figure></div>

Upload an apk file.

<p align="center"><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FgzxJIqbTiYtP00rlBWcc%2Fimage.png?alt=media&amp;token=879cb4aa-c799-469f-b639-fe97284b935d" alt="" data-size="original"></p>

Start Static Analysis.&#x20;

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FA6ICXJyA9M7O3TACcWRK%2Fimage.png?alt=media&amp;token=1d76025f-4dc9-48ed-b758-e0c9fac3d5b0" alt=""><figcaption></figcaption></figure>

If everything is working correctly, we should be able to start Dynamic Analysis as well.

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2Fx39chHHvfELk4B4MIVdw%2Fimage.png?alt=media&amp;token=47cb4626-0d13-4f82-86e8-b58650f1c332" alt=""><figcaption></figcaption></figure>

Expected output

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FXnB69NBQBzSVwfxAotEQ%2Fimage.png?alt=media&amp;token=ded625b7-8db0-4a42-b8e0-5f95c51eea3b" alt=""><figcaption></figcaption></figure>

## Static Analysis

### AndroidManifest.xml

<img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FpNLhVc79Za2tJAsgHwJK%2Funknown.png?alt=media&amp;token=ee1c97d9-7cc5-4d52-bedc-f05fae371791" alt="" width="539">

Look for misconfigurations, exposed components, insecure permissions, and security-relevant settings.

#### Exported Components

1. **Activities**

> \<activity\
> &#x20;   android:name=".AdminActivity"\
> &#x20;   android:**exported="true"**/>

If exported, any app can potentially launch it. Run the following shell command in MobSF to test it.

```
shell am start -n <package>/.AdminActivity
```

2. **Content Providers**

> \<provider\
> &#x20;   android:name=".DataProvider"\
> &#x20;   androi&#x64;**:exported="true"**/>

High-value target because providers often expose databases, file and user information. Run the following shell command in MobSF to test it.

```
shell content query --uri content://authority/path
```

#### Application level settings

1. **android:debuggable="true"**

> \<application\
> &#x20;  android:allowBackup="true">

The risk is that it allows allows debugging of the application on production devices, which may expose sensitive information. It can enable runtime manipulation using tools like MobSF, Frida, or Android Studio.

2. **android:allowBackup="true"**

> \<application\
> &#x20;  android:allowBackup="true">

The risk is that application data can potentially be backed up using ADB, which may expose databases, shared preferences, and files. Run the following shell command in MobSF to test it.

```
backup -apk -shared <package>
```

## Dynamic Analysis&#x20;

### Shell access

It provides an interactive shell on the Android device or emulator that MobSF is analyzing.

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2F0tUDnpelfsB8hDZL7mxd%2Fimage.png?alt=media&amp;token=08c6797f-8c41-4748-91c1-9e5beb21ad84" alt=""><figcaption></figcaption></figure>

See which are the commands available.

```
help
```

<img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FQSPuSiFmekljhcdpKkbc%2Funknown.png?alt=media&amp;token=0ba45875-26e2-4ad0-9296-ed820816f9d2" alt="" height="65" width="624">

Displays the username of the account currently running the shell session.

```
shell whoami 
```

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FDxqRNgHtriD2N15Qn1U9%2Fimage.png?alt=media&amp;token=b174616a-faa0-43e6-8fcb-11c6358f2c27" alt=""><figcaption></figcaption></figure>

Check out the list of installed packages. Take note of the target application.

```
shell pm list packages
```

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FMl5vRWKoWOkqXaf8mwdr%2Fimage.png?alt=media&amp;token=60f70bec-b15f-44e1-be03-3748259022bd" alt=""><figcaption></figcaption></figure>

Test for exported activities.

```
shell am start -n owasp.sat.agoat/.AccessControl1ViewActivity
```

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2Fk7HNBJ0iXd3amzCxM3Rt%2Fimage.png?alt=media&amp;token=b5f0ec56-a82c-4d04-92d8-155805e4cef2" alt=""><figcaption></figcaption></figure>

Emulator screen. Any app can get access to unprotected android components.&#x20;

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2F3bNYuBRbCypsDMGXv6Wb%2Fimage.png?alt=media&amp;token=53bde929-31f3-48de-8910-24d858377e36" alt=""><figcaption></figcaption></figure>

<br>

<br>
