Agent: Remove usage of proxies
This commit is contained in:
parent
1c805184fe
commit
7530a89152
|
@ -2,7 +2,6 @@ import json
|
|||
import logging
|
||||
import platform
|
||||
from socket import gethostname
|
||||
from typing import MutableMapping, Optional
|
||||
|
||||
import requests
|
||||
from urllib3 import disable_warnings
|
||||
|
@ -25,8 +24,7 @@ class ControlClient:
|
|||
# https://github.com/guardicore/monkey/blob/133f7f5da131b481561141171827d1f9943f6aec/monkey/infection_monkey/telemetry/base_telem.py
|
||||
control_client_object = None
|
||||
|
||||
def __init__(self, server_address: str, proxies: Optional[MutableMapping[str, str]] = None):
|
||||
self.proxies = {} if not proxies else proxies
|
||||
def __init__(self, server_address: str):
|
||||
self.server_address = server_address
|
||||
|
||||
def wakeup(self, parent=None):
|
||||
|
@ -47,15 +45,11 @@ class ControlClient:
|
|||
"launch_time": agent_process.get_start_time(),
|
||||
}
|
||||
|
||||
if self.proxies:
|
||||
monkey["tunnel"] = self.proxies.get("https")
|
||||
|
||||
requests.post( # noqa: DUO123
|
||||
f"https://{self.server_address}/api/agent",
|
||||
data=json.dumps(monkey),
|
||||
headers={"content-type": "application/json"},
|
||||
verify=False,
|
||||
proxies=self.proxies,
|
||||
timeout=MEDIUM_REQUEST_TIMEOUT,
|
||||
)
|
||||
|
||||
|
@ -73,7 +67,6 @@ class ControlClient:
|
|||
data=json.dumps(telemetry),
|
||||
headers={"content-type": "application/json"},
|
||||
verify=False,
|
||||
proxies=self.proxies,
|
||||
timeout=MEDIUM_REQUEST_TIMEOUT,
|
||||
)
|
||||
except Exception as exc:
|
||||
|
@ -89,7 +82,6 @@ class ControlClient:
|
|||
data=json.dumps(telemetry),
|
||||
headers={"content-type": "application/json"},
|
||||
verify=False,
|
||||
proxies=self.proxies,
|
||||
timeout=MEDIUM_REQUEST_TIMEOUT,
|
||||
)
|
||||
except Exception as exc:
|
||||
|
@ -100,7 +92,6 @@ class ControlClient:
|
|||
return requests.get( # noqa: DUO123
|
||||
PBA_FILE_DOWNLOAD % (self.server_address, filename),
|
||||
verify=False,
|
||||
proxies=self.proxies,
|
||||
timeout=LONG_REQUEST_TIMEOUT,
|
||||
)
|
||||
except requests.exceptions.RequestException:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import io
|
||||
import threading
|
||||
from functools import lru_cache
|
||||
from typing import Mapping
|
||||
|
||||
import requests
|
||||
|
||||
|
@ -18,9 +17,8 @@ class CachingAgentBinaryRepository(IAgentBinaryRepository):
|
|||
request is actually sent to the island for each requested binary.
|
||||
"""
|
||||
|
||||
def __init__(self, island_url: str, proxies: Mapping[str, str]):
|
||||
def __init__(self, island_url: str):
|
||||
self._island_url = island_url
|
||||
self._proxies = proxies
|
||||
self._lock = threading.Lock()
|
||||
|
||||
def get_agent_binary(
|
||||
|
@ -40,7 +38,6 @@ class CachingAgentBinaryRepository(IAgentBinaryRepository):
|
|||
response = requests.get( # noqa: DUO123
|
||||
f"{self._island_url}/api/agent-binaries/{os_name}",
|
||||
verify=False,
|
||||
proxies=self._proxies,
|
||||
timeout=MEDIUM_REQUEST_TIMEOUT,
|
||||
)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
import logging
|
||||
from pprint import pformat
|
||||
from typing import MutableMapping, Optional, Sequence
|
||||
from typing import Optional, Sequence
|
||||
from uuid import UUID
|
||||
|
||||
import requests
|
||||
|
@ -22,10 +22,9 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class ControlChannel(IControlChannel):
|
||||
def __init__(self, server: str, agent_id: str, proxies: MutableMapping[str, str]):
|
||||
def __init__(self, server: str, agent_id: str):
|
||||
self._agent_id = agent_id
|
||||
self._control_channel_server = server
|
||||
self._proxies = proxies
|
||||
|
||||
def register_agent(self, parent: Optional[UUID] = None):
|
||||
agent_registration_data = AgentRegistrationData(
|
||||
|
@ -44,7 +43,6 @@ class ControlChannel(IControlChannel):
|
|||
url,
|
||||
json=agent_registration_data.dict(simplify=True),
|
||||
verify=False,
|
||||
proxies=self._proxies,
|
||||
timeout=SHORT_REQUEST_TIMEOUT,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
@ -68,7 +66,6 @@ class ControlChannel(IControlChannel):
|
|||
response = requests.get( # noqa: DUO123
|
||||
url,
|
||||
verify=False,
|
||||
proxies=self._proxies,
|
||||
timeout=SHORT_REQUEST_TIMEOUT,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
@ -89,7 +86,6 @@ class ControlChannel(IControlChannel):
|
|||
response = requests.get( # noqa: DUO123
|
||||
f"https://{self._control_channel_server}/api/agent-configuration",
|
||||
verify=False,
|
||||
proxies=self._proxies,
|
||||
timeout=SHORT_REQUEST_TIMEOUT,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
@ -116,7 +112,6 @@ class ControlChannel(IControlChannel):
|
|||
response = requests.get( # noqa: DUO123
|
||||
propagation_credentials_url,
|
||||
verify=False,
|
||||
proxies=self._proxies,
|
||||
timeout=SHORT_REQUEST_TIMEOUT,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
|
|
@ -78,7 +78,6 @@ from infection_monkey.telemetry.messengers.legacy_telemetry_messenger_adapter im
|
|||
LegacyTelemetryMessengerAdapter,
|
||||
)
|
||||
from infection_monkey.telemetry.state_telem import StateTelem
|
||||
from infection_monkey.telemetry.tunnel_telem import TunnelTelem
|
||||
from infection_monkey.utils.aws_environment_check import run_aws_environment_check
|
||||
from infection_monkey.utils.environment import is_windows_os
|
||||
from infection_monkey.utils.file_utils import mark_file_for_deletion_on_windows
|
||||
|
@ -160,9 +159,7 @@ class InfectionMonkey:
|
|||
|
||||
run_aws_environment_check(self._telemetry_messenger)
|
||||
|
||||
should_stop = ControlChannel(
|
||||
self._control_client.server_address, GUID, self._control_client.proxies
|
||||
).should_agent_stop()
|
||||
should_stop = ControlChannel(self._control_client.server_address, GUID).should_agent_stop()
|
||||
if should_stop:
|
||||
logger.info("The Monkey Island has instructed this agent to stop")
|
||||
return
|
||||
|
@ -178,9 +175,7 @@ class InfectionMonkey:
|
|||
if firewall.is_enabled():
|
||||
firewall.add_firewall_rule()
|
||||
|
||||
control_channel = ControlChannel(
|
||||
self._control_client.server_address, GUID, self._control_client.proxies
|
||||
)
|
||||
control_channel = ControlChannel(self._control_client.server_address, GUID)
|
||||
control_channel.register_agent(self._opts.parent)
|
||||
|
||||
config = control_channel.get_config()
|
||||
|
@ -197,7 +192,6 @@ class InfectionMonkey:
|
|||
self._relay.start()
|
||||
|
||||
StateTelem(is_done=False, version=get_version()).send()
|
||||
TunnelTelem(self._control_client.proxies).send()
|
||||
|
||||
self._build_master()
|
||||
|
||||
|
@ -207,9 +201,7 @@ class InfectionMonkey:
|
|||
local_network_interfaces = InfectionMonkey._get_local_network_interfaces()
|
||||
|
||||
# TODO control_channel and control_client have same responsibilities, merge them
|
||||
control_channel = ControlChannel(
|
||||
self._control_client.server_address, GUID, self._control_client.proxies
|
||||
)
|
||||
control_channel = ControlChannel(self._control_client.server_address, GUID)
|
||||
propagation_credentials_repository = AggregatingPropagationCredentialsRepository(
|
||||
control_channel
|
||||
)
|
||||
|
@ -281,7 +273,7 @@ class InfectionMonkey:
|
|||
puppet.load_plugin("ssh", SSHFingerprinter(), PluginType.FINGERPRINTER)
|
||||
|
||||
agent_binary_repository = CachingAgentBinaryRepository(
|
||||
f"https://{self._control_client.server_address}", self._control_client.proxies
|
||||
f"https://{self._control_client.server_address}"
|
||||
)
|
||||
exploit_wrapper = ExploiterWrapper(
|
||||
self._telemetry_messenger, event_queue, agent_binary_repository
|
||||
|
|
Loading…
Reference in New Issue