forked from p15670423/monkey
File deletion
This commit is contained in:
parent
d539f2301c
commit
4292fc845b
|
@ -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
|
||||
|
|
|
@ -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 {}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue