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