Island: Add Machine.island field

This commit is contained in:
Mike Salvatore 2022-09-20 15:09:43 -04:00
parent aed9022a7a
commit a323441ffe
2 changed files with 21 additions and 0 deletions

View File

@ -20,6 +20,9 @@ class Machine(MutableInfectionMonkeyBaseModel):
hardware_id: Optional[HardwareID] hardware_id: Optional[HardwareID]
"""An identifier generated by the agent that uniquely identifies a machine""" """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() network_interfaces: Sequence[IPv4Interface] = tuple()
"""The machine's networking interfaces""" """The machine's networking interfaces"""

View File

@ -12,6 +12,7 @@ MACHINE_OBJECT_DICT = MappingProxyType(
{ {
"id": 1, "id": 1,
"hardware_id": uuid.getnode(), "hardware_id": uuid.getnode(),
"island": True,
"network_interfaces": [IPv4Interface("10.0.0.1/24"), IPv4Interface("192.168.5.32/16")], "network_interfaces": [IPv4Interface("10.0.0.1/24"), IPv4Interface("192.168.5.32/16")],
"operating_system": OperatingSystem.WINDOWS, "operating_system": OperatingSystem.WINDOWS,
"operating_system_version": "eXtra Problems", "operating_system_version": "eXtra Problems",
@ -23,6 +24,7 @@ MACHINE_SIMPLE_DICT = MappingProxyType(
{ {
"id": 1, "id": 1,
"hardware_id": uuid.getnode(), "hardware_id": uuid.getnode(),
"island": True,
"network_interfaces": ["10.0.0.1/24", "192.168.5.32/16"], "network_interfaces": ["10.0.0.1/24", "192.168.5.32/16"],
"operating_system": "windows", "operating_system": "windows",
"operating_system_version": "eXtra Problems", "operating_system_version": "eXtra Problems",
@ -52,6 +54,7 @@ def test_to_dict():
[ [
("id", "not-an-int"), ("id", "not-an-int"),
("hardware_id", "not-an-int"), ("hardware_id", "not-an-int"),
("island", "not-a-bool"),
("network_interfaces", "not-a-list"), ("network_interfaces", "not-a-list"),
("operating_system", 2.1), ("operating_system", 2.1),
("operating_system", "bsd"), ("operating_system", "bsd"),
@ -130,6 +133,21 @@ def test_hardware_id_default():
assert m.hardware_id is None 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(): def test_network_interfaces_set_valid_value():
m = Machine(**MACHINE_OBJECT_DICT) m = Machine(**MACHINE_OBJECT_DICT)