Agent: Add publish methods to HostExploiter

This commit is contained in:
Ilija Lazoroski 2022-10-03 18:00:01 +02:00 committed by Kekoa Kaaikala
parent bf4fecf464
commit 0b72e4ef9a
1 changed files with 39 additions and 0 deletions

View File

@ -2,13 +2,16 @@ import logging
import threading import threading
from abc import abstractmethod from abc import abstractmethod
from datetime import datetime from datetime import datetime
from ipaddress import IPv4Address
from typing import Dict, Sequence from typing import Dict, Sequence
from common.agent_events import ExploitationEvent, PropagationEvent
from common.event_queue import IAgentEventQueue from common.event_queue import IAgentEventQueue
from common.utils.exceptions import FailedExploitationError from common.utils.exceptions import FailedExploitationError
from infection_monkey.i_puppet import ExploiterResultData from infection_monkey.i_puppet import ExploiterResultData
from infection_monkey.model import VictimHost from infection_monkey.model import VictimHost
from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger
from infection_monkey.utils.ids import get_agent_id
from . import IAgentBinaryRepository from . import IAgentBinaryRepository
@ -124,3 +127,39 @@ class HostExploiter:
""" """
powershell = True if "powershell" in cmd.lower() else False powershell = True if "powershell" in cmd.lower() else False
self.exploit_info["executed_cmds"].append({"cmd": cmd, "powershell": powershell}) self.exploit_info["executed_cmds"].append({"cmd": cmd, "powershell": powershell})
def publish_propagation_event(
self,
target: str,
propagation_success: bool,
exploiter_name: str,
tags: frozenset = frozenset(),
error_message: str = "",
):
propagation_event = PropagationEvent(
source=get_agent_id(),
target=IPv4Address(target),
success=propagation_success,
exploiter_name=exploiter_name,
error_message=error_message,
tags=tags,
)
self.agent_event_queue.publish(propagation_event)
def publish_exploitation_event(
self,
target: str,
exploitation_success: bool,
exploiter_name: str,
tags: frozenset = frozenset(),
error_message: str = "",
):
exploitation_event = ExploitationEvent(
source=get_agent_id(),
target=IPv4Address(target),
success=exploitation_success,
exploiter_name=exploiter_name,
error_message=error_message,
tags=tags,
)
self.agent_event_queue.publish(exploitation_event)