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,6 +14,8 @@ 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"]
|
||||||
|
|
||||||
|
|
||||||
|
class PostBreachFilesService:
|
||||||
|
@staticmethod
|
||||||
def remove_PBA_files():
|
def remove_PBA_files():
|
||||||
if monkey_island.cc.services.config.ConfigService.get_config():
|
if monkey_island.cc.services.config.ConfigService.get_config():
|
||||||
windows_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
windows_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
||||||
|
@ -23,12 +25,12 @@ def remove_PBA_files():
|
||||||
PBA_LINUX_FILENAME_PATH
|
PBA_LINUX_FILENAME_PATH
|
||||||
)
|
)
|
||||||
if linux_filename:
|
if linux_filename:
|
||||||
remove_file(linux_filename)
|
PostBreachFilesService._remove_file(linux_filename)
|
||||||
if windows_filename:
|
if windows_filename:
|
||||||
remove_file(windows_filename)
|
PostBreachFilesService._remove_file(windows_filename)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def remove_file(file_name):
|
def _remove_file(file_name):
|
||||||
file_path = os.path.join(env_singleton.env.get_config().data_dir_abs_path, file_name)
|
file_path = os.path.join(env_singleton.env.get_config().data_dir_abs_path, file_name)
|
||||||
try:
|
try:
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
|
@ -36,7 +38,7 @@ def remove_file(file_name):
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
logger.error("Can't remove previously uploaded post breach files: %s" % e)
|
logger.error("Can't remove previously uploaded post breach files: %s" % e)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def set_config_PBA_files(config_json):
|
def set_config_PBA_files(config_json):
|
||||||
"""
|
"""
|
||||||
Sets PBA file info in config_json to current config's PBA file info values.
|
Sets PBA file info in config_json to current config's PBA file info values.
|
||||||
|
|
Loading…
Reference in New Issue