Skip to content

Commit d021da6

Browse files
authored
HOTFIX: MobSF Android Dynamic Analysis Docker Support (#2214)
* MobSF Android Docker Support * Pin pip version * Update mobsf-test.yml
1 parent dc0dc27 commit d021da6

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

.github/workflows/mobsf-test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ jobs:
2525
uses: actions/setup-python@v1
2626
with:
2727
python-version: ${{ matrix.python-version }}
28+
- name: Setup Pip
29+
run: |
30+
python -m pip install pip==22.3.1
2831
- name: Lint
2932
if: startsWith(matrix.os, 'ubuntu')
3033
run: |
31-
python -m pip install --upgrade pip tox
34+
python -m pip install --upgrade tox
3235
tox -e lint
3336
- name: Install Ubuntu Dependencies
3437
if: startsWith(matrix.os, 'ubuntu')

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ WORKDIR /home/mobsf/Mobile-Security-Framework-MobSF
8080
# Copy source code
8181
COPY . .
8282

83-
# Set adb binary path and apktool directory
84-
RUN sed -i "s#ADB_BINARY = ''#ADB_BINARY = '/usr/bin/adb'#" mobsf/MobSF/settings.py && \
85-
mkdir -p /home/mobsf/.local/share/apktool/framework
83+
# Set adb binary path and create apktool framework directory
84+
ENV MOBSF_ADB_BINARY=/usr/bin/adb
85+
RUN mkdir -p /home/mobsf/.local/share/apktool/framework
8686

8787
# Postgres support is set to false by default
8888
ARG POSTGRES=False

mobsf/DynamicAnalyzer/tools/webproxy.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from django.conf import settings
1010

11-
from mobsf.MobSF.utils import is_file_exists, upstream_proxy
11+
from mobsf.MobSF.utils import upstream_proxy
1212

1313
logger = logging.getLogger(__name__)
1414

@@ -61,17 +61,17 @@ def create_ca():
6161
stdout=None,
6262
stderr=None,
6363
close_fds=True)
64-
time.sleep(2)
64+
time.sleep(3)
6565

6666

6767
def get_ca_file():
6868
"""Get CA Dir."""
6969
from mitmproxy import ctx
7070
ca_dir = Path(ctx.mitmproxy.options.CONF_DIR).expanduser()
71-
ca_file = os.path.join(str(ca_dir), 'mitmproxy-ca-cert.pem')
72-
if not is_file_exists(ca_file):
71+
ca_file = ca_dir / 'mitmproxy-ca-cert.pem'
72+
if not ca_file.exists():
7373
create_ca()
74-
return ca_file
74+
return ca_file.as_posix()
7575

7676

7777
def get_traffic(package):

mobsf/DynamicAnalyzer/views/android/dynamic_analyzer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def dynamic_analysis(request, api=False):
7575
try:
7676
if identifier:
7777
env = Environment(identifier)
78+
env.connect()
7879
device_packages = env.get_device_packages()
7980
pkg_file = Path(settings.DWD_DIR) / 'packages.json'
8081
with pkg_file.open('w', encoding='utf-8') as target:

mobsf/DynamicAnalyzer/views/android/environment.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from frida import __version__ as frida_version
1818

1919
from mobsf.DynamicAnalyzer.tools.webproxy import (
20+
create_ca,
2021
get_ca_file,
2122
get_http_tools_url,
2223
start_proxy,
@@ -35,7 +36,7 @@
3536
from mobsf.StaticAnalyzer.models import StaticAnalyzerAndroid
3637

3738
logger = logging.getLogger(__name__)
38-
ANDROID_API_SUPPORTED = 29
39+
ANDROID_API_SUPPORTED = 30
3940

4041

4142
class Environment:
@@ -51,8 +52,9 @@ def __init__(self, identifier=None):
5152

5253
def wait(self, sec):
5354
"""Wait in Seconds."""
54-
logger.info('Waiting for %s seconds...', str(sec))
55-
time.sleep(sec)
55+
if sec > 0:
56+
logger.info('Waiting for %s seconds...', str(sec))
57+
time.sleep(sec)
5658

5759
def check_connect_error(self, output):
5860
"""Check if connect failed."""
@@ -61,12 +63,19 @@ def check_connect_error(self, output):
6163
return False
6264
return True
6365

64-
def run_subprocess_verify_output(self, cmd):
66+
def run_subprocess_verify_output(self, cmd, wait=2):
6567
"""Run subprocess and verify execution."""
6668
out = subprocess.check_output(cmd) # lgtm [py/command-line-injection]
67-
self.wait(2) # adb shell is allowed
69+
self.wait(wait) # adb shell is allowed
6870
return self.check_connect_error(out)
6971

72+
def connect(self):
73+
"""ADB Connect."""
74+
logger.info('Connecting to Android %s', self.identifier)
75+
self.run_subprocess_verify_output([get_adb(),
76+
'connect',
77+
self.identifier], 0)
78+
7079
def connect_n_mount(self):
7180
"""Test ADB Connection."""
7281
self.adb_command(['kill-server'])
@@ -564,6 +573,7 @@ def mobsfy_init(self):
564573

565574
def mobsf_agents_setup(self, agent):
566575
"""Setup MobSF agents."""
576+
create_ca()
567577
# Install MITM RootCA
568578
self.install_mobsf_ca('install')
569579
# Install MobSF Agents

mobsf/MobSF/init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
logger = logging.getLogger(__name__)
1212

13-
VERSION = '3.6.8'
13+
VERSION = '3.6.9'
1414
BANNER = """
1515
__ __ _ ____ _____ _____ __
1616
| \/ | ___ | |__/ ___|| ___|_ _|___ / / /_

mobsf/templates/dynamic_analysis/dynamic_analysis.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ <h3 class="card-title">Android Runtime not found!</h3>
8787
<div class="col-md-9">
8888
<h4>MobSF Dynamic Analyzer Supports</h4>
8989
<h5>
90-
<strong>• Genymotion Android VM</strong> version 4.1 - 10.0 (x86, upto API 29)<br/>
90+
<strong>• Genymotion Android VM</strong> version 4.1 - 11.0 (x86, upto API 30)<br/>
9191
<strong>• Android Emulator AVD</strong> (non production) version 5.0 - 9.0 (arm, arm64, x86, and x86_64 upto API 28)
9292
</h5>
9393
<p>

0 commit comments

Comments
 (0)