diff --git a/monkey/monkey_island/cc/app.py b/monkey/monkey_island/cc/app.py index e8238185e..4f055fec6 100644 --- a/monkey/monkey_island/cc/app.py +++ b/monkey/monkey_island/cc/app.py @@ -8,29 +8,30 @@ from bson.json_util import dumps from flask import Flask, send_from_directory, make_response, Response from werkzeug.exceptions import NotFound -from cc.auth import init_jwt -from cc.database import mongo, database -from cc.environment.environment import env -from cc.resources.client_run import ClientRun -from cc.resources.edge import Edge -from cc.resources.local_run import LocalRun -from cc.resources.log import Log -from cc.resources.island_logs import IslandLog -from cc.resources.monkey import Monkey -from cc.resources.monkey_configuration import MonkeyConfiguration -from cc.resources.island_configuration import IslandConfiguration -from cc.resources.monkey_download import MonkeyDownload -from cc.resources.netmap import NetMap -from cc.resources.node import Node -from cc.resources.remote_run import RemoteRun -from cc.resources.report import Report -from cc.resources.root import Root -from cc.resources.telemetry import Telemetry -from cc.resources.telemetry_feed import TelemetryFeed -from cc.resources.pba_file_download import PBAFileDownload -from cc.services.config import ConfigService -from cc.resources.pba_file_upload import FileUpload -from cc.resources.attack_telem import AttackTelem +from monkey_island.cc.auth import init_jwt +from monkey_island.cc.database import mongo, database +from monkey_island.cc.environment.environment import env +from monkey_island.cc.resources.client_run import ClientRun +from monkey_island.cc.resources.edge import Edge +from monkey_island.cc.resources.local_run import LocalRun +from monkey_island.cc.resources.log import Log +from monkey_island.cc.resources.island_logs import IslandLog +from monkey_island.cc.resources.monkey import Monkey +from monkey_island.cc.resources.monkey_configuration import MonkeyConfiguration +from monkey_island.cc.resources.island_configuration import IslandConfiguration +from monkey_island.cc.resources.monkey_download import MonkeyDownload +from monkey_island.cc.resources.netmap import NetMap +from monkey_island.cc.resources.node import Node +from monkey_island.cc.resources.remote_run import RemoteRun +from monkey_island.cc.resources.report import Report +from monkey_island.cc.resources.root import Root +from monkey_island.cc.resources.telemetry import Telemetry +from monkey_island.cc.resources.telemetry_feed import TelemetryFeed +from monkey_island.cc.resources.pba_file_download import PBAFileDownload +from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH +from monkey_island.cc.resources.pba_file_upload import FileUpload +from monkey_island.cc.resources.attack_telem import AttackTelem __author__ = 'Barak' @@ -42,7 +43,7 @@ def serve_static_file(static_path): if static_path.startswith('api/'): raise NotFound() try: - return send_from_directory(os.path.join(os.getcwd(), 'monkey_island/cc/ui/dist'), static_path) + return send_from_directory(os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc/ui/dist'), static_path) except NotFound: # Because react uses various urls for same index page, this is probably the user's intention. if static_path == HOME_FILE: diff --git a/monkey/monkey_island/cc/auth.py b/monkey/monkey_island/cc/auth.py index f12a7f8cd..2e7eb69ff 100644 --- a/monkey/monkey_island/cc/auth.py +++ b/monkey/monkey_island/cc/auth.py @@ -4,7 +4,7 @@ from flask import current_app, abort from flask_jwt import JWT, _jwt_required, JWTError from werkzeug.security import safe_str_cmp -from cc.environment.environment import env +from monkey_island.cc.environment.environment import env __author__ = 'itay.mizeretz' diff --git a/monkey/monkey_island/cc/consts.py b/monkey/monkey_island/cc/consts.py new file mode 100644 index 000000000..deb1db449 --- /dev/null +++ b/monkey/monkey_island/cc/consts.py @@ -0,0 +1,5 @@ +import os + +__author__ = 'itay.mizeretz' + +MONKEY_ISLAND_ABS_PATH = os.path.join(os.getcwd(), 'monkey_island') diff --git a/monkey/monkey_island/cc/encryptor.py b/monkey/monkey_island/cc/encryptor.py index 84e6fba9d..98473b60a 100644 --- a/monkey/monkey_island/cc/encryptor.py +++ b/monkey/monkey_island/cc/encryptor.py @@ -4,12 +4,14 @@ import os from Crypto import Random from Crypto.Cipher import AES +from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH + __author__ = "itay.mizeretz" class Encryptor: _BLOCK_SIZE = 32 - _DB_PASSWORD_FILENAME = "monkey_island/cc/mongo_key.bin" + _DB_PASSWORD_FILENAME = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc/mongo_key.bin') def __init__(self): self._load_key() diff --git a/monkey/monkey_island/cc/environment/aws.py b/monkey/monkey_island/cc/environment/aws.py index 7a53fadb2..3d3544a32 100644 --- a/monkey/monkey_island/cc/environment/aws.py +++ b/monkey/monkey_island/cc/environment/aws.py @@ -1,5 +1,5 @@ -import cc.auth -from cc.environment import Environment +import monkey_island.cc.auth +from monkey_island.cc.environment import Environment from common.cloud.aws_instance import AwsInstance from Crypto.Hash import SHA3_512 @@ -21,5 +21,5 @@ class AwsEnvironment(Environment): def get_auth_users(self): return [ - cc.auth.User(1, 'monkey', self.hash_secret(self._instance_id)) + monkey_island.cc.auth.User(1, 'monkey', self.hash_secret(self._instance_id)) ] diff --git a/monkey/monkey_island/cc/environment/environment.py b/monkey/monkey_island/cc/environment/environment.py index 27413a98c..3cd6bb587 100644 --- a/monkey/monkey_island/cc/environment/environment.py +++ b/monkey/monkey_island/cc/environment/environment.py @@ -1,9 +1,11 @@ import json import logging +import os -from cc.environment import standard -from cc.environment import aws -from cc.environment import password +from monkey_island.cc.environment import standard +from monkey_island.cc.environment import aws +from monkey_island.cc.environment import password +from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH __author__ = 'itay.mizeretz' @@ -21,7 +23,7 @@ ENV_DICT = { def load_server_configuration_from_file(): - with open('monkey_island/cc/server_config.json', 'r') as f: + with open(os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc/server_config.json'), 'r') as f: config_content = f.read() return json.loads(config_content) diff --git a/monkey/monkey_island/cc/environment/password.py b/monkey/monkey_island/cc/environment/password.py index 30ddd8267..89abfea8c 100644 --- a/monkey/monkey_island/cc/environment/password.py +++ b/monkey/monkey_island/cc/environment/password.py @@ -1,5 +1,5 @@ -from cc.environment import Environment -import cc.auth +from monkey_island.cc.environment import Environment +import monkey_island.cc.auth __author__ = 'itay.mizeretz' @@ -8,5 +8,5 @@ class PasswordEnvironment(Environment): def get_auth_users(self): return [ - cc.auth.User(1, self.config['user'], self.config['hash']) + monkey_island.cc.auth.User(1, self.config['user'], self.config['hash']) ] diff --git a/monkey/monkey_island/cc/environment/standard.py b/monkey/monkey_island/cc/environment/standard.py index 532ced959..f84aeaeef 100644 --- a/monkey/monkey_island/cc/environment/standard.py +++ b/monkey/monkey_island/cc/environment/standard.py @@ -1,5 +1,5 @@ -import cc.auth -from cc.environment import Environment +import monkey_island.cc.auth +from monkey_island.cc.environment import Environment __author__ = 'itay.mizeretz' @@ -11,5 +11,5 @@ class StandardEnvironment(Environment): def get_auth_users(self): return [ - cc.auth.User(1, StandardEnvironment.NO_AUTH_CREDS, StandardEnvironment.NO_AUTH_CREDS) + monkey_island.cc.auth.User(1, StandardEnvironment.NO_AUTH_CREDS, StandardEnvironment.NO_AUTH_CREDS) ] diff --git a/monkey/monkey_island/cc/exporter_init.py b/monkey/monkey_island/cc/exporter_init.py index 9b25469f9..3450e98f2 100644 --- a/monkey/monkey_island/cc/exporter_init.py +++ b/monkey/monkey_island/cc/exporter_init.py @@ -1,6 +1,6 @@ -from cc.environment.environment import load_env_from_file, AWS -from cc.report_exporter_manager import ReportExporterManager -from cc.resources.aws_exporter import AWSExporter +from monkey_island.cc.environment.environment import load_env_from_file, AWS +from monkey_island.cc.report_exporter_manager import ReportExporterManager +from monkey_island.cc.resources.aws_exporter import AWSExporter __author__ = 'maor.rayzin' diff --git a/monkey/monkey_island/cc/main.py b/monkey/monkey_island/cc/main.py index 713e83b96..412c3c399 100644 --- a/monkey/monkey_island/cc/main.py +++ b/monkey/monkey_island/cc/main.py @@ -11,17 +11,18 @@ BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) if BASE_PATH not in sys.path: sys.path.insert(0, BASE_PATH) -from cc.island_logger import json_setup_logging +from monkey_island.cc.island_logger import json_setup_logging +from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH # This is here in order to catch EVERYTHING, some functions are being called on imports the log init needs to be on top. -json_setup_logging(default_path=os.path.join(BASE_PATH, 'cc', 'island_logger_default_config.json'), +json_setup_logging(default_path=os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'island_logger_default_config.json'), default_level=logging.DEBUG) logger = logging.getLogger(__name__) -from cc.app import init_app -from cc.exporter_init import populate_exporter_list -from cc.utils import local_ip_addresses -from cc.environment.environment import env -from cc.database import is_db_server_up +from monkey_island.cc.app import init_app +from monkey_island.cc.exporter_init import populate_exporter_list +from monkey_island.cc.utils import local_ip_addresses +from monkey_island.cc.environment.environment import env +from monkey_island.cc.database import is_db_server_up def main(): @@ -37,12 +38,16 @@ def main(): populate_exporter_list() app = init_app(mongo_url) + + crt_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'server.crt') + key_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'server.key') + if env.is_debug(): - app.run(host='0.0.0.0', debug=True, ssl_context=('monkey_island/cc/server.crt', 'monkey_island/cc/server.key')) + app.run(host='0.0.0.0', debug=True, ssl_context=(crt_path, key_path)) else: http_server = HTTPServer(WSGIContainer(app), - ssl_options={'certfile': os.environ.get('SERVER_CRT', 'monkey_island/cc/server.crt'), - 'keyfile': os.environ.get('SERVER_KEY', 'monkey_island/cc/server.key')}) + ssl_options={'certfile': os.environ.get('SERVER_CRT', crt_path), + 'keyfile': os.environ.get('SERVER_KEY', key_path)}) http_server.listen(env.get_island_port()) logger.info( 'Monkey Island Server is running on https://{}:{}'.format(local_ip_addresses()[0], env.get_island_port())) diff --git a/monkey/monkey_island/cc/resources/attack_telem.py b/monkey/monkey_island/cc/resources/attack_telem.py index 0dfa013e8..bef0a8585 100644 --- a/monkey/monkey_island/cc/resources/attack_telem.py +++ b/monkey/monkey_island/cc/resources/attack_telem.py @@ -1,7 +1,7 @@ import flask_restful from flask import request import json -from cc.services.attack.attack_telem import set_results +from monkey_island.cc.services.attack.attack_telem import set_results import logging __author__ = 'VakarisZ' diff --git a/monkey/monkey_island/cc/resources/aws_exporter.py b/monkey/monkey_island/cc/resources/aws_exporter.py index 9b820cf51..b08c16ae6 100644 --- a/monkey/monkey_island/cc/resources/aws_exporter.py +++ b/monkey/monkey_island/cc/resources/aws_exporter.py @@ -4,9 +4,9 @@ from datetime import datetime import boto3 from botocore.exceptions import UnknownServiceError -from cc.resources.exporter import Exporter -from cc.services.config import ConfigService -from cc.environment.environment import load_server_configuration_from_file +from monkey_island.cc.resources.exporter import Exporter +from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.environment.environment import load_server_configuration_from_file from common.cloud.aws_instance import AwsInstance __author__ = 'maor.rayzin' diff --git a/monkey/monkey_island/cc/resources/client_run.py b/monkey/monkey_island/cc/resources/client_run.py index 0e4be42e7..4b2c03105 100644 --- a/monkey/monkey_island/cc/resources/client_run.py +++ b/monkey/monkey_island/cc/resources/client_run.py @@ -2,7 +2,7 @@ import logging from flask import request, jsonify import flask_restful -from cc.services.node import NodeService +from monkey_island.cc.services.node import NodeService __author__ = 'itay.mizeretz' diff --git a/monkey/monkey_island/cc/resources/edge.py b/monkey/monkey_island/cc/resources/edge.py index 2ef0c15bc..f3ce94ee3 100644 --- a/monkey/monkey_island/cc/resources/edge.py +++ b/monkey/monkey_island/cc/resources/edge.py @@ -1,7 +1,7 @@ from flask import request import flask_restful -from cc.services.edge import EdgeService +from monkey_island.cc.services.edge import EdgeService __author__ = 'Barak' diff --git a/monkey/monkey_island/cc/resources/island_configuration.py b/monkey/monkey_island/cc/resources/island_configuration.py index 57fda34fe..28ef32c46 100644 --- a/monkey/monkey_island/cc/resources/island_configuration.py +++ b/monkey/monkey_island/cc/resources/island_configuration.py @@ -3,8 +3,8 @@ import json import flask_restful from flask import request, jsonify, abort -from cc.auth import jwt_required -from cc.services.config import ConfigService +from monkey_island.cc.auth import jwt_required +from monkey_island.cc.services.config import ConfigService class IslandConfiguration(flask_restful.Resource): diff --git a/monkey/monkey_island/cc/resources/island_logs.py b/monkey/monkey_island/cc/resources/island_logs.py index 971306c14..724087e52 100644 --- a/monkey/monkey_island/cc/resources/island_logs.py +++ b/monkey/monkey_island/cc/resources/island_logs.py @@ -2,8 +2,8 @@ import logging import flask_restful -from cc.auth import jwt_required -from cc.services.island_logs import IslandLogService +from monkey_island.cc.auth import jwt_required +from monkey_island.cc.services.island_logs import IslandLogService __author__ = "Maor.Rayzin" diff --git a/monkey/monkey_island/cc/resources/local_run.py b/monkey/monkey_island/cc/resources/local_run.py index 6e7d44cb9..d402a440c 100644 --- a/monkey/monkey_island/cc/resources/local_run.py +++ b/monkey/monkey_island/cc/resources/local_run.py @@ -6,16 +6,18 @@ import sys from flask import request, jsonify, make_response import flask_restful -from cc.environment.environment import env -from cc.resources.monkey_download import get_monkey_executable -from cc.services.node import NodeService -from cc.utils import local_ip_addresses +from monkey_island.cc.environment.environment import env +from monkey_island.cc.resources.monkey_download import get_monkey_executable +from monkey_island.cc.services.node import NodeService +from monkey_island.cc.utils import local_ip_addresses +from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH __author__ = 'Barak' import logging logger = logging.getLogger(__name__) + def run_local_monkey(): import platform import subprocess @@ -26,8 +28,8 @@ def run_local_monkey(): if not result: return False, "OS Type not found" - monkey_path = os.path.join(os.getcwd(), 'monkey_island', 'cc', 'binaries', result['filename']) - target_path = os.path.join(os.getcwd(), 'monkey_island', result['filename']) + monkey_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'binaries', result['filename']) + target_path = os.path.join(MONKEY_ISLAND_ABS_PATH, result['filename']) # copy the executable to temp path (don't run the monkey from its current location as it may delete itself) try: diff --git a/monkey/monkey_island/cc/resources/log.py b/monkey/monkey_island/cc/resources/log.py index 62dee1168..cbce92a37 100644 --- a/monkey/monkey_island/cc/resources/log.py +++ b/monkey/monkey_island/cc/resources/log.py @@ -4,10 +4,10 @@ import flask_restful from bson import ObjectId from flask import request -from cc.auth import jwt_required -from cc.database import mongo -from cc.services.log import LogService -from cc.services.node import NodeService +from monkey_island.cc.auth import jwt_required +from monkey_island.cc.database import mongo +from monkey_island.cc.services.log import LogService +from monkey_island.cc.services.node import NodeService __author__ = "itay.mizeretz" diff --git a/monkey/monkey_island/cc/resources/monkey.py b/monkey/monkey_island/cc/resources/monkey.py index 80dd14604..7eb7ecc69 100644 --- a/monkey/monkey_island/cc/resources/monkey.py +++ b/monkey/monkey_island/cc/resources/monkey.py @@ -5,9 +5,9 @@ import dateutil.parser from flask import request import flask_restful -from cc.database import mongo -from cc.services.config import ConfigService -from cc.services.node import NodeService +from monkey_island.cc.database import mongo +from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.node import NodeService __author__ = 'Barak' diff --git a/monkey/monkey_island/cc/resources/monkey_configuration.py b/monkey/monkey_island/cc/resources/monkey_configuration.py index 7032ba643..1c067892f 100644 --- a/monkey/monkey_island/cc/resources/monkey_configuration.py +++ b/monkey/monkey_island/cc/resources/monkey_configuration.py @@ -3,8 +3,8 @@ import json import flask_restful from flask import request, jsonify, abort -from cc.auth import jwt_required -from cc.services.config import ConfigService +from monkey_island.cc.auth import jwt_required +from monkey_island.cc.services.config import ConfigService __author__ = 'Barak' diff --git a/monkey/monkey_island/cc/resources/monkey_download.py b/monkey/monkey_island/cc/resources/monkey_download.py index 305d8c6e9..78a092a26 100644 --- a/monkey/monkey_island/cc/resources/monkey_download.py +++ b/monkey/monkey_island/cc/resources/monkey_download.py @@ -5,6 +5,8 @@ import os import flask_restful from flask import request, send_from_directory +from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH + __author__ = 'Barak' logger = logging.getLogger(__name__) @@ -70,7 +72,7 @@ class MonkeyDownload(flask_restful.Resource): # Used by monkey. can't secure. def get(self, path): - return send_from_directory('binaries', path) + return send_from_directory(os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'binaries'), path) # Used by monkey. can't secure. def post(self): @@ -81,7 +83,7 @@ class MonkeyDownload(flask_restful.Resource): if result: # change resulting from new base path - real_path = os.path.join("monkey_island", "cc", 'binaries', result['filename']) + real_path = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", 'binaries', result['filename']) if os.path.isfile(real_path): result['size'] = os.path.getsize(real_path) return result diff --git a/monkey/monkey_island/cc/resources/netmap.py b/monkey/monkey_island/cc/resources/netmap.py index 3ba7fafa8..ed83414f5 100644 --- a/monkey/monkey_island/cc/resources/netmap.py +++ b/monkey/monkey_island/cc/resources/netmap.py @@ -1,9 +1,9 @@ import flask_restful -from cc.auth import jwt_required -from cc.services.edge import EdgeService -from cc.services.node import NodeService -from cc.database import mongo +from monkey_island.cc.auth import jwt_required +from monkey_island.cc.services.edge import EdgeService +from monkey_island.cc.services.node import NodeService +from monkey_island.cc.database import mongo __author__ = 'Barak' diff --git a/monkey/monkey_island/cc/resources/node.py b/monkey/monkey_island/cc/resources/node.py index bc00c40cf..e4c2761c9 100644 --- a/monkey/monkey_island/cc/resources/node.py +++ b/monkey/monkey_island/cc/resources/node.py @@ -1,8 +1,8 @@ from flask import request import flask_restful -from cc.auth import jwt_required -from cc.services.node import NodeService +from monkey_island.cc.auth import jwt_required +from monkey_island.cc.services.node import NodeService __author__ = 'Barak' diff --git a/monkey/monkey_island/cc/resources/pba_file_download.py b/monkey/monkey_island/cc/resources/pba_file_download.py index b4a33984e..5b567e8e4 100644 --- a/monkey/monkey_island/cc/resources/pba_file_download.py +++ b/monkey/monkey_island/cc/resources/pba_file_download.py @@ -1,6 +1,6 @@ import flask_restful from flask import send_from_directory -from cc.resources.pba_file_upload import GET_FILE_DIR +from monkey_island.cc.resources.pba_file_upload import GET_FILE_DIR __author__ = 'VakarisZ' diff --git a/monkey/monkey_island/cc/resources/pba_file_upload.py b/monkey/monkey_island/cc/resources/pba_file_upload.py index 9a24a9a90..0d924a742 100644 --- a/monkey/monkey_island/cc/resources/pba_file_upload.py +++ b/monkey/monkey_island/cc/resources/pba_file_upload.py @@ -1,8 +1,8 @@ import flask_restful from flask import request, send_from_directory, Response -from cc.services.config import ConfigService -from cc.services.post_breach_files import PBA_WINDOWS_FILENAME_PATH, PBA_LINUX_FILENAME_PATH, UPLOADS_DIR -from cc.auth import jwt_required +from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.post_breach_files import PBA_WINDOWS_FILENAME_PATH, PBA_LINUX_FILENAME_PATH, UPLOADS_DIR +from monkey_island.cc.auth import jwt_required import os from werkzeug.utils import secure_filename import logging diff --git a/monkey/monkey_island/cc/resources/remote_run.py b/monkey/monkey_island/cc/resources/remote_run.py index 5484d23d2..ccd9fbbbe 100644 --- a/monkey/monkey_island/cc/resources/remote_run.py +++ b/monkey/monkey_island/cc/resources/remote_run.py @@ -2,8 +2,8 @@ import json from flask import request, jsonify, make_response import flask_restful -from cc.auth import jwt_required -from cc.services.remote_run_aws import RemoteRunAwsService +from monkey_island.cc.auth import jwt_required +from monkey_island.cc.services.remote_run_aws import RemoteRunAwsService from common.cloud.aws_service import AwsService diff --git a/monkey/monkey_island/cc/resources/report.py b/monkey/monkey_island/cc/resources/report.py index 1a00fa609..62a014fef 100644 --- a/monkey/monkey_island/cc/resources/report.py +++ b/monkey/monkey_island/cc/resources/report.py @@ -1,7 +1,7 @@ import flask_restful -from cc.auth import jwt_required -from cc.services.report import ReportService +from monkey_island.cc.auth import jwt_required +from monkey_island.cc.services.report import ReportService __author__ = "itay.mizeretz" diff --git a/monkey/monkey_island/cc/resources/root.py b/monkey/monkey_island/cc/resources/root.py index 923535096..828a97682 100644 --- a/monkey/monkey_island/cc/resources/root.py +++ b/monkey/monkey_island/cc/resources/root.py @@ -4,13 +4,13 @@ import logging import flask_restful from flask import request, make_response, jsonify -from cc.auth import jwt_required -from cc.database import mongo -from cc.services.config import ConfigService -from cc.services.node import NodeService -from cc.services.report import ReportService -from cc.utils import local_ip_addresses -from cc.services.post_breach_files import remove_PBA_files +from monkey_island.cc.auth import jwt_required +from monkey_island.cc.database import mongo +from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.node import NodeService +from monkey_island.cc.services.report import ReportService +from monkey_island.cc.utils import local_ip_addresses +from monkey_island.cc.services.post_breach_files import remove_PBA_files __author__ = 'Barak' diff --git a/monkey/monkey_island/cc/resources/telemetry.py b/monkey/monkey_island/cc/resources/telemetry.py index 3e2824d3b..04a6ddbd1 100644 --- a/monkey/monkey_island/cc/resources/telemetry.py +++ b/monkey/monkey_island/cc/resources/telemetry.py @@ -7,14 +7,14 @@ import dateutil import flask_restful from flask import request -from cc.auth import jwt_required -from cc.database import mongo -from cc.services import mimikatz_utils -from cc.services.config import ConfigService -from cc.services.edge import EdgeService -from cc.services.node import NodeService -from cc.encryptor import encryptor -from cc.services.wmi_handler import WMIHandler +from monkey_island.cc.auth import jwt_required +from monkey_island.cc.database import mongo +from monkey_island.cc.services import mimikatz_utils +from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.edge import EdgeService +from monkey_island.cc.services.node import NodeService +from monkey_island.cc.encryptor import encryptor +from monkey_island.cc.services.wmi_handler import WMIHandler __author__ = 'Barak' diff --git a/monkey/monkey_island/cc/resources/telemetry_feed.py b/monkey/monkey_island/cc/resources/telemetry_feed.py index 8286bba00..f01ff90d6 100644 --- a/monkey/monkey_island/cc/resources/telemetry_feed.py +++ b/monkey/monkey_island/cc/resources/telemetry_feed.py @@ -5,9 +5,9 @@ import flask_restful from flask import request import flask_pymongo -from cc.auth import jwt_required -from cc.database import mongo -from cc.services.node import NodeService +from monkey_island.cc.auth import jwt_required +from monkey_island.cc.database import mongo +from monkey_island.cc.services.node import NodeService __author__ = 'itay.mizeretz' diff --git a/monkey/monkey_island/cc/services/attack/attack_telem.py b/monkey/monkey_island/cc/services/attack/attack_telem.py index 295100c23..a4e219270 100644 --- a/monkey/monkey_island/cc/services/attack/attack_telem.py +++ b/monkey/monkey_island/cc/services/attack/attack_telem.py @@ -2,7 +2,7 @@ File that contains ATT&CK telemetry storing/retrieving logic """ import logging -from cc.database import mongo +from monkey_island.cc.database import mongo __author__ = "VakarisZ" diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index 87b4bf914..171fbb7bf 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -4,12 +4,12 @@ import functools import logging from jsonschema import Draft4Validator, validators from six import string_types -import cc.services.post_breach_files +import monkey_island.cc.services.post_breach_files -from cc.database import mongo -from cc.encryptor import encryptor -from cc.environment.environment import env -from cc.utils import local_ip_addresses +from monkey_island.cc.database import mongo +from monkey_island.cc.encryptor import encryptor +from monkey_island.cc.environment.environment import env +from monkey_island.cc.utils import local_ip_addresses from config_schema import SCHEMA __author__ = "itay.mizeretz" @@ -146,7 +146,7 @@ class ConfigService: @staticmethod def update_config(config_json, should_encrypt): # PBA file upload happens on pba_file_upload endpoint and corresponding config options are set there - cc.services.post_breach_files.set_config_PBA_files(config_json) + monkey_island.cc.services.post_breach_files.set_config_PBA_files(config_json) if should_encrypt: try: ConfigService.encrypt_config(config_json) @@ -182,7 +182,7 @@ class ConfigService: @staticmethod def reset_config(): - cc.services.post_breach_files.remove_PBA_files() + monkey_island.cc.services.post_breach_files.remove_PBA_files() config = ConfigService.get_default_config(True) ConfigService.set_server_ips_in_config(config) ConfigService.update_config(config, should_encrypt=False) diff --git a/monkey/monkey_island/cc/services/edge.py b/monkey/monkey_island/cc/services/edge.py index 520808be8..eb23c3901 100644 --- a/monkey/monkey_island/cc/services/edge.py +++ b/monkey/monkey_island/cc/services/edge.py @@ -1,7 +1,7 @@ from bson import ObjectId -from cc.database import mongo -import cc.services.node +from monkey_island.cc.database import mongo +import monkey_island.cc.services.node __author__ = "itay.mizeretz" @@ -87,7 +87,7 @@ class EdgeService: @staticmethod def get_infected_monkey_island_pseudo_edges(): - monkey = cc.services.node.NodeService.get_monkey_island_monkey() + monkey = monkey_island.cc.services.node.NodeService.get_monkey_island_monkey() existing_ids = [x["from"] for x in mongo.db.edge.find({"to": monkey["_id"]})] monkey_ids = [x["_id"] for x in mongo.db.monkey.find({}) if ("tunnel" not in x) and (x["_id"] not in existing_ids) and (x["_id"] != monkey["_id"])] @@ -136,11 +136,11 @@ class EdgeService: {"_id": edge["_id"]}, {"$set": {"exploited": True}} ) - cc.services.node.NodeService.set_node_exploited(edge["to"]) + monkey_island.cc.services.node.NodeService.set_node_exploited(edge["to"]) @staticmethod def get_edge_label(edge): - NodeService = cc.services.node.NodeService + NodeService = monkey_island.cc.services.node.NodeService from_label = NodeService.get_monkey_label(NodeService.get_monkey_by_id(edge["from"])) if edge["to"] == ObjectId("000000000000000000000000"): to_label = 'MonkeyIsland' diff --git a/monkey/monkey_island/cc/services/log.py b/monkey/monkey_island/cc/services/log.py index 81603e62e..a685e45b6 100644 --- a/monkey/monkey_island/cc/services/log.py +++ b/monkey/monkey_island/cc/services/log.py @@ -1,7 +1,7 @@ from datetime import datetime -import cc.services.node -from cc.database import mongo, database +import monkey_island.cc.services.node +from monkey_island.cc.database import mongo, database __author__ = "itay.mizeretz" @@ -15,8 +15,8 @@ class LogService: log = mongo.db.log.find_one({'monkey_id': monkey_id}) if log: log_file = database.gridfs.get(log['file_id']) - monkey_label = cc.services.node.NodeService.get_monkey_label( - cc.services.node.NodeService.get_monkey_by_id(log['monkey_id'])) + monkey_label = monkey_island.cc.services.node.NodeService.get_monkey_label( + monkey_island.cc.services.node.NodeService.get_monkey_by_id(log['monkey_id'])) return \ { 'monkey_label': monkey_label, diff --git a/monkey/monkey_island/cc/services/node.py b/monkey/monkey_island/cc/services/node.py index b2a264f33..fa500aab5 100644 --- a/monkey/monkey_island/cc/services/node.py +++ b/monkey/monkey_island/cc/services/node.py @@ -2,10 +2,10 @@ from datetime import datetime, timedelta from bson import ObjectId -import cc.services.log -from cc.database import mongo -from cc.services.edge import EdgeService -from cc.utils import local_ip_addresses +import monkey_island.cc.services.log +from monkey_island.cc.database import mongo +from monkey_island.cc.services.edge import EdgeService +from monkey_island.cc.utils import local_ip_addresses import socket __author__ = "itay.mizeretz" @@ -59,7 +59,7 @@ class NodeService: else: new_node["services"] = [] - new_node['has_log'] = cc.services.log.LogService.log_exists(ObjectId(node_id)) + new_node['has_log'] = monkey_island.cc.services.log.LogService.log_exists(ObjectId(node_id)) return new_node @staticmethod diff --git a/monkey/monkey_island/cc/services/post_breach_files.py b/monkey/monkey_island/cc/services/post_breach_files.py index 076fa7159..7d88d9d85 100644 --- a/monkey/monkey_island/cc/services/post_breach_files.py +++ b/monkey/monkey_island/cc/services/post_breach_files.py @@ -1,4 +1,4 @@ -import cc.services.config +import monkey_island.cc.services.config import logging import os @@ -13,9 +13,9 @@ UPLOADS_DIR = 'monkey_island/cc/userUploads' def remove_PBA_files(): - if cc.services.config.ConfigService.get_config(): - windows_filename = cc.services.config.ConfigService.get_config_value(PBA_WINDOWS_FILENAME_PATH) - linux_filename = cc.services.config.ConfigService.get_config_value(PBA_LINUX_FILENAME_PATH) + if monkey_island.cc.services.config.ConfigService.get_config(): + windows_filename = monkey_island.cc.services.config.ConfigService.get_config_value(PBA_WINDOWS_FILENAME_PATH) + linux_filename = monkey_island.cc.services.config.ConfigService.get_config_value(PBA_LINUX_FILENAME_PATH) if linux_filename: remove_file(linux_filename) if windows_filename: @@ -36,8 +36,8 @@ def set_config_PBA_files(config_json): Sets PBA file info in config_json to current config's PBA file info values. :param config_json: config_json that will be modified """ - if cc.services.config.ConfigService.get_config(): - linux_filename = cc.services.config.ConfigService.get_config_value(PBA_LINUX_FILENAME_PATH) - windows_filename = cc.services.config.ConfigService.get_config_value(PBA_WINDOWS_FILENAME_PATH) + if monkey_island.cc.services.config.ConfigService.get_config(): + linux_filename = monkey_island.cc.services.config.ConfigService.get_config_value(PBA_LINUX_FILENAME_PATH) + windows_filename = monkey_island.cc.services.config.ConfigService.get_config_value(PBA_WINDOWS_FILENAME_PATH) config_json['monkey']['behaviour']['PBA_linux_filename'] = linux_filename config_json['monkey']['behaviour']['PBA_windows_filename'] = windows_filename diff --git a/monkey/monkey_island/cc/services/pth_report.py b/monkey/monkey_island/cc/services/pth_report.py index 3d7375dc1..93fd51989 100644 --- a/monkey/monkey_island/cc/services/pth_report.py +++ b/monkey/monkey_island/cc/services/pth_report.py @@ -1,10 +1,10 @@ from itertools import product -from cc.database import mongo +from monkey_island.cc.database import mongo from bson import ObjectId -from cc.services.groups_and_users_consts import USERTYPE -from cc.services.node import NodeService +from monkey_island.cc.services.groups_and_users_consts import USERTYPE +from monkey_island.cc.services.node import NodeService __author__ = 'maor.rayzin' diff --git a/monkey/monkey_island/cc/services/remote_run_aws.py b/monkey/monkey_island/cc/services/remote_run_aws.py index 0310cd9f9..7cc26008d 100644 --- a/monkey/monkey_island/cc/services/remote_run_aws.py +++ b/monkey/monkey_island/cc/services/remote_run_aws.py @@ -1,4 +1,4 @@ -from cc.services.config import ConfigService +from monkey_island.cc.services.config import ConfigService from common.cloud.aws_instance import AwsInstance from common.cloud.aws_service import AwsService from common.cmd.aws.aws_cmd_runner import AwsCmdRunner diff --git a/monkey/monkey_island/cc/services/report.py b/monkey/monkey_island/cc/services/report.py index 595d566f8..a19dc03c0 100644 --- a/monkey/monkey_island/cc/services/report.py +++ b/monkey/monkey_island/cc/services/report.py @@ -9,12 +9,12 @@ from enum import Enum from six import text_type -from cc.database import mongo -from cc.report_exporter_manager import ReportExporterManager -from cc.services.config import ConfigService -from cc.services.edge import EdgeService -from cc.services.node import NodeService -from cc.utils import local_ip_addresses, get_subnets +from monkey_island.cc.database import mongo +from monkey_island.cc.report_exporter_manager import ReportExporterManager +from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.edge import EdgeService +from monkey_island.cc.services.node import NodeService +from monkey_island.cc.utils import local_ip_addresses, get_subnets from pth_report import PTHReportService from common.network.network_range import NetworkRange diff --git a/monkey/monkey_island/cc/services/wmi_handler.py b/monkey/monkey_island/cc/services/wmi_handler.py index fec12c152..227bd18da 100644 --- a/monkey/monkey_island/cc/services/wmi_handler.py +++ b/monkey/monkey_island/cc/services/wmi_handler.py @@ -1,5 +1,5 @@ -from cc.database import mongo -from cc.services.groups_and_users_consts import USERTYPE, GROUPTYPE +from monkey_island.cc.database import mongo +from monkey_island.cc.services.groups_and_users_consts import USERTYPE, GROUPTYPE __author__ = 'maor.rayzin' diff --git a/monkey/monkey_island/monkey_island.ico b/monkey/monkey_island/monkey_island.ico new file mode 100644 index 000000000..0a9976256 Binary files /dev/null and b/monkey/monkey_island/monkey_island.ico differ diff --git a/monkey/monkey_island/monkey_island.spec b/monkey/monkey_island/monkey_island.spec new file mode 100644 index 000000000..342df5ab3 --- /dev/null +++ b/monkey/monkey_island/monkey_island.spec @@ -0,0 +1,93 @@ +# -*- mode: python -*- +import os +import platform + + +__author__ = 'itay.mizeretz' + +block_cipher = None + + +def main(): + a = Analysis(['cc/main.py'], + pathex=['..'], + hiddenimports=get_hidden_imports(), + hookspath=None, + runtime_hooks=None, + binaries=None, + datas=None, + excludes=None, + win_no_prefer_redirects=None, + win_private_assemblies=None, + cipher=block_cipher + ) + + a.binaries += get_binaries() + a.datas = process_datas(a.datas) + + pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) + exe = EXE(pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + name=get_monkey_filename(), + debug=False, + strip=get_exe_strip(), + upx=True, + console=True, + icon=get_exe_icon()) + + +def is_windows(): + return platform.system().find("Windows") >= 0 + + +def is_32_bit(): + return platform.architecture()[0] == "32bit" + + +def process_datas(orig_datas): + datas = orig_datas + if is_windows(): + datas = [i for i in datas if i[0].find('Include') < 0] + return datas + + +def get_binaries(): + binaries = get_windows_only_binaries() if is_windows() else get_linux_only_binaries() + return binaries + + +def get_windows_only_binaries(): + binaries = [] + binaries += get_msvcr() + return binaries + + +def get_linux_only_binaries(): + binaries = [] + return binaries + + +def get_hidden_imports(): + return ['_cffi_backend', 'queue'] if is_windows() else ['_cffi_backend'] + + +def get_msvcr(): + return [('msvcr100.dll', os.environ['WINDIR'] + '\\system32\\msvcr100.dll', 'BINARY')] + + +def get_monkey_filename(): + return 'monkey_island.exe' if is_windows() else 'monkey_island' + + +def get_exe_strip(): + return not is_windows() + + +def get_exe_icon(): + return 'monkey_island.ico' if is_windows() else None + + +main() # We don't check if __main__ because this isn't the main script. diff --git a/monkey/monkey_island/requirements.txt b/monkey/monkey_island/requirements.txt index b910f87cb..147f3481c 100644 --- a/monkey/monkey_island/requirements.txt +++ b/monkey/monkey_island/requirements.txt @@ -9,11 +9,13 @@ flask Flask-Pymongo Flask-Restful Flask-JWT -jsonschema +jsonschema==2.6.0 netifaces ipaddress enum34 pycryptodome boto3 awscli -bson \ No newline at end of file +bson +cffi +PyInstaller \ No newline at end of file diff --git a/monkey/monkey_island/windows/build_pyinstaller.bat b/monkey/monkey_island/windows/build_pyinstaller.bat new file mode 100644 index 000000000..58ec101d0 --- /dev/null +++ b/monkey/monkey_island/windows/build_pyinstaller.bat @@ -0,0 +1,5 @@ +REM - Builds Monkey Island Server EXE using pyinstaller - +bin\Python27\Scripts\pyinstaller.exe -F --log-level=DEBUG --clean --upx-dir=.\bin monkey_island.spec +move /Y dist\monkey_island.exe monkey_island.exe +rmdir /S /Q build +rmdir /S /Q dist \ No newline at end of file diff --git a/monkey/monkey_island/windows/run_cc.bat b/monkey/monkey_island/windows/run_cc.bat index f674376a1..c1a2fd88e 100644 --- a/monkey/monkey_island/windows/run_cc.bat +++ b/monkey/monkey_island/windows/run_cc.bat @@ -1,3 +1,4 @@ +REM - Runs Monkey Island Server using python - @title C^&C Server @pushd .. @monkey_island\bin\Python27\Scripts\python monkey_island.py diff --git a/monkey/monkey_island/windows/run_cc_exe.bat b/monkey/monkey_island/windows/run_cc_exe.bat new file mode 100644 index 000000000..a8b2cb14b --- /dev/null +++ b/monkey/monkey_island/windows/run_cc_exe.bat @@ -0,0 +1,5 @@ +REM - Runs Monkey Island Server using built pyinstaller EXE - +@title C^&C Server +@pushd .. +@monkey_island\monkey_island.exe +@popd \ No newline at end of file diff --git a/monkey/monkey_island/windows/run_mongodb.bat b/monkey/monkey_island/windows/run_mongodb.bat index ca33c22d7..970e98874 100644 --- a/monkey/monkey_island/windows/run_mongodb.bat +++ b/monkey/monkey_island/windows/run_mongodb.bat @@ -1,2 +1,3 @@ +REM - Runs MongoDB Server - @title MongoDB @bin\mongodb\mongod.exe --dbpath db \ No newline at end of file diff --git a/monkey/monkey_island/windows/run_server.bat b/monkey/monkey_island/windows/run_server.bat index a15fbcc04..ab2ad274c 100644 --- a/monkey/monkey_island/windows/run_server.bat +++ b/monkey/monkey_island/windows/run_server.bat @@ -1,4 +1,5 @@ +REM - Runs MongoDB Server & Monkey Island Server using built pyinstaller EXE - if not exist db mkdir db start windows\run_mongodb.bat -start windows\run_cc.bat +start windows\run_cc_exe.bat start https://localhost:5000 \ No newline at end of file diff --git a/monkey/monkey_island/windows/run_server_py.bat b/monkey/monkey_island/windows/run_server_py.bat new file mode 100644 index 000000000..07a587f49 --- /dev/null +++ b/monkey/monkey_island/windows/run_server_py.bat @@ -0,0 +1,5 @@ +REM - Runs MongoDB Server & Monkey Island Server using python - +if not exist db mkdir db +start windows\run_mongodb.bat +start windows\run_cc.bat +start https://localhost:5000 \ No newline at end of file