diff --git a/.gitignore b/.gitignore index 44ae856a5..062bf065e 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,6 @@ bin /monkey/monkey_island/cc/server.crt /monkey/monkey_island/cc/server.csr /monkey/monkey_island/cc/ui/node_modules/ + +# User files +/monkey/monkey_island/cc/userUploads diff --git a/monkey/monkey_island/cc/resources/monkey.py b/monkey/monkey_island/cc/resources/monkey.py index 80dd14604..171456d42 100644 --- a/monkey/monkey_island/cc/resources/monkey.py +++ b/monkey/monkey_island/cc/resources/monkey.py @@ -25,6 +25,9 @@ class Monkey(flask_restful.Resource): if guid: monkey_json = mongo.db.monkey.find_one_or_404({"guid": guid}) monkey_json['config'] = ConfigService.decrypt_flat_config(monkey_json['config']) + # Don't send file contents to the monkey + monkey_json['config']['custom_post_breach']['linux_file'] = '' + monkey_json['config']['custom_post_breach']['windows_file'] = '' return monkey_json return {} diff --git a/monkey/monkey_island/cc/resources/root.py b/monkey/monkey_island/cc/resources/root.py index 10e8f5170..1a18c2611 100644 --- a/monkey/monkey_island/cc/resources/root.py +++ b/monkey/monkey_island/cc/resources/root.py @@ -42,6 +42,7 @@ class Root(flask_restful.Resource): @staticmethod @jwt_required() def reset_db(): + ConfigService.remove_PBA_files() # We can't drop system collections. [mongo.db[x].drop() for x in mongo.db.collection_names() if not x.startswith('system.')] ConfigService.init_config() diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index 76a67a3c4..ae09ed176 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -179,6 +179,7 @@ class ConfigService: @staticmethod def reset_config(): + ConfigService.remove_PBA_files() config = ConfigService.get_default_config(True) ConfigService.set_server_ips_in_config(config) ConfigService.update_config(config, should_encrypt=False) @@ -309,6 +310,26 @@ class ConfigService: post_breach_files['windows_file_info']['name'] = windows_name post_breach_files['windows_file_info']['size'] = windows_size + @staticmethod + def remove_PBA_files(): + # Remove PBA files + current_config = ConfigService.get_config() + if current_config: + linux_file_name = ConfigService.get_config_value(['monkey', 'behaviour', 'custom_post_breach', 'linux_file_info', 'name']) + windows_file_name = ConfigService.get_config_value(['monkey', 'behaviour', 'custom_post_breach', 'windows_file_info', 'name']) + ConfigService.remove_file(linux_file_name) + ConfigService.remove_file(windows_file_name) + + @staticmethod + def remove_file(file_name): + file_path = os.path.join(UPLOADS_DIR, file_name) + try: + if os.path.exists(file_path): + os.remove(file_path) + except OSError as e: + logger.error("Can't remove previously uploaded post breach files: %s" % e) + + @staticmethod def upload_file(file_data, directory): """