Common: Flatten the ping scan event

This commit is contained in:
vakarisz 2022-09-29 13:00:53 +03:00 committed by Kekoa Kaaikala
parent 6aa69a10b6
commit 3d80adbcd5
3 changed files with 14 additions and 7 deletions

View File

@ -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

View File

@ -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)

View File

@ -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,
)