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.
https://opensecurity.in
GNU General Public License v3.0
17.16k stars 3.21k forks source link

failed to connect to 'host.docker.internal:5555': Connection refused for Dynamic Analysis with AVD #2427

Closed boulwabd closed 5 hours ago

boulwabd commented 6 hours ago

ENVIRONMENT

OS and Version: Ubuntu 20.04.5 LTS 
Python Version: Python 3.8.10
MobSF Version:  Mobile Security Framework v4.0.7
Docker Version: Docker version 27.3.1, build ce12230

EXPLANATION OF THE ISSUE

Connection to host.docker.internal:5555 refused when trying to start dynamic analysis with "--add-host=host.docker.internal:host-gateway" specified at startup.

STEPS TO REPRODUCE THE ISSUE

1. Start emulator "emulator -avd android28 -writable-system -no-snapshot -no-window -id emulator-5554"
2. Running docker with "sudo docker run -it --rm -p 8000:8000 -p 1337:1337 -e MOBSF_ANALYZER_IDENTIFIER=emulator-5554 --add-host=host.docker.internal:host-gateway opensecurity/mobile-security-framework-mobsf:latest"
3. Navigating to dynamic analysis page causes "failed to connect to 'host.docker.internal:5555': Connection refused"

I have verified the emulator is running and can manually run "/usr/bin/adb -s host.docker.internal:5555 shell getprop ro.build.version.release" after adding host.docker.internal to my /etc/hosts file but this step fails inside the container. 

This is my containers hosts file:
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.1      host.docker.internal
172.17.0.2      83be5dfcd65e

LOG FILE

INFO] 29/Sep/2024 18:23:06 - OS Environment: Linux (ubuntu 22.04 Jammy Jellyfish) Linux-5.4.0-196-generic-x86_64-with-glibc2.35
[INFO] 29/Sep/2024 18:23:06 - MobSF Basic Environment Check
[INFO] 29/Sep/2024 18:23:06 - Checking for Update.
[INFO] 29/Sep/2024 18:23:06 - No updates available.
[INFO] 29/Sep/2024 18:23:34 - Connecting to Android host.docker.internal:5555
* daemon not running; starting now at tcp:5037
* daemon started successfully
[INFO] 29/Sep/2024 18:23:37 - Waiting for 2 seconds...
[ERROR] 29/Sep/2024 18:23:39 - failed to connect to 'host.docker.internal:5555': Connection refused
[ERROR] 29/Sep/2024 18:23:39 - Error Running ADB Command
Traceback (most recent call last):
  File "/home/mobsf/Mobile-Security-Framework-MobSF/mobsf/DynamicAnalyzer/views/android/environment.py", line 167, in adb_command
    result = subprocess.check_output(
  File "/usr/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.10/subprocess.py", line 526, 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.
github-actions[bot] commented 6 hours ago

👋 @boulwabd Issues is only for reporting a bug/feature request. For limited support, questions, and discussions, please join MobSF Slack channel Please include all the requested and relevant information when opening a bug report. Improper reports will be closed without any response.

boulwabd commented 5 hours ago

Was searching through existing issues before posting but did not realize this situation was covered in the FAQ. I believe the problem is Docker CE cannot talk to localhost. Running the docker in the host network was the workaround for my case.