I want to perform a Dynamic scan using docker. I have a windows computer. I have android studio. I am using npx react-native. However, when i select dynamic scan its giving me errors; on the emulator it says to enable debugging and I always says yes but then the dynamic scan fails. Fix it. How to run it again?
Assistant
User
I AM USING Pixel_3a_API_34_extension_level_7_x86_64 API LEVEL 29. (base) H:\Mobile-Security-Framework-MobSF>adb devices
List of devices attached
emulator-5554 device. How do i run the emulator from cli?
Assistant
User
[INFO] 26/Jan/2025 10:18:00 - Connecting to Android host.docker.internal:5555
daemon not running; starting now at tcp:5037
daemon started successfully
[INFO] 26/Jan/2025 10:18:01 - Waiting for 2 seconds...
[ERROR] 26/Jan/2025 10:18:03 - Error Running ADB Command
Traceback (most recent call last):
File "/home/mobsf/Mobile-Security-Framework-MobSF/mobsf/DynamicAnalyzer/views/android/environment.py", line 168, in adb_command
result = subprocess.check_output(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/subprocess.py", line 466, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/bin/adb', '-s', 'host.docker.internal:5555', 'shell', 'getprop', 'ro.build.version.release']' returned non-zero exit status 1.
I am trying to perform dynamic analysis, i already did static one with mobsf using docker and android emualtor which is already starated but it fails. On the emulator, when i perform dynamic analysis it sais Allow USB debugging?
The computer's RSA key fingerprint is:
[Redacted IPAddress]:
[Redacted IPAddress]
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
To perform a Dynamic Scan using MobSF with Docker on a Windows computer, you need to ensure that both your MobSF Docker setup and your Android Studio emulator are correctly configured for MobSF's dynamic analysis. Below are step-by-step instructions to resolve the issue and set it up properly:
1. Verify Your Emulator Configuration
Ensure that your Android emulator meets the requirements for MobSF's Dynamic Analysis:
Android Version: The emulator should be running Android 5.0 (API Level 21) or higher, but below API Level 30.
Google API Image: Use an emulator image without Google Play (a production image). MobSF cannot dynamically analyze Google Play-enabled images.
Writable System: The emulator must be started with options for a writable system (-writable-system).
Steps to Reconfigure the Emulator:
Open Android Virtual Device (AVD) Manager in Android Studio.
Select an emulator that meets the above requirements.
Start the emulator using the following command (replace AVD_NAME with your emulator's name):
Alternatively, use the provided scripts/start_avd.sh script in the MobSF repository.
Enable Developer Options in the emulator:
Go to Settings > About Phone and tap Build Number 7 times to enable Developer Options.
In Developer Options, ensure USB Debugging is enabled.
2. Connect MobSF Docker with the Emulator
MobSF Docker must communicate with the emulator. On Windows, this can require some additional configuration.
Steps:
Find Emulator's IP Address:
Run the following command to list devices and their IP addresses:
bash
adb devices
Confirm the emulator is listed. The emulator typically listens on [Redacted IPAddress]:5555 (or another port if specified).
Set the Emulator Address for MobSF:
When running MobSF in Docker, set the environment variable MOBSF_ANALYZER_IDENTIFIER. If using Docker Compose, edit the docker-compose.yml file and add the following under environment for the mobsf service:
docker pull opensecurity/mobile-security-framework-mobsf:latest
docker run -it --rm -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest
Access MobSF at http://localhost:8000.
Verify the default MobSF credentials:
Username: [Redacted Person]
Password: mobsf
4. MobSF Dynamic Analysis Setup
Once MobSF is running:
Steps for Dynamic Analysis:
In MobSF, go to the Dynamic Analyzer section.
Select the emulator from the list of connected devices. If the emulator is not listed, ensure:
USB Debugging is enabled in the emulator.
The emulator is reachable via the MOBSF_ANALYZER_IDENTIFIER IP/Port.
MobSFy the Emulator:
MobSF may request permission to "MobSFy" the emulator. This involves installing the required tools, configuring Frida, and setting up the proxy for traffic interception.
Follow the instructions and allow MobSF to install its agents.
If MobSF fails to MobSFy the emulator, restart the emulator and retry.
Upload Your APK:
Build your React Native app into an APK:
bash
npx react-native run-android --variant=release
Upload the generated APK to MobSF for analysis.
Start the dynamic analysis.
5. Troubleshooting Common Issues
Dynamic Scan Fails After Debugging Prompt
Ensure that the emulator is running with root permissions.
Use the command:
bash
adb root
If MobSF fails to communicate, check the logs for errors like Connection Refused or Unable to Connect. This may indicate a networking or proxy misconfiguration.
Frida Server Not Running
[Redacted Person] is required for Dynamic Analysis. If it is not running, MobSF will fail.
Check if the Frida server is running on the emulator:
bash
adb shell ps | grep fd_server
If not, manually start it:
bash
adb shell /system/fd_server
Proxy Issues
Ensure MobSF's proxy is correctly configured and the emulator uses it:
-avd Pixel_3a_API_34_extension_level_7_x86_64
Specifies the name of the AVD (Android Virtual Device) to start.
-writable-system
Makes the system partition writable, which is required for MobSF to install tools like Frida or root CA certificates.
-no-snapshot
Disables loading/saving AVD snapshots to ensure a clean start each time.
-wipe-data
Resets the emulator to its factory default state. Clears any cached data to prevent conflicts.
-port 5554
Sets the emulator's port. This port must match the one shown in adb devices (e.g., emulator-5554).
4. Verify the Emulator is Running
After running the command:
Check that the emulator starts successfully and boots into Android.
Confirm that the emulator is listed in adb devices:
bash
adb devices
Output:
code
List of devices attached
emulator-5554 device
If it's listed, the emulator is ready for use.
5. Enable USB Debugging on the Emulator
Open the emulator's Settings app.
Navigate to About Phone > Build Number.
Tap Build Number 7 times to enable Developer Options.
Go to Developer Options in Settings and enable:
USB Debugging
Root Access (if available).
6. Start MobSF Dynamic Analysis
Now that your emulator is running:
Start MobSF Docker:
bash
docker run -it --rm -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest
Access MobSF at http://localhost:8000.
Go to the Dynamic Analyzer and select the emulator (emulator-5554) from the list of devices.
Follow the prompts to MobSFy the emulator, upload the APK, and start the analysis.
7. Troubleshooting
Error: adb: cannot connect to daemon
Restart the ADB server:
bash
adb kill-server
adb start-server
Emulator Does Not Start
Check if another emulator is already running. Kill all emulator processes:
bash
taskkill /F /IM emulator.exe
Retry the command.
Dynamic Analysis Fails
Ensure the emulator's API level is compatible (API 29 is supported by MobSF).
Verify that the system partition is writable by running:
bash
adb remount
If it fails, ensure you used the -writable-system flag.
Let me know if you encounter any issues!
and i always give permissions but right after that it fails: Dynamic Analysis Failed.
The issue you're encountering indicates that MobSF is unable to connect to the Android emulator over ADB (Android Debug Bridge). The error occurs after you approve the USB debugging prompt on the emulator, which suggests a potential problem with the ADB connection between the MobSF Docker container and the emulator running on your host machine.
Here’s how to resolve the issue step by step:
1. Ensure Correct ADB Configuration and Connectivity
Verify ADB is Working on the Host Machine
Run the following commands on your host machine to ensure that ADB is properly configured and can communicate with the emulator:
bash
adb devices
Expected Output:
code
List of devices attached
emulator-5554 device
If the emulator is not listed, ensure that:
The emulator is running.
USB debugging is enabled in the emulator.
ADB is installed correctly on your host machine.
Manually Connect ADB to the Emulator
If the emulator doesn't appear in the adb devices list, manually connect to it using:
2. Configure Docker to Communicate with the Emulator
When running MobSF in Docker, the container must communicate with the emulator via ADB. On Windows, host.docker.internal is used to access services on the host machine from the Docker container.
Test ADB from Docker
Enter the MobSF Docker container:
bash
docker exec -it <container_id_or_name> bash
Replace <container_id_or_name> with the MobSF container ID or name. You can find it using:
bash
docker ps
Test ADB connectivity from within the container:
bash
adb connect host.docker.internal:5555
adb devices
If you see host.docker.internal:5555 unauthorized, the container is not authorized to connect to the emulator.
Go back to the emulator and accept the USB debugging prompt again.
If the connection is successful, the output should show:
code
List of devices attached
host.docker.internal:5555 device
When the emulator prompts you to allow USB debugging, it means the MobSF Docker container is generating a new ADB keypair, and the emulator doesn't recognize it yet.
Steps to Fix the Issue:
Delete Existing ADB Keys on the Emulator:
Open the emulator shell using:
bash
adb -s localhost:5555 shell
Run the following commands to clear old ADB keys:
bash
rm /data/misc/adb/adb_keys
reboot
Restart the emulator.
Copy Host ADB Keys to MobSF Docker Container:
The ADB keys on your host machine need to be shared with the container to avoid repeated authorization prompts.
Locate the ADB keys on your host machine (typically in the .android folder):
If MobSF reports that the Frida server is not running:
Verify Frida is installed on the emulator:
bash
adb shell ls /system/fd_server
Start the Frida server manually:
bash
adb shell /system/fd_server &
By following these steps, the ADB connection between MobSF Docker and the emulator should work seamlessly, and you should be able to perform dynamic analysis successfully. Let me know if you encounter further issues!