Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cryptojacker fixes #3567

Merged
merged 2 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
from typing import Optional

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


class BitcoinMiningNetworkTrafficSimulator:
def __init__(
self,
island_server_address: SocketAddress,
agent_id: AgentID,
agent_event_publisher: IAgentEventPublisher,
):
self._island_server_address = island_server_address
self._agent_id = agent_id
self._agent_event_publisher = agent_event_publisher

def start(self):
pass

Expand Down
12 changes: 10 additions & 2 deletions monkey/agent_plugins/payloads/cryptojacker/src/cpu_utilizer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from typing import Optional

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


class CPUUtilizer:
def __init__(self, cpu_utilization: PercentLimited):
def __init__(
self,
cpu_utilization: PercentLimited,
agent_id: AgentID,
agent_event_publisher: IAgentEventPublisher,
):
self._cpu_utilization = cpu_utilization
self._agent_id = agent_id
self._agent_event_publisher = agent_event_publisher

def start(self):
pass
Expand Down
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
)
12 changes: 10 additions & 2 deletions monkey/agent_plugins/payloads/cryptojacker/src/memory_utilizer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from typing import Optional

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


class MemoryUtilizer:
def __init__(self, memory_utilization: PercentLimited):
def __init__(
self,
memory_utilization: PercentLimited,
agent_id: AgentID,
agent_event_publisher: IAgentEventPublisher,
):
self._memory_utilization = memory_utilization
self._agent_id = agent_id
self._agent_event_publisher = agent_event_publisher

def start(self):
pass
Expand Down
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