diff --git a/monkey/monkey_island/cc/main.py b/monkey/monkey_island/cc/main.py index 09f079c19..50e3bdd7c 100644 --- a/monkey/monkey_island/cc/main.py +++ b/monkey/monkey_island/cc/main.py @@ -31,7 +31,7 @@ from monkey_island.cc.bootloader_server import BootloaderHttpServer from monkey_island.cc.setup import setup -def main(should_setup_only): +def main(should_setup_only=False): logger.info("Starting bootloader server") mongo_url = os.environ.get('MONGO_URL', env.get_mongo_url()) bootloader_server_thread = Thread(target=BootloaderHttpServer(mongo_url).serve_forever, daemon=True) diff --git a/monkey/monkey_island/cc/services/attack/mitre_api_interface.py b/monkey/monkey_island/cc/services/attack/mitre_api_interface.py index ad4419be5..6390c600b 100644 --- a/monkey/monkey_island/cc/services/attack/mitre_api_interface.py +++ b/monkey/monkey_island/cc/services/attack/mitre_api_interface.py @@ -1,6 +1,6 @@ from typing import List, Dict -from stix2 import FileSystemSource, Filter, CourseOfAction, AttackPattern, v20 +from stix2 import FileSystemSource, Filter, CourseOfAction, AttackPattern class MitreApiInterface: @@ -32,14 +32,14 @@ class MitreApiInterface: return all_techniques @staticmethod - def get_stix2_external_reference_id(stix2_data: v20._DomainObject) -> str: + def get_stix2_external_reference_id(stix2_data) -> str: for reference in stix2_data['external_references']: if reference['source_name'] == "mitre-attack" and 'external_id' in reference: return reference['external_id'] return '' @staticmethod - def get_stix2_external_reference_url(stix2_data: v20._DomainObject) -> str: + def get_stix2_external_reference_url(stix2_data) -> str: for reference in stix2_data['external_references']: if 'url' in reference: return reference['url'] diff --git a/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py b/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py index 80dbe7518..bd4e07c24 100644 --- a/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py +++ b/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py @@ -5,7 +5,7 @@ from monkey_island.cc.database import mongo from common.utils.attack_utils import ScanStatus from monkey_island.cc.services.attack.attack_config import AttackConfig from common.utils.code_utils import abstractstatic -from cc.models.attack.attack_mitigations import AttackMitigations +from monkey_island.cc.models.attack.attack_mitigations import AttackMitigations logger = logging.getLogger(__name__) diff --git a/monkey/monkey_island/monkey_island.spec b/monkey/monkey_island/monkey_island.spec index ef6d9c2d3..59f95e34f 100644 --- a/monkey/monkey_island/monkey_island.spec +++ b/monkey/monkey_island/monkey_island.spec @@ -1,7 +1,7 @@ # -*- mode: python -*- import os import platform - +import sys __author__ = 'itay.mizeretz' @@ -9,15 +9,20 @@ block_cipher = None def main(): + # These data files and folders will be included in the bundle. + # The format of the tuples is (src, dest_dir). See https://pythonhosted.org/PyInstaller/spec-files.html#adding-data-files + added_datas = [ + ("../common/BUILD", "/common"), + ("../monkey_island/cc/services/attack/attack_data", "/monkey_island/cc/services/attack/attack_data") + ] + a = Analysis(['cc/main.py'], pathex=['..'], hiddenimports=get_hidden_imports(), - hookspath=None, + hookspath=[os.path.join(".", "pyinstaller_hooks")], runtime_hooks=None, binaries=None, - datas=[ - ("../common/BUILD", "/common") - ], + datas=added_datas, excludes=None, win_no_prefer_redirects=None, win_private_assemblies=None, @@ -36,8 +41,7 @@ def main(): name=get_monkey_filename(), debug=False, strip=get_exe_strip(), - upx=True, - upx_exclude=['vcruntime140.dll'], + upx=False, console=True, icon=get_exe_icon()) @@ -74,7 +78,7 @@ def get_linux_only_binaries(): def get_hidden_imports(): - return ['_cffi_backend', 'queue'] if is_windows() else ['_cffi_backend'] + return ['_cffi_backend', 'queue', 'pkg_resources.py2_warn'] if is_windows() else ['_cffi_backend'] def get_msvcr(): diff --git a/monkey/monkey_island/pyinstaller_hooks/__init__.py b/monkey/monkey_island/pyinstaller_hooks/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/monkey/monkey_island/pyinstaller_hooks/hook-stix2.py b/monkey/monkey_island/pyinstaller_hooks/hook-stix2.py new file mode 100644 index 000000000..22a9c9774 --- /dev/null +++ b/monkey/monkey_island/pyinstaller_hooks/hook-stix2.py @@ -0,0 +1,7 @@ +# Workaround for packaging Monkey Island using PyInstaller. See https://github.com/oasis-open/cti-python-stix2/issues/218 + +import os +from PyInstaller.utils.hooks import get_module_file_attribute + +stix2_dir = os.path.dirname(get_module_file_attribute('stix2')) +datas = [(stix2_dir, 'stix2')]