forked from p15670423/monkey
island: Wrap services/post_breach_files.py functions in a static class
This commit is contained in:
parent
ba86ba0395
commit
a7f2e023b8
|
@ -6,10 +6,10 @@ import logging
|
||||||
from jsonschema import Draft4Validator, validators
|
from jsonschema import Draft4Validator, validators
|
||||||
|
|
||||||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||||
import monkey_island.cc.services.post_breach_files
|
|
||||||
from monkey_island.cc.database import mongo
|
from monkey_island.cc.database import mongo
|
||||||
from monkey_island.cc.server_utils.encryptor import get_encryptor
|
from monkey_island.cc.server_utils.encryptor import get_encryptor
|
||||||
from monkey_island.cc.services.config_schema.config_schema import SCHEMA
|
from monkey_island.cc.services.config_schema.config_schema import SCHEMA
|
||||||
|
from monkey_island.cc.services.post_breach_files import PostBreachFilesService
|
||||||
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
|
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
|
||||||
|
|
||||||
__author__ = "itay.mizeretz"
|
__author__ = "itay.mizeretz"
|
||||||
|
@ -191,7 +191,7 @@ class ConfigService:
|
||||||
# PBA file upload happens on pba_file_upload endpoint and corresponding config options
|
# PBA file upload happens on pba_file_upload endpoint and corresponding config options
|
||||||
# are set there
|
# are set there
|
||||||
config_json = ConfigService._filter_none_values(config_json)
|
config_json = ConfigService._filter_none_values(config_json)
|
||||||
monkey_island.cc.services.post_breach_files.set_config_PBA_files(config_json)
|
PostBreachFilesService.set_config_PBA_files(config_json)
|
||||||
if should_encrypt:
|
if should_encrypt:
|
||||||
try:
|
try:
|
||||||
ConfigService.encrypt_config(config_json)
|
ConfigService.encrypt_config(config_json)
|
||||||
|
@ -229,7 +229,7 @@ class ConfigService:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def reset_config():
|
def reset_config():
|
||||||
monkey_island.cc.services.post_breach_files.remove_PBA_files()
|
PostBreachFilesService.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)
|
||||||
|
|
|
@ -14,40 +14,42 @@ PBA_WINDOWS_FILENAME_PATH = ["monkey", "post_breach", "PBA_windows_filename"]
|
||||||
PBA_LINUX_FILENAME_PATH = ["monkey", "post_breach", "PBA_linux_filename"]
|
PBA_LINUX_FILENAME_PATH = ["monkey", "post_breach", "PBA_linux_filename"]
|
||||||
|
|
||||||
|
|
||||||
def remove_PBA_files():
|
class PostBreachFilesService:
|
||||||
if monkey_island.cc.services.config.ConfigService.get_config():
|
@staticmethod
|
||||||
windows_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
def remove_PBA_files():
|
||||||
PBA_WINDOWS_FILENAME_PATH
|
if monkey_island.cc.services.config.ConfigService.get_config():
|
||||||
)
|
windows_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
||||||
linux_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
PBA_WINDOWS_FILENAME_PATH
|
||||||
PBA_LINUX_FILENAME_PATH
|
)
|
||||||
)
|
linux_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
||||||
if linux_filename:
|
PBA_LINUX_FILENAME_PATH
|
||||||
remove_file(linux_filename)
|
)
|
||||||
if windows_filename:
|
if linux_filename:
|
||||||
remove_file(windows_filename)
|
PostBreachFilesService._remove_file(linux_filename)
|
||||||
|
if windows_filename:
|
||||||
|
PostBreachFilesService._remove_file(windows_filename)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _remove_file(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)
|
||||||
|
except OSError as e:
|
||||||
|
logger.error("Can't remove previously uploaded post breach files: %s" % e)
|
||||||
|
|
||||||
def remove_file(file_name):
|
@staticmethod
|
||||||
file_path = os.path.join(env_singleton.env.get_config().data_dir_abs_path, file_name)
|
def set_config_PBA_files(config_json):
|
||||||
try:
|
"""
|
||||||
if os.path.exists(file_path):
|
Sets PBA file info in config_json to current config's PBA file info values.
|
||||||
os.remove(file_path)
|
:param config_json: config_json that will be modified
|
||||||
except OSError as e:
|
"""
|
||||||
logger.error("Can't remove previously uploaded post breach files: %s" % e)
|
if monkey_island.cc.services.config.ConfigService.get_config():
|
||||||
|
linux_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
||||||
|
PBA_LINUX_FILENAME_PATH
|
||||||
def set_config_PBA_files(config_json):
|
)
|
||||||
"""
|
windows_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
||||||
Sets PBA file info in config_json to current config's PBA file info values.
|
PBA_WINDOWS_FILENAME_PATH
|
||||||
:param config_json: config_json that will be modified
|
)
|
||||||
"""
|
config_json["monkey"]["post_breach"]["PBA_linux_filename"] = linux_filename
|
||||||
if monkey_island.cc.services.config.ConfigService.get_config():
|
config_json["monkey"]["post_breach"]["PBA_windows_filename"] = windows_filename
|
||||||
linux_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
|
||||||
PBA_LINUX_FILENAME_PATH
|
|
||||||
)
|
|
||||||
windows_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
|
||||||
PBA_WINDOWS_FILENAME_PATH
|
|
||||||
)
|
|
||||||
config_json["monkey"]["post_breach"]["PBA_linux_filename"] = linux_filename
|
|
||||||
config_json["monkey"]["post_breach"]["PBA_windows_filename"] = windows_filename
|
|
||||||
|
|
Loading…
Reference in New Issue