Added deletion of files

This commit is contained in:
VakarisZ 2019-02-25 19:18:10 +02:00
parent a51d7da1f9
commit 7281f2284b
3 changed files with 50 additions and 14 deletions

View File

@ -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/<string:path>')
api.add_resource(FileUpload, '/api/fileUpload/<string:file_type>')
api.add_resource(FileUpload, '/api/fileUpload/<string:file_type>',
'/api/fileUpload/<string:file_type>?load=<string:file_name>')
api.add_resource(RemoteRun, '/api/remote-monkey', '/api/remote-monkey/')
return app

View File

@ -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

View File

@ -153,6 +153,9 @@ class ConfigurePageComponent extends AuthComponent {
};
PBAwindows = () => {
if (! this.state.configuration.monkey.behaviour.custom_post_breach.windows_file_info){
}
return (<FilePond server='/api/fileUpload/PBAwindows'/>)
};