From 3d80adbcd510cfc54ca47e71102a7ffb529b5577 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Thu, 29 Sep 2022 13:00:53 +0300 Subject: [PATCH] Common: Flatten the ping scan event --- monkey/common/agent_events/ping_scan_event.py | 5 ++--- .../agent_event_handlers/handle_ping_scan_event.py | 4 ++-- .../test_handle_ping_scan_event.py | 12 ++++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/monkey/common/agent_events/ping_scan_event.py b/monkey/common/agent_events/ping_scan_event.py index 0e9ee6614..801876c95 100644 --- a/monkey/common/agent_events/ping_scan_event.py +++ b/monkey/common/agent_events/ping_scan_event.py @@ -2,7 +2,6 @@ from ipaddress import IPv4Address from typing import Optional from common import OperatingSystem - from . import AbstractAgentEvent @@ -11,8 +10,8 @@ class PingScanEvent(AbstractAgentEvent): An event that occurs when the agent performs a ping scan on its network Attributes: - :param response_received: Is any response from ping recieved - :param os: Operating system from the target system + :param response_received: Indicates if target responded to the ping + :param os: Operating system type determined by ICMP fingerprinting """ target: IPv4Address diff --git a/monkey/monkey_island/cc/agent_event_handlers/handle_ping_scan_event.py b/monkey/monkey_island/cc/agent_event_handlers/handle_ping_scan_event.py index bae20b607..fe7a2f150 100644 --- a/monkey/monkey_island/cc/agent_event_handlers/handle_ping_scan_event.py +++ b/monkey/monkey_island/cc/agent_event_handlers/handle_ping_scan_event.py @@ -52,6 +52,6 @@ class handle_ping_scan_event: return self._machine_repository.get_machine_by_id(agent.machine_id) def _update_destination_machine(self, machine: Machine, event: PingScanEvent): - if event.scan_data.os is not None: - machine.operating_system = event.scan_data.os + if event.os is not None: + machine.operating_system = event.os self._machine_repository.upsert_machine(machine) diff --git a/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_handle_ping_scan_event.py b/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_handle_ping_scan_event.py index ba1a7ff60..d8c11f91e 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_handle_ping_scan_event.py +++ b/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_handle_ping_scan_event.py @@ -7,7 +7,7 @@ import pytest from common import OperatingSystem from common.agent_events import PingScanEvent -from common.types import PingScanData, SocketAddress +from common.types import SocketAddress from monkey_island.cc.agent_event_handlers import handle_ping_scan_event from monkey_island.cc.models import Agent, CommunicationType, Machine from monkey_island.cc.repository import ( @@ -37,7 +37,15 @@ TARGET_MACHINE = Machine( EVENT = PingScanEvent( source=AGENT_ID, target=IPv4Address("10.10.10.1"), - scan_data=PingScanData(True, OperatingSystem.LINUX), + response_received=True, + os=OperatingSystem.LINUX, +) + +EVENT_NO_RESPONSE = PingScanEvent( + source=AGENT_ID, + target=IPv4Address("10.10.10.1"), + response_received=False, + os=OperatingSystem.LINUX, )