File deletion

This commit is contained in:
VakarisZ 2019-02-19 21:22:41 +02:00
parent d539f2301c
commit 4292fc845b
4 changed files with 28 additions and 0 deletions

3
.gitignore vendored
View File

@ -68,3 +68,6 @@ bin
/monkey/monkey_island/cc/server.crt /monkey/monkey_island/cc/server.crt
/monkey/monkey_island/cc/server.csr /monkey/monkey_island/cc/server.csr
/monkey/monkey_island/cc/ui/node_modules/ /monkey/monkey_island/cc/ui/node_modules/
# User files
/monkey/monkey_island/cc/userUploads

View File

@ -25,6 +25,9 @@ class Monkey(flask_restful.Resource):
if guid: if guid:
monkey_json = mongo.db.monkey.find_one_or_404({"guid": guid}) monkey_json = mongo.db.monkey.find_one_or_404({"guid": guid})
monkey_json['config'] = ConfigService.decrypt_flat_config(monkey_json['config']) 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 monkey_json
return {} return {}

View File

@ -42,6 +42,7 @@ class Root(flask_restful.Resource):
@staticmethod @staticmethod
@jwt_required() @jwt_required()
def reset_db(): def reset_db():
ConfigService.remove_PBA_files()
# We can't drop system collections. # We can't drop system collections.
[mongo.db[x].drop() for x in mongo.db.collection_names() if not x.startswith('system.')] [mongo.db[x].drop() for x in mongo.db.collection_names() if not x.startswith('system.')]
ConfigService.init_config() ConfigService.init_config()

View File

@ -179,6 +179,7 @@ class ConfigService:
@staticmethod @staticmethod
def reset_config(): def reset_config():
ConfigService.remove_PBA_files()
config = ConfigService.get_default_config(True) config = ConfigService.get_default_config(True)
ConfigService.set_server_ips_in_config(config) ConfigService.set_server_ips_in_config(config)
ConfigService.update_config(config, should_encrypt=False) 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']['name'] = windows_name
post_breach_files['windows_file_info']['size'] = windows_size 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 @staticmethod
def upload_file(file_data, directory): def upload_file(file_data, directory):
""" """