diff --git a/.dockerignore b/.dockerignore index 22118466..60652d0f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,16 +6,21 @@ .sonarcloud.properties .pyup.yml tox.ini -db.sqlite3 +mobsf/db.sqlite3 Dockerfile +dist +*.egg-info docker-compose.yml +*.md +venv +setup.py +MANIFEST.in setup.bat run.bat -*.md setup.sh run.sh -downloads -uploads -logs -venv -secret +mobsf/downloads +mobsf/uploads +mobsf/debug.log +mobsf/secret +mobsf/StaticAnalyzer/test_files/ \ No newline at end of file diff --git a/.gitattributes b/.gitattributes index 396822ee..43e141d5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -DynamicAnalyzer/tools/onDevice/frida/ filter=lfs diff=lfs merge=lfs -text +mobsf/DynamicAnalyzer/tools/onDevice/frida/ filter=lfs diff=lfs merge=lfs -text diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a664f961..45b4e35a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -39,7 +39,7 @@ Guidelines for bug reports: 3. **Isolate the problem** — create a [reduced test case](http://css-tricks.com/reduced-test-cases/) and a live example. -4. **Add Log file** — Please add the log file `logs/debug.log` while opening bugs. +4. **Add Log file** — Please add the log file `mobsf/debug.log` while opening bugs. 5. **Timely Response** — Once you open a bug, you should also provide additional information if requested. Failure to do so in 10 days will result in closure of the bug without further communication. @@ -60,7 +60,7 @@ Example: > 1. This is the first step > 2. This is the second step > 3. Further steps, etc. -> 4. Log information from `logs/debug.log` +> 4. Log information from `mobsf/debug.log` > > `` - a link to the reduced test case > diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index ba88862e..d9408c6c 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -39,7 +39,7 @@ What happens, under which versions, under what conditions, when, and what were y ## LOG FILE ``` -Paste the contents of logs/debug.log here or attach the log file. +Paste the contents of mobsf/debug.log here or attach the log file. ```
-

MobSF cannot find android instance identifier. Make sure that an android instance is running and refresh this page.

If this error persists, Please set ANALYZER_IDENTIFIER in MobSF/settings.py +

MobSF cannot find android instance identifier. Make sure that an android instance is running and refresh this page.

If this error persists, Please set ANALYZER_IDENTIFIER in MobSF/settings.py or ~/.MobSF/config.py

diff --git a/templates/general/about.html b/mobsf/templates/general/about.html similarity index 100% rename from templates/general/about.html rename to mobsf/templates/general/about.html diff --git a/templates/general/apidocs.html b/mobsf/templates/general/apidocs.html similarity index 100% rename from templates/general/apidocs.html rename to mobsf/templates/general/apidocs.html diff --git a/templates/general/error.html b/mobsf/templates/general/error.html similarity index 100% rename from templates/general/error.html rename to mobsf/templates/general/error.html diff --git a/templates/general/home.html b/mobsf/templates/general/home.html similarity index 100% rename from templates/general/home.html rename to mobsf/templates/general/home.html diff --git a/templates/general/not_found.html b/mobsf/templates/general/not_found.html similarity index 100% rename from templates/general/not_found.html rename to mobsf/templates/general/not_found.html diff --git a/templates/general/recent.html b/mobsf/templates/general/recent.html similarity index 99% rename from templates/general/recent.html rename to mobsf/templates/general/recent.html index c980321f..1c7d8ed4 100644 --- a/templates/general/recent.html +++ b/mobsf/templates/general/recent.html @@ -194,7 +194,7 @@ function delete_scan(item){ Swal.fire({ title: 'Are you sure?', - text: "This will permanently remove the scan results from MobSF", + text: "This will permanently remove the scan results from mobsf.MobSF", type: 'warning', showCancelButton: true, confirmButtonText: 'Yes', diff --git a/templates/general/search.html b/mobsf/templates/general/search.html similarity index 100% rename from templates/general/search.html rename to mobsf/templates/general/search.html diff --git a/templates/general/view.html b/mobsf/templates/general/view.html similarity index 100% rename from templates/general/view.html rename to mobsf/templates/general/view.html diff --git a/templates/general/zip.html b/mobsf/templates/general/zip.html similarity index 100% rename from templates/general/zip.html rename to mobsf/templates/general/zip.html diff --git a/templates/pdf/android_report.html b/mobsf/templates/pdf/android_report.html similarity index 100% rename from templates/pdf/android_report.html rename to mobsf/templates/pdf/android_report.html diff --git a/templates/pdf/ios_report.html b/mobsf/templates/pdf/ios_report.html similarity index 100% rename from templates/pdf/ios_report.html rename to mobsf/templates/pdf/ios_report.html diff --git a/templates/pdf/windows_report.html b/mobsf/templates/pdf/windows_report.html similarity index 100% rename from templates/pdf/windows_report.html rename to mobsf/templates/pdf/windows_report.html diff --git a/templates/static_analysis/android_binary_analysis.html b/mobsf/templates/static_analysis/android_binary_analysis.html similarity index 100% rename from templates/static_analysis/android_binary_analysis.html rename to mobsf/templates/static_analysis/android_binary_analysis.html diff --git a/templates/static_analysis/android_source_analysis.html b/mobsf/templates/static_analysis/android_source_analysis.html similarity index 100% rename from templates/static_analysis/android_source_analysis.html rename to mobsf/templates/static_analysis/android_source_analysis.html diff --git a/templates/static_analysis/compare.html b/mobsf/templates/static_analysis/compare.html similarity index 100% rename from templates/static_analysis/compare.html rename to mobsf/templates/static_analysis/compare.html diff --git a/templates/static_analysis/ios_binary_analysis.html b/mobsf/templates/static_analysis/ios_binary_analysis.html similarity index 100% rename from templates/static_analysis/ios_binary_analysis.html rename to mobsf/templates/static_analysis/ios_binary_analysis.html diff --git a/templates/static_analysis/ios_source_analysis.html b/mobsf/templates/static_analysis/ios_source_analysis.html similarity index 100% rename from templates/static_analysis/ios_source_analysis.html rename to mobsf/templates/static_analysis/ios_source_analysis.html diff --git a/templates/static_analysis/source_tree.html b/mobsf/templates/static_analysis/source_tree.html similarity index 100% rename from templates/static_analysis/source_tree.html rename to mobsf/templates/static_analysis/source_tree.html diff --git a/templates/static_analysis/treeview_file.html b/mobsf/templates/static_analysis/treeview_file.html similarity index 100% rename from templates/static_analysis/treeview_file.html rename to mobsf/templates/static_analysis/treeview_file.html diff --git a/templates/static_analysis/treeview_folder.html b/mobsf/templates/static_analysis/treeview_folder.html similarity index 100% rename from templates/static_analysis/treeview_folder.html rename to mobsf/templates/static_analysis/treeview_folder.html diff --git a/templates/static_analysis/windows_binary_analysis.html b/mobsf/templates/static_analysis/windows_binary_analysis.html similarity index 100% rename from templates/static_analysis/windows_binary_analysis.html rename to mobsf/templates/static_analysis/windows_binary_analysis.html diff --git a/requirements.txt b/requirements.txt index 0ce466e9..935afa16 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,17 +2,17 @@ Django==3.1.5 pdfkit==0.6.1 androguard==3.3.5 lxml==4.6.2 -rsa==4.6 +rsa==4.7 biplist==1.0.3 requests==2.25.1 bs4==0.0.1 -colorlog==4.6.2 +colorlog==4.7.2 macholib==1.14 google-play-scraper==0.1.2 whitenoise==5.2.0 -waitress==1.4.4 -gunicorn==20.0.4 -frida==14.2.2 +waitress==1.4.4;platform_system=='Windows' +gunicorn==20.0.4;platform_system!='Windows' +frida==14.2.6 psutil==5.8.0 shelljob==0.6.2 asn1crypto==1.4.0 @@ -21,8 +21,11 @@ distro==1.5.0 IP2Location==8.5.1 lief==0.10.1 http-tools==2.0.0 -libsast==1.3.6 +libsast==1.3.7 # Do not update the following apkid==2.1.1 +click==7.1.2 # pyup: ignore cryptography<3.3,>=3.2 # pyup: ignore pyOpenSSL<19.2,>=19.1.0 # pyup: ignore +# For semgrep +ruamel.yaml==0.16.10 # pyup: ignore \ No newline at end of file diff --git a/run.bat b/run.bat index 2728dd9c..c1b85f95 100644 --- a/run.bat +++ b/run.bat @@ -6,4 +6,4 @@ goto :run :usage SET conf="0.0.0.0:8000" :run -.\venv\Scripts\activate && waitress-serve --listen=%conf% --threads=10 --channel-timeout=3600 MobSF.wsgi:application +.\venv\Scripts\activate && waitress-serve --listen=%conf% --threads=10 --channel-timeout=3600 mobsf.MobSF.wsgi:application diff --git a/run.sh b/run.sh index 9aa48450..0ed84dab 100755 --- a/run.sh +++ b/run.sh @@ -45,4 +45,4 @@ if [ ! -z "$var" ]; then IP='0.0.0.0' PORT='8000' fi -. venv/bin/activate && gunicorn -b ${IP}:${PORT} MobSF.wsgi:application --workers=1 --threads=10 --timeout=3600 +. venv/bin/activate && gunicorn -b ${IP}:${PORT} mobsf.MobSF.wsgi:application --workers=1 --threads=10 --timeout=3600 diff --git a/scripts/clean.bat b/scripts/clean.bat index cc94d8d4..1d4ea3cb 100644 --- a/scripts/clean.bat +++ b/scripts/clean.bat @@ -5,27 +5,27 @@ SET mypath=%~dp0 echo %mypath:~0,-1% IF "%~1"=="y" ( echo Deleting all Uploads -rmdir "uploads" /q /s >nul 2>&1 +rmdir "mobsf\uploads" /q /s >nul 2>&1 echo Deleting all Downloads -rmdir "downloads" /q /s >nul 2>&1 +rmdir "mobsf\downloads" /q /s >nul 2>&1 echo Deleting Static Analyzer Migrations -rmdir "StaticAnalyzer\migrations" /q /s >nul 2>&1 +rmdir "mobsf\StaticAnalyzer\migrations" /q /s >nul 2>&1 echo Deleting Dynamic Analyzer Migrations -rmdir "DynamicAnalyzer\migrations" /q /s >nul 2>&1 +rmdir "mobsf\DynamicAnalyzer\migrations" /q /s >nul 2>&1 echo Deleting MobSF Migrations -rmdir "MobSF\migrations" /q /s >nul 2>&1 +rmdir "mobsf\MobSF\migrations" /q /s >nul 2>&1 echo Deleting temp and log files -rmdir "logs" /q /s >nul 2>&1 +del /f "mobsf\debug.log" >nul 2>&1 del /f "classes*" >nul 2>&1 echo Deleting DB -del /f "db.sqlite3" >nul 2>&1 +del /f "mobsf\db.sqlite3" >nul 2>&1 echo Deleting Secret File -del /f "secret" >nul 2>&1 +del /f "mobsf\secret" >nul 2>&1 echo Deleting Previous Setup files rmdir "%UserProfile%\MobSF" /q /s >nul 2>&1 del /f "setup_done.txt" >nul 2>&1 echo Done ) ELSE ( -echo Please run script from MobSF directory +echo Please run script from mobsf.MobSF directory echo 'scripts/clean.bat y ) \ No newline at end of file diff --git a/scripts/clean.sh b/scripts/clean.sh index d566dcd7..21630a69 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -5,7 +5,7 @@ echo 'Running this script will delete the Scan database, all files uploaded and script_path=$(dirname $0) if [ "$script_path" != "scripts" ] && [ "$script_path" != "./scripts" ]; then - echo 'Please run script from MobSF directory ' + echo 'Please run script from mobsf.MobSF directory ' echo './scripts/clean.sh ' exit 1 fi @@ -20,24 +20,24 @@ echo if [[ $VAL =~ ^[Yy]$ ]] then echo 'Deleting all Uploads' - rm -rf ./uploads/* + rm -rf ./mobsf/uploads/* echo 'Deleting all Downloads' - rm -rf ./downloads/* + rm -rf ./mobsf/downloads/* echo 'Deleting Static Analyzer Migrations' - rm -rf ./StaticAnalyzer/migrations/* + rm -rf ./mobsf/StaticAnalyzer/migrations/* echo 'Deleting Dynamic Analyzer Migrations' - rm -rf ./DynamicAnalyzer/migrations/* + rm -rf ./mobsf/DynamicAnalyzer/migrations/* echo 'Deleting MobSF Migrations' - rm -rf ./MobSF/migrations/* + rm -rf ./mobsf/MobSF/migrations/* echo 'Deleting python byte code files' find ./ -name "*.pyc" -exec rm -rf {} \; find ./ | grep -E "(__pycache__|\.pyo$)" | xargs rm -rf echo 'Deleting temp and log files' - rm -rf ./logs/* + rm -rf ./mobsf/debug.log rm -rf ./classes* echo 'Deleting DB' - rm -rf ./db.sqlite3 + rm -rf ./mobsf/db.sqlite3 echo 'Deleting Secret File' - rm -rf ./secret + rm -rf ./mobsf/secret echo 'Done' fi diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index 5752db96..49b98610 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -5,4 +5,4 @@ python3 manage.py makemigrations && \ python3 manage.py makemigrations StaticAnalyzer && \ python3 manage.py migrate -gunicorn -b 0.0.0.0:8000 "MobSF.wsgi:application" --workers=1 --threads=10 --timeout=1800 +gunicorn -b 0.0.0.0:8000 "mobsf.MobSF.wsgi:application" --workers=1 --threads=10 --timeout=1800 diff --git a/scripts/postgres_support.sh b/scripts/postgres_support.sh index f46e570c..16765fb3 100644 --- a/scripts/postgres_support.sh +++ b/scripts/postgres_support.sh @@ -5,7 +5,7 @@ echo "Postgres support : ${POSTGRES}" if [ "$POSTGRES" == True ]; then pip3 install psycopg2-binary #Enable postgres support - sed -i '/# Sqlite3 suport/,/# End Sqlite3 support/d' ../MobSF/settings.py && \ - sed -i '/# Postgres DB - Install psycopg2/,/"""/d' ../MobSF/settings.py && \ - sed -i '/# End Postgres support/,/"""/d' ../MobSF/settings.py + sed -i '/# Sqlite3 suport/,/# End Sqlite3 support/d' ../mobsf/MobSF/settings.py && \ + sed -i '/# Postgres DB - Install psycopg2/,/"""/d' ../mobsf/MobSF/settings.py && \ + sed -i '/# End Postgres support/,/"""/d' ../mobsf/MobSF/settings.py fi diff --git a/scripts/update_android_permissions.py b/scripts/update_android_permissions.py index ce256274..06f3222d 100644 --- a/scripts/update_android_permissions.py +++ b/scripts/update_android_permissions.py @@ -33,7 +33,8 @@ for pd in permission_divs: # check the permissions we currently have in dvm_permissions.py DVM_PERMISSIONS = {} -eval(compile(open('../StaticAnalyzer/views/android/dvm_permissions.py').read(), +eval(compile(open('../mobsf/StaticAnalyzer/views/' + 'android/dvm_permissions.py').read(), '', 'exec')) MANIFEST_PERMISSIONS = DVM_PERMISSIONS['MANIFEST_PERMISSION'] diff --git a/scripts/update_frida.py b/scripts/update_frida.py index 404f9e86..b056adb2 100644 --- a/scripts/update_frida.py +++ b/scripts/update_frida.py @@ -17,7 +17,7 @@ def get_latest_frida_binaries(): def download_file(url): fname = url.split('/')[-1] print(f'Downloading & Extracting - {fname}') - base = '../DynamicAnalyzer/tools/onDevice/frida/' + base = '../mobsf/DynamicAnalyzer/tools/onDevice/frida/' dwd_file = fname.replace('.xz', '') dwd_loc = f'{base}{dwd_file}' with requests.get(url, stream=True) as r: diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..0d3b795a --- /dev/null +++ b/setup.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +"""Setup for MobSF.""" + + +from setuptools import ( + find_packages, + setup, +) + +from pathlib import Path + + +SETTINGS_LOC = 'mobsf/MobSF/settings.py' + + +def read(rel_path): + init = Path(__file__).resolve().parent / rel_path + return init.read_text('utf-8', 'ignore') + + +def get_version(rel_path): + for line in read(rel_path).splitlines(): + if line.startswith('VERSION'): + return line.split('\'')[1] + raise RuntimeError('Unable to find version string.') + + +def settings_change(path, txt, new_text): + settings = Path(path) + old = settings.read_text() + settings.write_text(old.replace(txt, new_text)) + + +settings_change(SETTINGS_LOC, 'USE_HOME = False', 'USE_HOME = True') +description = ( + '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.') +setup( + name='mobsf', + version=get_version(SETTINGS_LOC), + description=description, + author='Ajin Abraham', + author_email='ajin25@gmail.com', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + ('License :: OSI Approved :: ' + 'GNU General Public License v3 (GPLv3)',), + 'Programming Language :: Python :: 3.7', + 'Topic :: Security', + 'Topic :: Software Development :: Quality Assurance', + ], + packages=find_packages(include=[ + 'mobsf', 'mobsf.*', + ]), + include_package_data=True, + python_requires='>=3.7<3.9', + entry_points={ + 'console_scripts': [ + 'mobsf = mobsf.__main__:main', + 'mobsfdb = mobsf.__main__:db', + ], + }, + url='https://github.com/MobSF/Mobile-Security-Framework-MobSF', + long_description=read('README.md'), + long_description_content_type='text/markdown', + install_requires=Path('requirements.txt').read_text().splitlines(), +) +settings_change(SETTINGS_LOC, 'USE_HOME = True', 'USE_HOME = False') diff --git a/tox.ini b/tox.ini index c5af4926..2bc06a52 100644 --- a/tox.ini +++ b/tox.ini @@ -14,7 +14,7 @@ whitelist_externals = bash commands = git submodule update --init --recursive - bash -c '. venv/bin/activate && python manage.py test' + bash -c '. venv/bin/activate && python manage.py test mobsf' [testenv:lint] skip_install = true @@ -62,15 +62,15 @@ exclude = .tox .git __pycache__ - uploads - downloads - static - templates - logs + mobsf/uploads + mobsf/downloads + mobsf/static + mobsf/templates venv - DynamicAnalyzer/tools/adb/ - StaticAnalyzer/migrations/ - StaticAnalyzer/tools/enjarify/ + build + mobsf/DynamicAnalyzer/tools/adb/ + mobsf/StaticAnalyzer/migrations/ + mobsf/StaticAnalyzer/tools/enjarify/ ignore = D100 D101