diff --git a/monkey/infection_monkey/exploit/powershell.py b/monkey/infection_monkey/exploit/powershell.py index 9d4b32e6b..6d6520080 100644 --- a/monkey/infection_monkey/exploit/powershell.py +++ b/monkey/infection_monkey/exploit/powershell.py @@ -6,7 +6,6 @@ import infection_monkey.monkeyfs as monkeyfs from common.utils.exploit_enum import ExploitType from infection_monkey.exploit.consts import WIN_ARCH_32 from infection_monkey.exploit.HostExploiter import HostExploiter -from infection_monkey.exploit.powershell_utils import utils from infection_monkey.exploit.powershell_utils.auth_options import ( AUTH_NEGOTIATE, ENCRYPTION_AUTO, @@ -24,7 +23,8 @@ from infection_monkey.exploit.powershell_utils.powershell_client import ( PowerShellClient, ) from infection_monkey.exploit.tools.helpers import get_monkey_depth, get_target_monkey_by_os -from infection_monkey.model import VictimHost +from infection_monkey.model import DROPPER_ARG, RUN_MONKEY, VictimHost +from infection_monkey.utils.commands import build_monkey_commandline from infection_monkey.utils.environment import is_windows_os logger = logging.getLogger(__name__) @@ -186,7 +186,7 @@ class PowerShellExploiter(HostExploiter): monkey_local_file.write(monkey_virtual_file.read()) def _run_monkey_executable_on_victim(self, executable_path) -> None: - monkey_execution_command = utils.build_monkey_execution_command( + monkey_execution_command = build_monkey_execution_command( self.host, get_monkey_depth() - 1, executable_path ) @@ -195,3 +195,18 @@ class PowerShellExploiter(HostExploiter): ) self._client.execute_cmd_as_detached_process(monkey_execution_command) + + +def build_monkey_execution_command(host: VictimHost, depth: int, executable_path: str) -> str: + monkey_params = build_monkey_commandline( + target_host=host, + depth=depth, + vulnerable_port=None, + location=executable_path, + ) + + return RUN_MONKEY % { + "monkey_path": executable_path, + "monkey_type": DROPPER_ARG, + "parameters": monkey_params, + } diff --git a/monkey/infection_monkey/exploit/powershell_utils/utils.py b/monkey/infection_monkey/exploit/powershell_utils/utils.py deleted file mode 100644 index 4c0ab3dce..000000000 --- a/monkey/infection_monkey/exploit/powershell_utils/utils.py +++ /dev/null @@ -1,17 +0,0 @@ -from infection_monkey.model import DROPPER_ARG, RUN_MONKEY, VictimHost -from infection_monkey.utils.commands import build_monkey_commandline - - -def build_monkey_execution_command(host: VictimHost, depth: int, executable_path: str) -> str: - monkey_params = build_monkey_commandline( - target_host=host, - depth=depth, - vulnerable_port=None, - location=executable_path, - ) - - return RUN_MONKEY % { - "monkey_path": executable_path, - "monkey_type": DROPPER_ARG, - "parameters": monkey_params, - } diff --git a/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_utils.py b/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_utils.py deleted file mode 100644 index de5ca3b5d..000000000 --- a/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_utils.py +++ /dev/null @@ -1,13 +0,0 @@ -from infection_monkey.exploit.powershell_utils import utils -from infection_monkey.model.host import VictimHost - - -def test_build_monkey_execution_command(): - host = VictimHost("127.0.0.1") - depth = 2 - executable_path = "/tmp/test-monkey" - - cmd = utils.build_monkey_execution_command(host, depth, executable_path) - - assert f"-d {depth}" in cmd - assert executable_path in cmd diff --git a/monkey/tests/unit_tests/infection_monkey/exploit/test_powershell.py b/monkey/tests/unit_tests/infection_monkey/exploit/test_powershell.py index 4e5c98823..b9254c1d8 100644 --- a/monkey/tests/unit_tests/infection_monkey/exploit/test_powershell.py +++ b/monkey/tests/unit_tests/infection_monkey/exploit/test_powershell.py @@ -216,3 +216,14 @@ def test_login_attemps_correctly_reported(monkeypatch, powershell_exploiter): "ntlm_hash": NT_HASH_LIST[1], "ssh_key": "", } in powershell_exploiter.exploit_attempts + + +def test_build_monkey_execution_command(): + host = VictimHost("127.0.0.1") + depth = 2 + executable_path = "/tmp/test-monkey" + + cmd = powershell.build_monkey_execution_command(host, depth, executable_path) + + assert f"-d {depth}" in cmd + assert executable_path in cmd