forked from p15670423/monkey
Agent: Make agent target paths a Path objects
This commit is contained in:
parent
e4a2a54c71
commit
09958c21c6
|
@ -20,8 +20,11 @@ from infection_monkey.utils.file_utils import mark_file_for_deletion_on_windows
|
|||
|
||||
if "win32" == sys.platform:
|
||||
from win32process import DETACHED_PROCESS
|
||||
|
||||
DATE_REFERENCE_PATH_WINDOWS = os.path.expandvars(WindowsPath(r"%windir%\system32\kernel32.dll"))
|
||||
else:
|
||||
DETACHED_PROCESS = 0
|
||||
DATE_REFERENCE_PATH_LINUX = PosixPath("/bin/sh")
|
||||
|
||||
# Linux doesn't have WindowsError
|
||||
try:
|
||||
|
@ -34,8 +37,6 @@ except NameError:
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
MOVEFILE_DELAY_UNTIL_REBOOT = 4
|
||||
DATE_REFERENCE_PATH_WINDOWS = WindowsPath(r"%windir%\system32\kernel32.dll")
|
||||
DATE_REFERENCE_PATH_LINUX = PosixPath("/bin/sh")
|
||||
|
||||
|
||||
class MonkeyDrops(object):
|
||||
|
@ -112,7 +113,7 @@ class MonkeyDrops(object):
|
|||
return False
|
||||
|
||||
if sys.platform == "win32":
|
||||
dropper_date_reference_path = os.path.expandvars(DATE_REFERENCE_PATH_WINDOWS)
|
||||
dropper_date_reference_path = DATE_REFERENCE_PATH_WINDOWS
|
||||
else:
|
||||
dropper_date_reference_path = DATE_REFERENCE_PATH_LINUX
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ logger = logging.getLogger(__name__)
|
|||
RAND_SUFFIX_LEN = 8
|
||||
|
||||
# Where to upload agent binaries on victims
|
||||
AGENT_BINARY_PATH_LINUX = "/tmp/monkey"
|
||||
AGENT_BINARY_PATH_WIN64 = r"C:\Windows\temp\monkey64.exe"
|
||||
AGENT_BINARY_PATH_LINUX = PurePosixPath("/tmp/monkey")
|
||||
AGENT_BINARY_PATH_WIN64 = PureWindowsPath(r"C:\Windows\temp\monkey64.exe")
|
||||
|
||||
|
||||
def get_agent_dst_path(host: VictimHost) -> PurePath:
|
||||
|
|
|
@ -5,7 +5,7 @@ from unittest.mock import MagicMock
|
|||
import pytest
|
||||
|
||||
from infection_monkey.exploit import powershell
|
||||
from infection_monkey.exploit.tools.helpers import AGENT_BINARY_PATH_WIN64, RAND_SUFFIX_LEN
|
||||
from infection_monkey.exploit.tools.helpers import AGENT_BINARY_PATH_WIN64
|
||||
from infection_monkey.model.host import VictimHost
|
||||
|
||||
# Use the path_win32api_get_user_name fixture for all tests in this module
|
||||
|
@ -113,10 +113,7 @@ def test_successful_copy(monkeypatch, powershell_exploiter, powershell_arguments
|
|||
|
||||
exploit_result = powershell_exploiter.exploit_host(**powershell_arguments)
|
||||
|
||||
# Check if the copied agent name has randomness of 8 plus dash
|
||||
assert len(str(AGENT_BINARY_PATH_WIN64)) + RAND_SUFFIX_LEN + 1 == len(
|
||||
str(mock_client.return_value.copy_file.call_args[0][1])
|
||||
)
|
||||
assert AGENT_BINARY_PATH_WIN64.stem in str(mock_client.return_value.copy_file.call_args[0][1])
|
||||
assert exploit_result.exploitation_success
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue