forked from p15670423/monkey
Agent: Rename cc_client to control_client
This commit is contained in:
parent
02a30e6950
commit
3c8530cf14
|
@ -89,9 +89,9 @@ class InfectionMonkey:
|
||||||
self._singleton = SystemSingleton()
|
self._singleton = SystemSingleton()
|
||||||
self._opts = self._get_arguments(args)
|
self._opts = self._get_arguments(args)
|
||||||
self._cmd_island_ip, self._cmd_island_port = address_to_ip_port(self._opts.server)
|
self._cmd_island_ip, self._cmd_island_port = address_to_ip_port(self._opts.server)
|
||||||
self.cc_client = ControlClient(self._opts.server)
|
self._control_client = ControlClient(self._opts.server)
|
||||||
# TODO Refactor the BaseTelem to have its own control client
|
# TODO Refactor the BaseTelem to have its own control client
|
||||||
ControlClient.control_client_object = self.cc_client
|
ControlClient.control_client_object = self._control_client
|
||||||
self._monkey_inbound_tunnel = None
|
self._monkey_inbound_tunnel = None
|
||||||
self._telemetry_messenger = LegacyTelemetryMessengerAdapter()
|
self._telemetry_messenger = LegacyTelemetryMessengerAdapter()
|
||||||
self._current_depth = self._opts.depth
|
self._current_depth = self._opts.depth
|
||||||
|
@ -131,7 +131,7 @@ class InfectionMonkey:
|
||||||
run_aws_environment_check(self._telemetry_messenger)
|
run_aws_environment_check(self._telemetry_messenger)
|
||||||
|
|
||||||
should_stop = ControlChannel(
|
should_stop = ControlChannel(
|
||||||
self.cc_client.server_address, GUID, self.cc_client.proxies
|
self._control_client.server_address, GUID, self._control_client.proxies
|
||||||
).should_agent_stop()
|
).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")
|
||||||
|
@ -143,17 +143,17 @@ class InfectionMonkey:
|
||||||
def _connect_to_island(self):
|
def _connect_to_island(self):
|
||||||
# Sets island's IP and port for monkey to communicate to
|
# Sets island's IP and port for monkey to communicate to
|
||||||
if self._current_server_is_set():
|
if self._current_server_is_set():
|
||||||
logger.debug("Default server set to: %s" % self.cc_client.server_address)
|
logger.debug("Default server set to: %s" % self._control_client.server_address)
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"Monkey couldn't find server with {} default tunnel.".format(self._opts.tunnel)
|
"Monkey couldn't find server with {} default tunnel.".format(self._opts.tunnel)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.cc_client.wakeup(parent=self._opts.parent)
|
self._control_client.wakeup(parent=self._opts.parent)
|
||||||
self.cc_client.load_control_config()
|
self._control_client.load_control_config()
|
||||||
|
|
||||||
def _current_server_is_set(self) -> bool:
|
def _current_server_is_set(self) -> bool:
|
||||||
if self.cc_client.find_server(default_tunnel=self._opts.tunnel):
|
if self._control_client.find_server(default_tunnel=self._opts.tunnel):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@ -166,12 +166,12 @@ class InfectionMonkey:
|
||||||
if firewall.is_enabled():
|
if firewall.is_enabled():
|
||||||
firewall.add_firewall_rule()
|
firewall.add_firewall_rule()
|
||||||
|
|
||||||
self._monkey_inbound_tunnel = self.cc_client.create_control_tunnel()
|
self._monkey_inbound_tunnel = self._control_client.create_control_tunnel()
|
||||||
if self._monkey_inbound_tunnel and self._propagation_enabled():
|
if self._monkey_inbound_tunnel and self._propagation_enabled():
|
||||||
self._monkey_inbound_tunnel.start()
|
self._monkey_inbound_tunnel.start()
|
||||||
|
|
||||||
StateTelem(is_done=False, version=get_version()).send()
|
StateTelem(is_done=False, version=get_version()).send()
|
||||||
TunnelTelem(self.cc_client.proxies).send()
|
TunnelTelem(self._control_client.proxies).send()
|
||||||
|
|
||||||
self._build_master()
|
self._build_master()
|
||||||
|
|
||||||
|
@ -182,9 +182,9 @@ class InfectionMonkey:
|
||||||
|
|
||||||
# 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.cc_client.server_address, GUID, self.cc_client.proxies
|
self._control_client.server_address, GUID, self._control_client.proxies
|
||||||
)
|
)
|
||||||
control_client = self.cc_client
|
control_client = self._control_client
|
||||||
credentials_store = AggregatingCredentialsStore(control_channel)
|
credentials_store = AggregatingCredentialsStore(control_channel)
|
||||||
|
|
||||||
puppet = self._build_puppet(credentials_store)
|
puppet = self._build_puppet(credentials_store)
|
||||||
|
@ -238,7 +238,7 @@ class InfectionMonkey:
|
||||||
puppet.load_plugin("ssh", SSHFingerprinter(), PluginType.FINGERPRINTER)
|
puppet.load_plugin("ssh", SSHFingerprinter(), PluginType.FINGERPRINTER)
|
||||||
|
|
||||||
agent_repository = CachingAgentRepository(
|
agent_repository = CachingAgentRepository(
|
||||||
f"https://{self.cc_client.server_address}", self.cc_client.proxies
|
f"https://{self._control_client.server_address}", self._control_client.proxies
|
||||||
)
|
)
|
||||||
exploit_wrapper = ExploiterWrapper(self._telemetry_messenger, agent_repository)
|
exploit_wrapper = ExploiterWrapper(self._telemetry_messenger, agent_repository)
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ class InfectionMonkey:
|
||||||
)
|
)
|
||||||
puppet.load_plugin(
|
puppet.load_plugin(
|
||||||
"CustomPBA",
|
"CustomPBA",
|
||||||
CustomPBA(self._telemetry_messenger, self.cc_client),
|
CustomPBA(self._telemetry_messenger, self._control_client),
|
||||||
PluginType.POST_BREACH_ACTION,
|
PluginType.POST_BREACH_ACTION,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ class InfectionMonkey:
|
||||||
)
|
)
|
||||||
|
|
||||||
def _running_on_island(self, local_network_interfaces: List[NetworkInterface]) -> bool:
|
def _running_on_island(self, local_network_interfaces: List[NetworkInterface]) -> bool:
|
||||||
server_ip, _ = address_to_ip_port(self.cc_client.server_address)
|
server_ip, _ = address_to_ip_port(self._control_client.server_address)
|
||||||
return server_ip in {interface.address for interface in local_network_interfaces}
|
return server_ip in {interface.address for interface in local_network_interfaces}
|
||||||
|
|
||||||
def _is_another_monkey_running(self):
|
def _is_another_monkey_running(self):
|
||||||
|
@ -389,7 +389,7 @@ class InfectionMonkey:
|
||||||
|
|
||||||
def _close_tunnel(self):
|
def _close_tunnel(self):
|
||||||
tunnel_address = (
|
tunnel_address = (
|
||||||
self.cc_client.proxies.get("https", "").replace("http://", "").split(":")[0]
|
self._control_client.proxies.get("https", "").replace("http://", "").split(":")[0]
|
||||||
)
|
)
|
||||||
if tunnel_address:
|
if tunnel_address:
|
||||||
logger.info("Quitting tunnel %s", tunnel_address)
|
logger.info("Quitting tunnel %s", tunnel_address)
|
||||||
|
@ -403,7 +403,7 @@ class InfectionMonkey:
|
||||||
else:
|
else:
|
||||||
log = ""
|
log = ""
|
||||||
|
|
||||||
self.cc_client.send_log(log)
|
self._control_client.send_log(log)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _self_delete() -> bool:
|
def _self_delete() -> bool:
|
||||||
|
|
|
@ -25,12 +25,12 @@ class CustomPBA(PBA):
|
||||||
Defines user's configured post breach action.
|
Defines user's configured post breach action.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, telemetry_messenger: ITelemetryMessenger, cc_client: ControlClient):
|
def __init__(self, telemetry_messenger: ITelemetryMessenger, control_client: ControlClient):
|
||||||
super(CustomPBA, self).__init__(
|
super(CustomPBA, self).__init__(
|
||||||
telemetry_messenger, POST_BREACH_FILE_EXECUTION, timeout=None
|
telemetry_messenger, POST_BREACH_FILE_EXECUTION, timeout=None
|
||||||
)
|
)
|
||||||
self.filename = ""
|
self.filename = ""
|
||||||
self.cc_client = cc_client
|
self.control_client = control_client
|
||||||
|
|
||||||
def run(self, options: Dict) -> Iterable[PostBreachData]:
|
def run(self, options: Dict) -> Iterable[PostBreachData]:
|
||||||
self._set_options(options)
|
self._set_options(options)
|
||||||
|
@ -73,7 +73,7 @@ class CustomPBA(PBA):
|
||||||
:return: True if successful, false otherwise
|
:return: True if successful, false otherwise
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pba_file_contents = self.cc_client.get_pba_file(filename)
|
pba_file_contents = self.control_client.get_pba_file(filename)
|
||||||
|
|
||||||
status = None
|
status = None
|
||||||
if not pba_file_contents or not pba_file_contents.content:
|
if not pba_file_contents or not pba_file_contents.content:
|
||||||
|
@ -86,8 +86,8 @@ class CustomPBA(PBA):
|
||||||
self.telemetry_messenger.send_telemetry(
|
self.telemetry_messenger.send_telemetry(
|
||||||
T1105Telem(
|
T1105Telem(
|
||||||
status,
|
status,
|
||||||
self.cc_client.server_address.split(":")[0],
|
self.control_client.server_address.split(":")[0],
|
||||||
get_interface_to_target(self.cc_client.server_address.split(":")[0]),
|
get_interface_to_target(self.control_client.server_address.split(":")[0]),
|
||||||
filename,
|
filename,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue