MobSF(Mobile-Security-Framework)是一种开源自动化的移动应用程序(Android / iOS / Windows)安全测试框架,能够执行静态,动态和恶意软件分析。
它可用于Android/iOS和Windows移动应用程序的有效和快速安全分析,并支持二进制文件(APK,IPA和APPX)分析。
MobSF有两种方式,一种是使用docker安装,另外就是使用源码安装。pdf格式。MobSf,打开cmd窗口进入该项目目录。将项目内的requirements.txt打开,最后一行libsast==1.2.2改为libsast==1.3.4setup.batC:\Users\Shuqing
λ cd C:\Users\Shuqing\Desktop\MobSF
C:\Users\Shuqing\Desktop\MobSF
λ setup.bat
bin目录配置到环境变量。
run.bat
localhost:8000。如果需要修改默认端口,可以在run.bat中进行修改SET conf="0.0.0.0:8000"中的端口号。由于众所周知的网络原因,导致无法访问一些域名如raw.githubusercontent.com这个域名,从而运行界面会出现如下报错提示:
Traceback (most recent call last):
File "/Users/atx/Desktop/mobsf/MobSF/utils.py", line 110, in check_update
response = requests.get(github_url, timeout=5,
File "/Users/atx/Desktop/mobsf/venv/lib/python3.8/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/Users/atx/Desktop/mobsf/venv/lib/python3.8/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/atx/Desktop/mobsf/venv/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/Users/atx/Desktop/mobsf/venv/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/Users/atx/Desktop/mobsf/venv/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='raw.githubusercontent.com', port=443): Max retries exceeded with url: /MobSF/Mobile-Security-Framework-MobSF/master/MobSF/settings.py (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x109f12a60>: Failed to establish a new connection: [Errno 61] Connection refused'))
解决方法:
raw.githubusercontent.com查询到真实IP地址如:199.232.4.133。199.232.4.133 raw.githubusercontent.com即可。MobSf,打开终端命令窗口进入该项目目录。输入命令./setup.sh执行安装。Python3.6以上的版本需要单独安装证书,否则后续安装过程会出现如下错误:Error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)
Mac 操作系统下,Python 不再使用系统默认的证书,且本身也不提供证书。在进行 HTTPS 请求时,需要使用 certifi库提供的证书,但 SDK 不支持指定,所以只能使用 Install Certificates.command 命令安装证书才能解决此问题。certifi然后进入到Mac的/Applications/Python{版本号}目录之中,如果是使用homebrew安装的Python则在/Applications不会有python目录,需要安装pkg安装包。pip3 install certifi
/Applications/Python{版本号}目录双击Install Certificates.command安装即可。
sudo ./run.sh后即可运行服务。(ubuntu执行命令sudo bash run.sh)run.sh文件中修改PORT='8000'默认端口号。frida文件时可能超过默认2分钟的等待时间,导致出现如下报错,可以根据报错日志提示,手动下载对应的文件放到对应的目录。Building wheel for frida (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /Users/atx/Desktop/mobsf/venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-bbfbrc_4/frida/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-bbfbrc_4/frida/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/tmp/pip-wheel-qgnu51tn
cwd: /private/tmp/pip-install-bbfbrc_4/frida/
Complete output (15 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.8
creating build/lib.macosx-10.9-x86_64-3.8/frida
copying frida/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/frida
copying frida/core.py -> build/lib.macosx-10.9-x86_64-3.8/frida
running build_ext
looking for prebuilt extension in home directory, i.e. /Users/atx/frida-12.11.12-py3.8-macosx-10.9-x86_64.egg
prebuilt extension not found in home directory, will try downloading it
querying pypi for available prebuilds
downloading prebuilt extension from https://files.pythonhosted.org/packages/07/dd/f0a156369a6ac0e033e5a5fcf327a8da1cb2e2d771d4d45b0cdbd39e737a/frida-12.11.12-py3.8-macosx-10.9-x86_64.egg
unable to download it within 120 seconds; please download it manually to /Users/atx/frida-12.11.12-py3.8-macosx-10.9-x86_64.egg
error: The read operation timed out
----------------------------------------
ERROR: Failed building wheel for frida
frida-12.11.12-py3.8-macosx-10.9-x86_64.egg 放置到/Users/atx/目录之中。Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/logging/config.py", line 563, in configure
handler = self.configure_handler(handlers[name])
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/logging/config.py", line 744, in configure_handler
result = factory(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/logging/__init__.py", line 1143, in __init__
StreamHandler.__init__(self, self._open())
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/logging/__init__.py", line 1172, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: '/Users/atx/Desktop/mobsf/logs/debug.log'
mobile-security-framework-mobsf (本文使用Mac环境下Docker安装)atxdeMac-mini:~ atx$ docker pull opensecurity/mobile-security-framework-mobsf
Using default tag: latest
latest: Pulling from opensecurity/mobile-security-framework-mobsf
3ff22d22a855: Pull complete
e7cb79d19722: Pull complete
323d0d660b6a: Pull complete
b7f616834fd0: Pull complete
6bfde659e3f1: Pull complete
2e41d5beb2f8: Pull complete
55301430fd9f: Pull complete
2b5227325181: Pull complete
844627dd5c16: Pull complete
516af7a49fe2: Pull complete
a9f1027468db: Pull complete
dd9571251a13: Pull complete
11ecc671e91c: Pull complete
99a61bee50cb: Pull complete
d99b0120e9d0: Pull complete
d52913225066: Pull complete
Digest: sha256:887ceb024c56b55d5372be9aee228ee81a61f7f7fad85a67bff3b89b98ef6145
Status: Downloaded newer image for opensecurity/mobile-security-framework-mobsf:latest
docker.io/opensecurity/mobile-security-framework-mobsf:latest
docker run -it -p 8008:8000 opensecurity/mobile-security-framework-mobsf:latest运行容器。atxdeMac-mini:~ atx$ docker run -it -p 8008:8000 opensecurity/mobile-security-framework-mobsf:latest
[INFO] 12/Aug/2020 00:49:19 -
__ __ _ ____ _____ _____ _
| \/ | ___ | |__/ ___|| ___|_ _|___ / / |
| |\/| |/ _ \| '_ \___ \| |_ \ \ / / |_ \ | |
| | | | (_) | |_) |__) | _| \ V / ___) || |
|_| |_|\___/|_.__/____/|_| \_/ |____(_)_|
[INFO] 12/Aug/2020 00:49:19 - Mobile Security Framework v3.1.2 Beta
REST API Key: 9ded7cbd333acb8fa916783270e34cd621d690e1db910f7219f2b9fbe33b57d9
[INFO] 12/Aug/2020 00:49:19 - OS: Linux
[INFO] 12/Aug/2020 00:49:19 - Platform: Linux-4.9.184-linuxkit-x86_64-with-glibc2.29
[INFO] 12/Aug/2020 00:49:19 - Dist: ubuntu 20.04 focal
[INFO] 12/Aug/2020 00:49:19 - MobSF Basic Environment Check
[INFO] 12/Aug/2020 00:49:19 - Checking for Update.
No changes detected
电脑iP:8008即可打开首页,如下图所示:
MD5、SHA-1、SHA-256Main Activity、版本号等Activity、Service、Broadcast Receiver、Content ProviderSigner Certificate)Android API信息Androidmanifest分析(标志位、组件配置等)url、email、string等IPA基本信息ATS)Plist文件分析上传Android 或iOS(需要部署到Mac OS环境下) 测试包自动执行扫描,扫描报告结果如下:

该平台没有提供多语言版本,所以想要中文显示界面需要需要自己汉化,主要是汉化项目中templates中的前端页面文件。
在Recent Scans界面选择一个应用点击Diff or Compare,再选择另外一个应用即可自动对比。

MobSF支持Android应用动态分析(iOS 应用不支持),可以动态调试正在运行的应用。
如果需要动态分析,请不要在Docker或虚拟机中部署MobSF,另外需要下载安装Genymotion模拟器。
在启动MobSF之前,请运行Genymotion模拟器 。一切都会在运行时自动配置。建议使用Android 7.0及更高版本。
Android 5.0-9.0-这些版本使用Frida(一款基于python + java 的hook框架),开箱即用。Android 4.1-4.4- 这些版本使用Xposed Framework。Android的版本4.4 - 9.0,全局代理设置在运行时自动应用。Android版本4.1-4.3,需要设置Dynamic Analyzer页面中显示的Android VM代理。Genymotion是基于X86的,不支持ARM架构。所以有些应用是基于ARM架构编译的就无法安装,出现如下提示
[INFO] 22/Sep/2020 08:51:01 - Getting screen resolution
[INFO] 22/Sep/2020 08:51:02 - Installing APK
adb: failed to install C:/Users/Shuqing/Desktop/MobSF/uploads/b011baaa8aac34fbdf68691e63a96a08/b011baaa8aac34fbdf68691e63a96a08.apk: Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]
[INFO] 22/Sep/2020 08:51:07 - Removing Global Proxy for Android VM
[ERROR] 22/Sep/2020 08:51:09 - This APK cannot be installed. Is this APK compatible the Android VM/Emulator?
[ERROR] 22/Sep/2020 08:51:09 - Internal Server Error: /android_dynamic/
解决方案
下载安装转换工具Genymotion_ARM_Translation 根据自己的模拟器系统版本下载对应的zip包,然后将包直接拖入到模拟器安装,安装完成后重启模拟器即可。
Genymotion模拟器。DYNAMIC ANALYZER192.168.46.101:5555。

