Skip to content

Commit

Permalink
Cryptojacker: Use IAgentEventPublisher and not IAgentEventQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyamalviya committed Aug 9, 2023
1 parent 2f8f6e3 commit 2ce4461
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from egg_timer import EggTimer

from common.event_queue import IAgentEventQueue
from common.types import AgentID, Event, SocketAddress
from common.types import Event

from .bitcoin_mining_network_traffic_simulator import BitcoinMiningNetworkTrafficSimulator
from .cpu_utilizer import CPUUtilizer
Expand All @@ -25,17 +24,11 @@ def __init__(
cpu_utilizer: CPUUtilizer,
memory_utilizer: MemoryUtilizer,
bitcoin_mining_network_traffic_simulator: BitcoinMiningNetworkTrafficSimulator,
agent_id: AgentID,
agent_event_queue: IAgentEventQueue,
island_server_address: SocketAddress,
):
self._options = options
self._cpu_utilizer = cpu_utilizer
self._memory_utilizer = memory_utilizer
self._bitcoin_mining_network_traffic_simulator = bitcoin_mining_network_traffic_simulator
self._agent_id = agent_id
self._agent_event_queue = agent_event_queue
self._island_server_address = island_server_address

def run(self, interrupt: Event):
logger.info("Running cryptojacker payload")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from pprint import pformat

from common.event_queue import IAgentEventQueue
from common.event_queue import IAgentEventPublisher
from common.types import AgentID, PercentLimited, SocketAddress

from .bitcoin_mining_network_traffic_simulator import BitcoinMiningNetworkTrafficSimulator
Expand All @@ -16,33 +16,46 @@
def build_cryptojacker(
options: CryptojackerOptions,
agent_id: AgentID,
agent_event_queue: IAgentEventQueue,
agent_event_publisher: IAgentEventPublisher,
island_server_address: SocketAddress,
):
logger.debug(f"Cryptojacker configuration:\n{pformat(options)}")

cpu_utilizer = _build_cpu_utilizer(options.cpu_utilization)
memory_utilizer = _build_memory_utilizer(options.memory_utilization)
bitcoin_mining_network_traffic_simulator = _build_bitcoin_mining_network_traffic_simulator()
cpu_utilizer = _build_cpu_utilizer(options.cpu_utilization, agent_id, agent_event_publisher)
memory_utilizer = _build_memory_utilizer(
options.memory_utilization, agent_id, agent_event_publisher
)
bitcoin_mining_network_traffic_simulator = _build_bitcoin_mining_network_traffic_simulator(
island_server_address, agent_id, agent_event_publisher
)

return Cryptojacker(
options=options,
cpu_utilizer=cpu_utilizer,
memory_utilizer=memory_utilizer,
bitcoin_mining_network_traffic_simulator=bitcoin_mining_network_traffic_simulator,
agent_id=agent_id,
agent_event_queue=agent_event_queue,
island_server_address=island_server_address,
)


def _build_cpu_utilizer(cpu_utilization: PercentLimited) -> CPUUtilizer:
return CPUUtilizer(cpu_utilization)
def _build_cpu_utilizer(
cpu_utilization: PercentLimited, agent_id: AgentID, agent_event_publisher: IAgentEventPublisher
) -> CPUUtilizer:
return CPUUtilizer(cpu_utilization, agent_id, agent_event_publisher)


def _build_memory_utilizer(memory_utilization: PercentLimited) -> MemoryUtilizer:
return MemoryUtilizer(memory_utilization)
def _build_memory_utilizer(
memory_utilization: PercentLimited,
agent_id: AgentID,
agent_event_publisher: IAgentEventPublisher,
) -> MemoryUtilizer:
return MemoryUtilizer(memory_utilization, agent_id, agent_event_publisher)


def _build_bitcoin_mining_network_traffic_simulator() -> BitcoinMiningNetworkTrafficSimulator:
return BitcoinMiningNetworkTrafficSimulator()
def _build_bitcoin_mining_network_traffic_simulator(
island_server_address: SocketAddress,
agent_id: AgentID,
agent_event_publisher: IAgentEventPublisher,
) -> BitcoinMiningNetworkTrafficSimulator:
return BitcoinMiningNetworkTrafficSimulator(
island_server_address, agent_id, agent_event_publisher
)
2 changes: 1 addition & 1 deletion monkey/agent_plugins/payloads/cryptojacker/src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run(
cryptojacker = build_cryptojacker(
options=cryptojacker_options,
agent_id=self._agent_id,
agent_event_queue=self._agent_event_publisher,
agent_event_publisher=self._agent_event_publisher,
island_server_address=self._island_server_address,
)
except Exception as err:
Expand Down

0 comments on commit 2ce4461

Please sign in to comment.