diff --git a/monkey/infection_monkey/exploit/mssqlexec.py b/monkey/infection_monkey/exploit/mssqlexec.py index 6247f3779..f1fdcd460 100644 --- a/monkey/infection_monkey/exploit/mssqlexec.py +++ b/monkey/infection_monkey/exploit/mssqlexec.py @@ -9,7 +9,7 @@ from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT from common.utils.exceptions import ExploitingVulnerableMachineError, FailedExploitationError from common.utils.exploit_enum import ExploitType from infection_monkey.exploit.HostExploiter import HostExploiter -from infection_monkey.exploit.tools.helpers import get_monkey_dest_path, try_get_target_monkey +from infection_monkey.exploit.tools.helpers import get_agent_dest_path, try_get_target_monkey from infection_monkey.exploit.tools.http_tools import HTTPTools from infection_monkey.exploit.tools.payload_parsing import LimitedSizePayload from infection_monkey.i_puppet import ExploiterResultData @@ -139,9 +139,9 @@ class MSSQLExploiter(HostExploiter): self.run_mssql_command(tmp_dir_removal_command) def start_monkey_server(self) -> LockedHTTPServer: - monkey_src = try_get_target_monkey(self.host) + dst_path = get_agent_dest_path(self.host, self.options) self.agent_http_path, http_thread = HTTPTools.create_locked_transfer( - self.host, monkey_src, self.agent_repository + self.host, dst_path, self.agent_repository ) return http_thread @@ -156,7 +156,7 @@ class MSSQLExploiter(HostExploiter): return monkey_download_command def get_monkey_launch_command(self): - dst_path = get_monkey_dest_path(self.agent_http_path) + dst_path = get_agent_dest_path(self.host, self.options) # Form monkey's launch command monkey_args = build_monkey_commandline(self.host, self.current_depth - 1, dst_path) suffix = ">>{}".format(self.payload_file_path) @@ -168,7 +168,7 @@ class MSSQLExploiter(HostExploiter): ) def get_monkey_download_command(self): - dst_path = get_monkey_dest_path(self.agent_http_path) + dst_path = get_agent_dest_path(self.host, self.options) monkey_download_command = MSSQLExploiter.MONKEY_DOWNLOAD_COMMAND.format( http_path=self.agent_http_path, dst_path=dst_path ) diff --git a/monkey/infection_monkey/exploit/tools/helpers.py b/monkey/infection_monkey/exploit/tools/helpers.py index d0af82304..62cfda4da 100644 --- a/monkey/infection_monkey/exploit/tools/helpers.py +++ b/monkey/infection_monkey/exploit/tools/helpers.py @@ -1,4 +1,7 @@ import logging +from typing import Mapping, Any + +from infection_monkey.model import VictimHost logger = logging.getLogger(__name__) @@ -26,31 +29,8 @@ def get_monkey_depth(): return WormConfiguration.depth -def get_monkey_dest_path(url_to_monkey): - """ - Gets destination path from monkey's source url. - :param url_to_monkey: Hosted monkey's url. egz : http://localserver:9999/monkey/windows-64.exe - :return: Corresponding monkey path from configuration - """ - from infection_monkey.config import WormConfiguration - - if not url_to_monkey or ("linux" not in url_to_monkey and "windows" not in url_to_monkey): - logger.error("Can't get destination path because source path %s is invalid.", url_to_monkey) - return False - try: - if "linux" in url_to_monkey: - return WormConfiguration.dropper_target_path_linux - elif "windows-64" in url_to_monkey: - return WormConfiguration.dropper_target_path_win_64 - else: - logger.error( - "Could not figure out what type of monkey server was trying to upload, " - "thus destination path can not be chosen." - ) - return False - except AttributeError: - logger.error( - "Seems like monkey's source configuration property names changed. " - "Can not get destination path to upload monkey" - ) - return False +def get_agent_dest_path(host: VictimHost, options: Mapping[str, Any]) -> str: + if host.os["type"] == "windows": + return options["dropper_target_path_win_64"] + else: + return options["dropper_target_path_linux"]