MobSFy Android Runtime,然后点击弹窗界面的MobSFy!按钮检测动态分析环境是否正常。界面提示MobSF agents and Frida server installed.说明环境正常。
Android instance无法检测到设备,可以在项目文件中MobSF/setting.py中添加配置ANALYZER_IDENTIFIER = '192.168.56.101(模拟器实际ip):5555' 然后重启MobSF服务。引导页面在历史静态扫描记录上点击【Start Dynamic Analysis】 按钮进入动态分析界面,运行成功之后可以进入动态分析页面如下图所示:

run运行命令界面可以看到日志信息[INFO] 22/Sep/2020 10:43:17 - Creating Dynamic Analysis Environment
[INFO] 22/Sep/2020 10:43:20 - ADB Restarted
[INFO] 22/Sep/2020 10:43:20 - Waiting for 2 seconds...
[INFO] 22/Sep/2020 10:43:22 - Connecting to Android 192.168.46.101:5555
[INFO] 22/Sep/2020 10:43:22 - Waiting for 2 seconds...
[INFO] 22/Sep/2020 10:43:24 - Restarting ADB Daemon as root
[INFO] 22/Sep/2020 10:43:24 - Waiting for 2 seconds...
[INFO] 22/Sep/2020 10:43:26 - Reconnecting to Android Device
[INFO] 22/Sep/2020 10:43:27 - Waiting for 2 seconds...
[INFO] 22/Sep/2020 10:43:30 - Found Genymotion x86 Android VM
[INFO] 22/Sep/2020 10:43:30 - Remounting
[INFO] 22/Sep/2020 10:43:30 - Performing System check
[INFO] 22/Sep/2020 10:43:30 - Android API Level identified as 24
[INFO] 22/Sep/2020 10:43:30 - Android Version identified as 7.0
[INFO] 22/Sep/2020 10:43:30 - Environment MobSFyed Check
[INFO] 22/Sep/2020 10:43:30 - Installing MobSF RootCA
[INFO] 22/Sep/2020 10:43:31 - Starting HTTPs Proxy on 1337
[INFO] 22/Sep/2020 10:43:31 - Killing httptools UI
[INFO] 22/Sep/2020 10:43:31 - Enabling ADB Reverse TCP on 1337
[INFO] 22/Sep/2020 10:43:31 - Setting Global Proxy for Android VM
[INFO] 22/Sep/2020 10:43:32 - Starting Clipboard Monitor
[INFO] 22/Sep/2020 10:43:33 - Getting screen resolution
[INFO] 22/Sep/2020 10:43:33 - Removing existing installation
[INFO] 22/Sep/2020 10:43:34 - Installing APK
[INFO] 22/Sep/2020 10:43:35 - Testing Environment is Ready!
动态分析功能主要如下:
开启/关闭屏幕1.点击Show Screen 可以实时同步设备屏幕,方便测试执行查看。在Dynamic Analyzer菜单可以查看实时动态分析日志,Errors菜单可以查看错误日志。

Frida相关选项,Frida是个轻量级别的hook框架,核心是用C编写的,并将Google的V8引擎注入到目标进程中,在这些进程中,JS可以完全访问内存,Hook函数甚至调用进程内的本机函数来执行。Auxiliary中的选项,甚至右侧Frida Code Editor编辑窗口,可以直接编写脚本进行调试。Fira使用教程请参考官方文档:https://frida.re/docs/home/Install/Remove MobSF RootCA用来安装卸载MobSF CA证书,方便对样本中HTTPS流量进行截获。
遍历获取AndroidManifest.xml文件中的所有Exported Activity 测试流程如下:
activity,adb -s IP:PORT shell am start -n PACKAGE/ACTIVITYactivity运行时的屏幕截图,并保存截屏adb -s IP:PORT shell am force-stop PACKAGEAndroidManifest.xml文件中的所有Activity,而不单单是Exported。Exported Activity一致。截屏并保存到本地。
输出logcat日志信息,如下所示:
09-21 22:15:31.252 573 573 D ConditionProviders.SCP: onReceive android.intent.action.TIME_SET
09-21 22:15:31.252 573 573 D ConditionProviders.SCP: notifyCondition condition://android/schedule?days=6.7&start=23.30&end=10.0&exitAtAlarm=false STATE_FALSE reason=!meetsSchedule
09-21 22:15:31.252 573 573 D ConditionProviders.SCP: notifyCondition condition://android/schedule?days=1.2.3.4.5&start=22.0&end=7.0&exitAtAlarm=false STATE_TRUE reason=meetsSchedule
09-21 22:15:31.252 573 573 D ConditionProviders.SCP: Scheduling evaluate for Mon Sep 21 23:30:00 EDT 2020 (1600745400000), in +1h14m28s748ms, now=Mon Sep 21 22:15:31 EDT 2020 (1600740931252)
生成动态分析报告,如下图所示:
