diff --git a/monkey/monkey_island/cc/app.py b/monkey/monkey_island/cc/app.py index fd95abc6b..863529ea0 100644 --- a/monkey/monkey_island/cc/app.py +++ b/monkey/monkey_island/cc/app.py @@ -119,7 +119,8 @@ def init_app(mongo_url): api.add_resource(Log, '/api/log', '/api/log/') api.add_resource(IslandLog, '/api/log/island/download', '/api/log/island/download/') api.add_resource(PBAFileDownload, '/api/pba/download/') - api.add_resource(FileUpload, '/api/fileUpload/') + api.add_resource(FileUpload, '/api/fileUpload/', + '/api/fileUpload/?load=') api.add_resource(RemoteRun, '/api/remote-monkey', '/api/remote-monkey/') return app diff --git a/monkey/monkey_island/cc/resources/file_upload.py b/monkey/monkey_island/cc/resources/file_upload.py index 7e53ab3be..d2b2f4d0e 100644 --- a/monkey/monkey_island/cc/resources/file_upload.py +++ b/monkey/monkey_island/cc/resources/file_upload.py @@ -1,9 +1,11 @@ import flask_restful -from flask import request, send_from_directory +from flask import request, send_from_directory, Response from cc.services.config import ConfigService import os from werkzeug.utils import secure_filename +import logging +LOG = logging.getLogger(__name__) UPLOADS_DIR = "./monkey_island/cc/userUploads" @@ -12,18 +14,48 @@ class FileUpload(flask_restful.Resource): def get(self, path): return send_from_directory(UPLOADS_DIR, path) + def get(self, file_type, file_name): + req_data = request.data + def post(self, file_type): + filename = '' if file_type == 'PBAlinux': - config = ConfigService.get_config() - file_info = ConfigService.get_config_value(['monkey', 'behaviour', 'custom_post_breach', 'linux_file_info']) - filename = secure_filename(request.files['filepond'].filename) - file_path = os.path.join(UPLOADS_DIR, filename) - request.files['filepond'].save(file_path) - file_size = os.path.getsize(file_path) - # config['monkey']['behaviour']['cutom_post_breach']['linux_file_info']['size'] = file_size - # config['monkey']['behaviour']['cutom_post_breach']['linux_file_info']['name'] = filename - # ConfigService.update_config(config, True) - - + filename = FileUpload.upload_pba_file(request) elif file_type == 'PBAwindows': - request.files['filepond'].save("./useless.file") + filename = FileUpload.upload_pba_file(request, False) + + response = Response( + response=filename, + status=200, mimetype='text/plain') + return response + + def delete(self, file_type): + config = ConfigService.get_config(should_decrypt=False) + if file_type == 'PBAlinux': + file_info = 'linux_file_info' + else: + file_info = 'windows_file_info' + filename = config['monkey']['behaviour']['custom_post_breach'][file_info]['name'] + file_path = os.path.join(UPLOADS_DIR, filename) + try: + if os.path.exists(file_path): + os.remove(file_path) + except OSError as e: + LOG.error("Can't remove previously uploaded post breach files: %s" % e) + return {} + + @staticmethod + def upload_pba_file(request_, is_linux=True): + config = ConfigService.get_config(should_decrypt=False) + filename = secure_filename(request_.files['filepond'].filename) + file_path = os.path.join(UPLOADS_DIR, filename) + request_.files['filepond'].save(file_path) + file_size = os.path.getsize(file_path) + if is_linux: + file_info = 'linux_file_info' + else: + file_info = 'windows_file_info' + config['monkey']['behaviour']['custom_post_breach'][file_info]['size'] = file_size + config['monkey']['behaviour']['custom_post_breach'][file_info]['name'] = filename + ConfigService.update_config(config, should_encrypt=False) + return filename diff --git a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js index 23efa5cd2..5008ef1eb 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -153,6 +153,9 @@ class ConfigurePageComponent extends AuthComponent { }; PBAwindows = () => { + if (! this.state.configuration.monkey.behaviour.custom_post_breach.windows_file_info){ + + } return () };