From 8bf1d1f46fb8d928640114b757c12f44a15b0e13 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Mon, 3 Oct 2022 18:01:49 +0300 Subject: [PATCH] Island, Common: Add services to machine.py --- monkey/common/types.py | 6 +++++- monkey/monkey_island/cc/models/machine.py | 7 +++++-- vulture_allowlist.py | 10 +++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/monkey/common/types.py b/monkey/common/types.py index 499df9339..049c7b7de 100644 --- a/monkey/common/types.py +++ b/monkey/common/types.py @@ -1,7 +1,7 @@ from __future__ import annotations from dataclasses import dataclass -from enum import Enum +from enum import Enum, auto from ipaddress import IPv4Address from typing import Dict, List, Optional, Union from uuid import UUID @@ -28,6 +28,10 @@ JSONSerializable = Union[ # type: ignore[misc] ] +class NetworkServiceNameEnum(Enum): + UNKNOWN = auto() + + class NetworkPort(ConstrainedInt): """ Define network port as constrainer integer. diff --git a/monkey/monkey_island/cc/models/machine.py b/monkey/monkey_island/cc/models/machine.py index ece877b9e..9175b49a2 100644 --- a/monkey/monkey_island/cc/models/machine.py +++ b/monkey/monkey_island/cc/models/machine.py @@ -1,12 +1,12 @@ from ipaddress import IPv4Interface -from typing import Optional, Sequence +from typing import Mapping, Optional, Sequence from pydantic import Field, validator from common import OperatingSystem from common.base_models import MutableInfectionMonkeyBaseModel from common.transforms import make_immutable_sequence -from common.types import HardwareID +from common.types import HardwareID, NetworkServiceNameEnum, SocketAddress from . import MachineID @@ -35,6 +35,9 @@ class Machine(MutableInfectionMonkeyBaseModel): hostname: str = "" """The hostname of the machine""" + network_services: Mapping[SocketAddress, NetworkServiceNameEnum] + """All network services found running on the machine""" + _make_immutable_sequence = validator("network_interfaces", pre=True, allow_reuse=True)( make_immutable_sequence ) diff --git a/vulture_allowlist.py b/vulture_allowlist.py index 0ff6b710d..62deedcd9 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -9,14 +9,13 @@ from common.agent_configuration.agent_sub_configurations import ( ) from common.agent_events import ExploitationEvent, PingScanEvent, PropagationEvent, TCPScanEvent from common.credentials import Credentials, LMHash, NTHash -from common.types import NetworkPort from infection_monkey.exploit.HostExploiter.HostExploiter import ( _publish_exploitation_event, _publish_propagation_event, ) +from common.types import NetworkPort, NetworkServiceNameEnum from infection_monkey.exploit.log4shell_utils.ldap_server import LDAPServerFactory -from monkey_island.cc.event_queue import IslandEventTopic, PyPubSubIslandEventQueue -from monkey_island.cc.models import Report +from monkey_island.cc.models import Machine, Node, Report from monkey_island.cc.models.networkmap import Arc, NetworkMap from monkey_island.cc.repository import MongoAgentRepository, MongoMachineRepository from monkey_island.cc.repository.attack.IMitigationsRepository import IMitigationsRepository @@ -340,3 +339,8 @@ SCANNED EXPLOITED CC CC_TUNNEL + +# TODO remove when 2267 is done +NetworkServiceNameEnum.UNKNOWN +Machine.network_services +Node.tcp_connections