forked from p15670423/monkey
Common: Rename OperatingSystems -> OperatingSystem
By convention, Enum names are singular.
This commit is contained in:
parent
9fb0532646
commit
0e78129515
|
@ -2,4 +2,4 @@
|
|||
Used for a common things between agent and island
|
||||
"""
|
||||
from .di_container import DIContainer, UnresolvableDependencyError
|
||||
from .operating_systems import OperatingSystems
|
||||
from .operating_system import OperatingSystem
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class OperatingSystems(Enum):
|
||||
class OperatingSystem(Enum):
|
||||
"""
|
||||
An Enum representing all supported operating systems
|
||||
|
|
@ -5,7 +5,7 @@ from typing import Mapping
|
|||
|
||||
import requests
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from common.common_consts.timeouts import MEDIUM_REQUEST_TIMEOUT
|
||||
|
||||
from . import IAgentRepository
|
||||
|
@ -24,7 +24,7 @@ class CachingAgentRepository(IAgentRepository):
|
|||
self._lock = threading.Lock()
|
||||
|
||||
def get_agent_binary(
|
||||
self, operating_system: OperatingSystems, architecture: str = None
|
||||
self, operating_system: OperatingSystem, architecture: str = None
|
||||
) -> io.BytesIO:
|
||||
# If multiple calls to get_agent_binary() are made simultaneously before the result of
|
||||
# _download_binary_from_island() is cached, then multiple requests will be sent to the
|
||||
|
@ -34,7 +34,7 @@ class CachingAgentRepository(IAgentRepository):
|
|||
return io.BytesIO(self._download_binary_from_island(operating_system))
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def _download_binary_from_island(self, operating_system: OperatingSystems) -> bytes:
|
||||
def _download_binary_from_island(self, operating_system: OperatingSystem) -> bytes:
|
||||
os_name = operating_system.value
|
||||
|
||||
response = requests.get( # noqa: DUO123
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import abc
|
||||
import io
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
|
||||
# TODO: The Island also has an IAgentRepository with a totally different interface. At the moment,
|
||||
# the Island and Agent have different needs, but at some point we should unify these.
|
||||
|
@ -16,7 +16,7 @@ class IAgentRepository(metaclass=abc.ABCMeta):
|
|||
|
||||
@abc.abstractmethod
|
||||
def get_agent_binary(
|
||||
self, operating_system: OperatingSystems, architecture: str = None
|
||||
self, operating_system: OperatingSystem, architecture: str = None
|
||||
) -> io.BytesIO:
|
||||
"""
|
||||
Retrieve the appropriate agent binary from the repository.
|
||||
|
|
|
@ -2,7 +2,7 @@ import logging
|
|||
import time
|
||||
from pathlib import PurePath
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT, MEDIUM_REQUEST_TIMEOUT
|
||||
from common.utils import Timer
|
||||
from infection_monkey.exploit.log4shell_utils import (
|
||||
|
@ -129,7 +129,7 @@ class Log4ShellExploiter(WebRCE):
|
|||
}
|
||||
|
||||
def _build_java_class(self, exploit_command: str) -> bytes:
|
||||
if OperatingSystems.LINUX == self.host.os["type"]:
|
||||
if OperatingSystem.LINUX == self.host.os["type"]:
|
||||
return build_exploit_bytecode(exploit_command, LINUX_EXPLOIT_TEMPLATE_PATH)
|
||||
else:
|
||||
return build_exploit_bytecode(exploit_command, WINDOWS_EXPLOIT_TEMPLATE_PATH)
|
||||
|
|
|
@ -2,7 +2,7 @@ import logging
|
|||
from pathlib import Path, PurePath
|
||||
from typing import List, Optional
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from infection_monkey.exploit.HostExploiter import HostExploiter
|
||||
from infection_monkey.exploit.powershell_utils.auth_options import AuthOptions, get_auth_options
|
||||
from infection_monkey.exploit.powershell_utils.credentials import (
|
||||
|
@ -163,7 +163,7 @@ class PowerShellExploiter(HostExploiter):
|
|||
temp_monkey_binary_filepath.unlink()
|
||||
|
||||
def _create_local_agent_file(self, binary_path):
|
||||
agent_binary_bytes = self.agent_repository.get_agent_binary(OperatingSystems.WINDOWS)
|
||||
agent_binary_bytes = self.agent_repository.get_agent_binary(OperatingSystem.WINDOWS)
|
||||
with open(binary_path, "wb") as f:
|
||||
f.write(agent_binary_bytes.getvalue())
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from abc import abstractmethod
|
|||
from posixpath import join
|
||||
from typing import List, Tuple
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from common.utils.attack_utils import BITS_UPLOAD_STRING, ScanStatus
|
||||
from infection_monkey.exploit.HostExploiter import HostExploiter
|
||||
from infection_monkey.exploit.tools.http_tools import HTTPTools
|
||||
|
@ -412,14 +412,14 @@ class WebRCE(HostExploiter):
|
|||
:return: Default monkey's destination path for corresponding host or False if failed.
|
||||
"""
|
||||
if not self.host.os.get("type") or (
|
||||
self.host.os["type"] != OperatingSystems.LINUX
|
||||
and self.host.os["type"] != OperatingSystems.WINDOWS
|
||||
self.host.os["type"] != OperatingSystem.LINUX
|
||||
and self.host.os["type"] != OperatingSystem.WINDOWS
|
||||
):
|
||||
logger.error("Target's OS was either unidentified or not supported. Aborting")
|
||||
return False
|
||||
if self.host.os["type"] == OperatingSystems.LINUX:
|
||||
if self.host.os["type"] == OperatingSystem.LINUX:
|
||||
return DROPPER_TARGET_PATH_LINUX
|
||||
if self.host.os["type"] == OperatingSystems.WINDOWS:
|
||||
if self.host.os["type"] == OperatingSystem.WINDOWS:
|
||||
return DROPPER_TARGET_PATH_WIN64
|
||||
|
||||
def get_target_url(self):
|
||||
|
|
|
@ -7,7 +7,7 @@ from queue import Queue
|
|||
from threading import Event
|
||||
from typing import Callable, Dict, Sequence
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from common.agent_configuration.agent_sub_configurations import (
|
||||
ExploitationConfiguration,
|
||||
PluginConfiguration,
|
||||
|
@ -26,14 +26,14 @@ Callback = Callable[[ExploiterName, VictimHost, ExploiterResultData], None]
|
|||
|
||||
|
||||
SUPPORTED_OS = {
|
||||
"HadoopExploiter": [OperatingSystems.LINUX, OperatingSystems.WINDOWS],
|
||||
"Log4ShellExploiter": [OperatingSystems.LINUX, OperatingSystems.WINDOWS],
|
||||
"MSSQLExploiter": [OperatingSystems.WINDOWS],
|
||||
"PowerShellExploiter": [OperatingSystems.WINDOWS],
|
||||
"SSHExploiter": [OperatingSystems.LINUX],
|
||||
"SmbExploiter": [OperatingSystems.WINDOWS],
|
||||
"WmiExploiter": [OperatingSystems.WINDOWS],
|
||||
"ZerologonExploiter": [OperatingSystems.WINDOWS],
|
||||
"HadoopExploiter": [OperatingSystem.LINUX, OperatingSystem.WINDOWS],
|
||||
"Log4ShellExploiter": [OperatingSystem.LINUX, OperatingSystem.WINDOWS],
|
||||
"MSSQLExploiter": [OperatingSystem.WINDOWS],
|
||||
"PowerShellExploiter": [OperatingSystem.WINDOWS],
|
||||
"SSHExploiter": [OperatingSystem.LINUX],
|
||||
"SmbExploiter": [OperatingSystem.WINDOWS],
|
||||
"WmiExploiter": [OperatingSystem.WINDOWS],
|
||||
"ZerologonExploiter": [OperatingSystem.WINDOWS],
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Optional
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
|
||||
|
||||
class VictimHost(object):
|
||||
|
@ -17,7 +17,7 @@ class VictimHost(object):
|
|||
return self.__dict__
|
||||
|
||||
def is_windows(self) -> bool:
|
||||
return OperatingSystems.WINDOWS == self.os["type"]
|
||||
return OperatingSystem.WINDOWS == self.os["type"]
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.ip_addr)
|
||||
|
|
|
@ -5,7 +5,7 @@ import re
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from infection_monkey.i_puppet import PingScanData
|
||||
from infection_monkey.utils.environment import is_windows_os
|
||||
|
||||
|
@ -80,9 +80,9 @@ def _process_ping_command_output(ping_command_output: str) -> PingScanData:
|
|||
|
||||
operating_system = None
|
||||
if ttl <= LINUX_TTL:
|
||||
operating_system = OperatingSystems.LINUX
|
||||
operating_system = OperatingSystem.LINUX
|
||||
else: # as far we we know, could also be OSX/BSD, but lets handle that when it comes up.
|
||||
operating_system = OperatingSystems.WINDOWS
|
||||
operating_system = OperatingSystem.WINDOWS
|
||||
|
||||
return PingScanData(True, operating_system)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Dict
|
|||
|
||||
from odict import odict
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from infection_monkey.i_puppet import (
|
||||
FingerprintData,
|
||||
IFingerprinter,
|
||||
|
@ -194,9 +194,9 @@ class SMBFingerprinter(IFingerprinter):
|
|||
logger.debug(f'os_version: "{os_version}", service_client: "{service_client}"')
|
||||
|
||||
if os_version.lower() != "unix":
|
||||
os_type = OperatingSystems.WINDOWS
|
||||
os_type = OperatingSystem.WINDOWS
|
||||
else:
|
||||
os_type = OperatingSystems.LINUX
|
||||
os_type = OperatingSystem.LINUX
|
||||
|
||||
smb_service["name"] = service_client
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
from typing import Dict, Optional, Tuple
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from infection_monkey.i_puppet import FingerprintData, IFingerprinter, PingScanData, PortScanData
|
||||
|
||||
SSH_REGEX = r"SSH-\d\.\d-OpenSSH"
|
||||
|
@ -41,6 +41,6 @@ class SSHFingerprinter(IFingerprinter):
|
|||
for dist in LINUX_DIST_SSH:
|
||||
if banner.lower().find(dist) != -1:
|
||||
os_version = banner.split(" ").pop().strip()
|
||||
os = OperatingSystems.LINUX
|
||||
os = OperatingSystem.LINUX
|
||||
|
||||
return os, os_version
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import json
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
|
||||
|
||||
class TelemetryJSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, OperatingSystems):
|
||||
if isinstance(obj, OperatingSystem):
|
||||
return obj.name
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Optional, Sequence
|
|||
|
||||
from pydantic import Field, PositiveInt, validator
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
|
||||
from .base_models import MutableBaseModel
|
||||
from .transforms import make_immutable_sequence
|
||||
|
@ -15,7 +15,7 @@ class Machine(MutableBaseModel):
|
|||
id: MachineID = Field(..., allow_mutation=False)
|
||||
hardware_id: Optional[PositiveInt]
|
||||
network_interfaces: Sequence[IPv4Interface]
|
||||
operating_system: OperatingSystems
|
||||
operating_system: OperatingSystem
|
||||
operating_system_version: str
|
||||
hostname: str
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from unittest.mock import Mock
|
|||
|
||||
import pytest
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from infection_monkey.exploit.tools.helpers import (
|
||||
AGENT_BINARY_PATH_LINUX,
|
||||
AGENT_BINARY_PATH_WIN64,
|
||||
|
@ -14,15 +14,15 @@ from infection_monkey.exploit.tools.helpers import (
|
|||
def _get_host(os):
|
||||
host = Mock()
|
||||
host.os = {"type": os}
|
||||
host.is_windows = lambda: os == OperatingSystems.WINDOWS
|
||||
host.is_windows = lambda: os == OperatingSystem.WINDOWS
|
||||
return host
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"os, path",
|
||||
[
|
||||
(OperatingSystems.LINUX, AGENT_BINARY_PATH_LINUX),
|
||||
(OperatingSystems.WINDOWS, AGENT_BINARY_PATH_WIN64),
|
||||
(OperatingSystem.LINUX, AGENT_BINARY_PATH_LINUX),
|
||||
(OperatingSystem.WINDOWS, AGENT_BINARY_PATH_WIN64),
|
||||
],
|
||||
)
|
||||
def test_get_agent_dst_path(os, path):
|
||||
|
@ -35,7 +35,7 @@ def test_get_agent_dst_path(os, path):
|
|||
|
||||
|
||||
def test_get_agent_dst_path_randomness():
|
||||
host = _get_host(OperatingSystems.WINDOWS)
|
||||
host = _get_host(OperatingSystem.WINDOWS)
|
||||
|
||||
path1 = get_agent_dst_path(host)
|
||||
path2 = get_agent_dst_path(host)
|
||||
|
@ -44,7 +44,7 @@ def test_get_agent_dst_path_randomness():
|
|||
|
||||
|
||||
def test_get_agent_dst_path_str_place():
|
||||
host = _get_host(OperatingSystems.WINDOWS)
|
||||
host = _get_host(OperatingSystem.WINDOWS)
|
||||
|
||||
rand_path = get_agent_dst_path(host)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import logging
|
|||
import threading
|
||||
from typing import Dict, Iterable, List, Sequence
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from common.credentials import Credentials, LMHash, Password, SSHKeypair, Username
|
||||
from infection_monkey.i_puppet import (
|
||||
ExploiterResultData,
|
||||
|
@ -186,19 +186,19 @@ class MockPuppet(IPuppet):
|
|||
successful_exploiters = {
|
||||
DOT_1: {
|
||||
"ZerologonExploiter": ExploiterResultData(
|
||||
False, False, False, OperatingSystems.WINDOWS, {}, [], "Zerologon failed"
|
||||
False, False, False, OperatingSystem.WINDOWS, {}, [], "Zerologon failed"
|
||||
),
|
||||
"SSHExploiter": ExploiterResultData(
|
||||
False,
|
||||
False,
|
||||
False,
|
||||
OperatingSystems.LINUX,
|
||||
OperatingSystem.LINUX,
|
||||
info_ssh,
|
||||
attempts,
|
||||
"Failed exploiting",
|
||||
),
|
||||
"WmiExploiter": ExploiterResultData(
|
||||
True, True, False, OperatingSystems.WINDOWS, info_wmi, attempts, None
|
||||
True, True, False, OperatingSystem.WINDOWS, info_wmi, attempts, None
|
||||
),
|
||||
},
|
||||
DOT_3: {
|
||||
|
@ -206,7 +206,7 @@ class MockPuppet(IPuppet):
|
|||
False,
|
||||
False,
|
||||
False,
|
||||
OperatingSystems.WINDOWS,
|
||||
OperatingSystem.WINDOWS,
|
||||
info_wmi,
|
||||
attempts,
|
||||
"PowerShell Exploiter Failed",
|
||||
|
@ -215,13 +215,13 @@ class MockPuppet(IPuppet):
|
|||
False,
|
||||
False,
|
||||
False,
|
||||
OperatingSystems.LINUX,
|
||||
OperatingSystem.LINUX,
|
||||
info_ssh,
|
||||
attempts,
|
||||
"Failed exploiting",
|
||||
),
|
||||
"ZerologonExploiter": ExploiterResultData(
|
||||
True, False, False, OperatingSystems.WINDOWS, {}, [], None
|
||||
True, False, False, OperatingSystem.WINDOWS, {}, [], None
|
||||
),
|
||||
},
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ class MockPuppet(IPuppet):
|
|||
False,
|
||||
False,
|
||||
False,
|
||||
OperatingSystems.LINUX,
|
||||
OperatingSystem.LINUX,
|
||||
{},
|
||||
[],
|
||||
f"{name} failed for host {host}",
|
||||
|
|
|
@ -7,7 +7,7 @@ from unittest.mock import MagicMock
|
|||
import pytest
|
||||
from tests.unit_tests.infection_monkey.master.mock_puppet import MockPuppet
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from common.agent_configuration.agent_sub_configurations import (
|
||||
ExploitationConfiguration,
|
||||
PluginConfiguration,
|
||||
|
@ -165,7 +165,7 @@ def test_exploiter_raises_exception(callback, hosts, hosts_to_exploit, run_explo
|
|||
|
||||
def test_windows_exploiters_run_on_windows_host(callback, hosts, hosts_to_exploit, run_exploiters):
|
||||
host = VictimHost("10.0.0.1")
|
||||
host.os["type"] = OperatingSystems.WINDOWS
|
||||
host.os["type"] = OperatingSystem.WINDOWS
|
||||
q = enqueue_hosts([host])
|
||||
run_exploiters(MockPuppet(), 1, q)
|
||||
|
||||
|
@ -177,7 +177,7 @@ def test_windows_exploiters_run_on_windows_host(callback, hosts, hosts_to_exploi
|
|||
|
||||
def test_linux_exploiters_run_on_linux_host(callback, hosts, hosts_to_exploit, run_exploiters):
|
||||
host = VictimHost("10.0.0.1")
|
||||
host.os["type"] = OperatingSystems.LINUX
|
||||
host.os["type"] = OperatingSystem.LINUX
|
||||
q = enqueue_hosts([host])
|
||||
run_exploiters(MockPuppet(), 1, q)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from unittest.mock import MagicMock
|
|||
|
||||
import pytest
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from infection_monkey.network_scanning import ping
|
||||
from infection_monkey.network_scanning.ping_scanner import EMPTY_PING_SCAN
|
||||
|
||||
|
@ -92,7 +92,7 @@ def test_linux_ping_success(patch_subprocess_running_ping_with_ping_output):
|
|||
result = ping("192.168.1.1", 1.0)
|
||||
|
||||
assert result.response_received
|
||||
assert result.os == OperatingSystems.LINUX
|
||||
assert result.os == OperatingSystem.LINUX
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("set_os_linux")
|
||||
|
@ -110,7 +110,7 @@ def test_windows_ping_success(patch_subprocess_running_ping_with_ping_output):
|
|||
result = ping("192.168.1.1", 1.0)
|
||||
|
||||
assert result.response_received
|
||||
assert result.os == OperatingSystems.WINDOWS
|
||||
assert result.os == OperatingSystem.WINDOWS
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("set_os_windows")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from infection_monkey.i_puppet import FingerprintData, PortScanData, PortStatus
|
||||
from infection_monkey.network_scanning.ssh_fingerprinter import SSHFingerprinter
|
||||
|
||||
|
@ -57,7 +57,7 @@ def test_ssh_os(ssh_fingerprinter):
|
|||
results = ssh_fingerprinter.get_host_fingerprint("127.0.0.1", None, port_scan_data, None)
|
||||
|
||||
assert results == FingerprintData(
|
||||
OperatingSystems.LINUX,
|
||||
OperatingSystem.LINUX,
|
||||
"Ubuntu-4ubuntu0.2",
|
||||
{
|
||||
"tcp-22": {
|
||||
|
@ -79,7 +79,7 @@ def test_multiple_os(ssh_fingerprinter):
|
|||
results = ssh_fingerprinter.get_host_fingerprint("127.0.0.1", None, port_scan_data, None)
|
||||
|
||||
assert results == FingerprintData(
|
||||
OperatingSystems.LINUX,
|
||||
OperatingSystem.LINUX,
|
||||
"Debian",
|
||||
{
|
||||
"tcp-22": {
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import MutableSequence
|
|||
|
||||
import pytest
|
||||
|
||||
from common import OperatingSystems
|
||||
from common import OperatingSystem
|
||||
from monkey_island.cc.models import Machine
|
||||
|
||||
MACHINE_OBJECT_DICT = MappingProxyType(
|
||||
|
@ -13,7 +13,7 @@ MACHINE_OBJECT_DICT = MappingProxyType(
|
|||
"id": 1,
|
||||
"hardware_id": uuid.getnode(),
|
||||
"network_interfaces": [IPv4Interface("10.0.0.1/24"), IPv4Interface("192.168.5.32/16")],
|
||||
"operating_system": OperatingSystems.WINDOWS,
|
||||
"operating_system": OperatingSystem.WINDOWS,
|
||||
"operating_system_version": "eXtra Problems",
|
||||
"hostname": "my.host",
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ def test_operating_system_set_valid_value():
|
|||
m = Machine(**MACHINE_OBJECT_DICT)
|
||||
|
||||
# Raises exception_on_failure
|
||||
m.operating_system = OperatingSystems.LINUX
|
||||
m.operating_system = OperatingSystem.LINUX
|
||||
|
||||
|
||||
def test_operating_system_set_invalid_value():
|
||||
|
|
Loading…
Reference in New Issue