forked from p15670423/monkey
cc: Upload custom PBAs to data_dir instead of MONKEY_ISLAND_ABS_PATH
This commit is contained in:
parent
a58f310e61
commit
3b4bd7b08c
|
@ -1,7 +1,7 @@
|
|||
import flask_restful
|
||||
from flask import send_from_directory
|
||||
|
||||
from monkey_island.cc.services.post_breach_files import ABS_UPLOAD_PATH
|
||||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||
|
||||
__author__ = "VakarisZ"
|
||||
|
||||
|
@ -13,4 +13,4 @@ class PBAFileDownload(flask_restful.Resource):
|
|||
|
||||
# Used by monkey. can't secure.
|
||||
def get(self, path):
|
||||
return send_from_directory(ABS_UPLOAD_PATH, path)
|
||||
return send_from_directory(env_singleton.env.get_config().data_dir_abs_path, path)
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import copy
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import flask_restful
|
||||
from flask import Response, request, send_from_directory
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.services.config import ConfigService
|
||||
from monkey_island.cc.services.post_breach_files import (
|
||||
ABS_UPLOAD_PATH,
|
||||
PBA_LINUX_FILENAME_PATH,
|
||||
PBA_WINDOWS_FILENAME_PATH,
|
||||
)
|
||||
|
@ -29,7 +30,7 @@ class FileUpload(flask_restful.Resource):
|
|||
|
||||
def __init__(self):
|
||||
# Create all directories on the way if they don't exist
|
||||
ABS_UPLOAD_PATH.mkdir(parents=True, exist_ok=True)
|
||||
Path(env_singleton.env.get_config().data_dir_abs_path).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@jwt_required
|
||||
def get(self, file_type):
|
||||
|
@ -43,7 +44,7 @@ class FileUpload(flask_restful.Resource):
|
|||
filename = ConfigService.get_config_value(copy.deepcopy(PBA_LINUX_FILENAME_PATH))
|
||||
else:
|
||||
filename = ConfigService.get_config_value(copy.deepcopy(PBA_WINDOWS_FILENAME_PATH))
|
||||
return send_from_directory(ABS_UPLOAD_PATH, filename)
|
||||
return send_from_directory(env_singleton.env.get_config().data_dir_abs_path, filename)
|
||||
|
||||
@jwt_required
|
||||
def post(self, file_type):
|
||||
|
@ -68,7 +69,7 @@ class FileUpload(flask_restful.Resource):
|
|||
PBA_LINUX_FILENAME_PATH if file_type == "PBAlinux" else PBA_WINDOWS_FILENAME_PATH
|
||||
)
|
||||
filename = ConfigService.get_config_value(filename_path)
|
||||
file_path = ABS_UPLOAD_PATH.joinpath(filename)
|
||||
file_path = Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename)
|
||||
try:
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
|
@ -87,7 +88,9 @@ class FileUpload(flask_restful.Resource):
|
|||
:return: filename string
|
||||
"""
|
||||
filename = secure_filename(request_.files["filepond"].filename)
|
||||
file_path = ABS_UPLOAD_PATH.joinpath(filename).absolute()
|
||||
file_path = (
|
||||
Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename).absolute()
|
||||
)
|
||||
request_.files["filepond"].save(str(file_path))
|
||||
ConfigService.set_config_value(
|
||||
(PBA_LINUX_FILENAME_PATH if is_linux else PBA_WINDOWS_FILENAME_PATH), filename
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import monkey_island.cc.services.config
|
||||
|
||||
__author__ = "VakarisZ"
|
||||
|
||||
from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH
|
||||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -15,8 +14,6 @@ PBA_WINDOWS_FILENAME_PATH = ["monkey", "post_breach", "PBA_windows_filename"]
|
|||
PBA_LINUX_FILENAME_PATH = ["monkey", "post_breach", "PBA_linux_filename"]
|
||||
UPLOADS_DIR_NAME = "userUploads"
|
||||
|
||||
ABS_UPLOAD_PATH = Path(MONKEY_ISLAND_ABS_PATH, "cc", UPLOADS_DIR_NAME)
|
||||
|
||||
|
||||
def remove_PBA_files():
|
||||
if monkey_island.cc.services.config.ConfigService.get_config():
|
||||
|
@ -33,7 +30,7 @@ def remove_PBA_files():
|
|||
|
||||
|
||||
def remove_file(file_name):
|
||||
file_path = os.path.join(ABS_UPLOAD_PATH, file_name)
|
||||
file_path = os.path.join(env_singleton.env.get_config().data_dir_abs_path, file_name)
|
||||
try:
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
|
|
Loading…
Reference in New Issue