forked from p34709852/monkey
Island: Extract method to improve readablility
This commit is contained in:
parent
c06d06edc4
commit
2aa79331e3
|
@ -38,13 +38,9 @@ class handle_ping_scan_event:
|
|||
|
||||
try:
|
||||
dest_machine = self._get_destination_machine(event)
|
||||
self._update_destination_machine(dest_machine, event)
|
||||
src_machine = self._get_source_machine(event)
|
||||
|
||||
# Update or create the node
|
||||
self._node_repository.upsert_communication(
|
||||
src_machine.id, dest_machine.id, CommunicationType.SCANNED
|
||||
)
|
||||
self._update_destination_machine_os(dest_machine, event)
|
||||
self._update_nodes(dest_machine, event)
|
||||
except (RetrievalError, StorageError, TypeError, UnknownRecordError):
|
||||
logger.exception("Unable to process ping scan data")
|
||||
|
||||
|
@ -60,11 +56,19 @@ class handle_ping_scan_event:
|
|||
self._machine_repository.upsert_machine(machine)
|
||||
return machine
|
||||
|
||||
def _get_source_machine(self, event: PingScanEvent) -> Machine:
|
||||
agent = self._agent_repository.get_agent_by_id(event.source)
|
||||
return self._machine_repository.get_machine_by_id(agent.machine_id)
|
||||
|
||||
def _update_destination_machine(self, machine: Machine, event: PingScanEvent):
|
||||
def _update_destination_machine_os(self, machine: Machine, event: PingScanEvent):
|
||||
if event.os is not None and machine.operating_system is None:
|
||||
machine.operating_system = event.os
|
||||
self._machine_repository.upsert_machine(machine)
|
||||
|
||||
def _update_nodes(self, dest_machine, event):
|
||||
src_machine = self._get_source_machine(event)
|
||||
|
||||
# Update or create the node
|
||||
self._node_repository.upsert_communication(
|
||||
src_machine.id, dest_machine.id, CommunicationType.SCANNED
|
||||
)
|
||||
|
||||
def _get_source_machine(self, event: PingScanEvent) -> Machine:
|
||||
agent = self._agent_repository.get_agent_by_id(event.source)
|
||||
return self._machine_repository.get_machine_by_id(agent.machine_id)
|
||||
|
|
Loading…
Reference in New Issue