From a323441ffe391b9fba2a6a13d70941b1913f694a Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 20 Sep 2022 15:09:43 -0400 Subject: [PATCH] Island: Add Machine.island field --- monkey/monkey_island/cc/models/machine.py | 3 +++ .../monkey_island/cc/models/test_machine.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/monkey/monkey_island/cc/models/machine.py b/monkey/monkey_island/cc/models/machine.py index 90fa0be00..99d4ae5eb 100644 --- a/monkey/monkey_island/cc/models/machine.py +++ b/monkey/monkey_island/cc/models/machine.py @@ -20,6 +20,9 @@ class Machine(MutableInfectionMonkeyBaseModel): hardware_id: Optional[HardwareID] """An identifier generated by the agent that uniquely identifies a machine""" + island: bool = Field(default=False, allow_mutation=False) + """Whether or not the machine is an island (C&C server)""" + network_interfaces: Sequence[IPv4Interface] = tuple() """The machine's networking interfaces""" diff --git a/monkey/tests/unit_tests/monkey_island/cc/models/test_machine.py b/monkey/tests/unit_tests/monkey_island/cc/models/test_machine.py index 49eeae9a7..b63006d35 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/models/test_machine.py +++ b/monkey/tests/unit_tests/monkey_island/cc/models/test_machine.py @@ -12,6 +12,7 @@ MACHINE_OBJECT_DICT = MappingProxyType( { "id": 1, "hardware_id": uuid.getnode(), + "island": True, "network_interfaces": [IPv4Interface("10.0.0.1/24"), IPv4Interface("192.168.5.32/16")], "operating_system": OperatingSystem.WINDOWS, "operating_system_version": "eXtra Problems", @@ -23,6 +24,7 @@ MACHINE_SIMPLE_DICT = MappingProxyType( { "id": 1, "hardware_id": uuid.getnode(), + "island": True, "network_interfaces": ["10.0.0.1/24", "192.168.5.32/16"], "operating_system": "windows", "operating_system_version": "eXtra Problems", @@ -52,6 +54,7 @@ def test_to_dict(): [ ("id", "not-an-int"), ("hardware_id", "not-an-int"), + ("island", "not-a-bool"), ("network_interfaces", "not-a-list"), ("operating_system", 2.1), ("operating_system", "bsd"), @@ -130,6 +133,21 @@ def test_hardware_id_default(): assert m.hardware_id is None +def test_island_immutable(): + m = Machine(**MACHINE_OBJECT_DICT) + with pytest.raises(TypeError): + m.island = True + + +def test_island_default(): + missing_island_dict = MACHINE_OBJECT_DICT.copy() + del missing_island_dict["island"] + + m = Machine(**missing_island_dict) + + assert m.island is False + + def test_network_interfaces_set_valid_value(): m = Machine(**MACHINE_OBJECT_DICT)