Agent: Fix typo interruptable -> interruptible

This commit is contained in:
Mike Salvatore 2022-03-22 08:33:38 -04:00
parent 8921ed77ac
commit 426fc15ec1
13 changed files with 33 additions and 33 deletions

View File

@ -18,7 +18,7 @@ from infection_monkey.network.info import get_free_tcp_port
from infection_monkey.network.tools import get_interface_to_target from infection_monkey.network.tools import get_interface_to_target
from infection_monkey.utils.commands import build_monkey_commandline from infection_monkey.utils.commands import build_monkey_commandline
from infection_monkey.utils.monkey_dir import get_monkey_dir_path from infection_monkey.utils.monkey_dir import get_monkey_dir_path
from infection_monkey.utils.threading import interruptable_iter from infection_monkey.utils.threading import interruptible_iter
from infection_monkey.utils.timer import Timer from infection_monkey.utils.timer import Timer
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -136,7 +136,7 @@ class Log4ShellExploiter(WebRCE):
# Try to exploit all services, # Try to exploit all services,
# because we don't know which services are running and on which ports # because we don't know which services are running and on which ports
for exploit in get_log4shell_service_exploiters(): for exploit in get_log4shell_service_exploiters():
intr_ports = interruptable_iter(self._open_ports, self.interrupt) intr_ports = interruptible_iter(self._open_ports, self.interrupt)
for port in intr_ports: for port in intr_ports:
logger.debug( logger.debug(

View File

@ -15,7 +15,7 @@ from infection_monkey.model import DROPPER_ARG
from infection_monkey.transport import LockedHTTPServer from infection_monkey.transport import LockedHTTPServer
from infection_monkey.utils.brute_force import generate_identity_secret_pairs from infection_monkey.utils.brute_force import generate_identity_secret_pairs
from infection_monkey.utils.commands import build_monkey_commandline from infection_monkey.utils.commands import build_monkey_commandline
from infection_monkey.utils.threading import interruptable_iter from infection_monkey.utils.threading import interruptible_iter
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -214,7 +214,7 @@ class MSSQLExploiter(HostExploiter):
""" """
# Main loop # Main loop
# Iterates on users list # Iterates on users list
credentials_iterator = interruptable_iter( credentials_iterator = interruptible_iter(
users_passwords_pairs_list, users_passwords_pairs_list,
self.interrupt, self.interrupt,
"MSSQL exploiter has been interrupted", "MSSQL exploiter has been interrupted",

View File

@ -23,7 +23,7 @@ from infection_monkey.exploit.tools.helpers import get_random_file_suffix
from infection_monkey.model import DROPPER_ARG, RUN_MONKEY, VictimHost from infection_monkey.model import DROPPER_ARG, RUN_MONKEY, VictimHost
from infection_monkey.utils.commands import build_monkey_commandline from infection_monkey.utils.commands import build_monkey_commandline
from infection_monkey.utils.environment import is_windows_os from infection_monkey.utils.environment import is_windows_os
from infection_monkey.utils.threading import interruptable_iter from infection_monkey.utils.threading import interruptible_iter
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -137,7 +137,7 @@ class PowerShellExploiter(HostExploiter):
def _authenticate_via_brute_force( def _authenticate_via_brute_force(
self, credentials: List[Credentials], auth_options: List[AuthOptions] self, credentials: List[Credentials], auth_options: List[AuthOptions]
) -> Optional[IPowerShellClient]: ) -> Optional[IPowerShellClient]:
for (creds, opts) in interruptable_iter(zip(credentials, auth_options), self.interrupt): for (creds, opts) in interruptible_iter(zip(credentials, auth_options), self.interrupt):
try: try:
client = PowerShellClient(self.host.ip_addr, creds, opts) client = PowerShellClient(self.host.ip_addr, creds, opts)
client.connect() client.connect()

View File

@ -15,7 +15,7 @@ from infection_monkey.utils.brute_force import (
get_credential_string, get_credential_string,
) )
from infection_monkey.utils.commands import build_monkey_commandline from infection_monkey.utils.commands import build_monkey_commandline
from infection_monkey.utils.threading import interruptable_iter from infection_monkey.utils.threading import interruptible_iter
logger = getLogger(__name__) logger = getLogger(__name__)
@ -35,7 +35,7 @@ class SMBExploiter(HostExploiter):
dest_path = get_agent_dest_path(self.host, self.options) dest_path = get_agent_dest_path(self.host, self.options)
creds = generate_brute_force_combinations(self.options["credentials"]) creds = generate_brute_force_combinations(self.options["credentials"])
for user, password, lm_hash, ntlm_hash in interruptable_iter(creds, self.interrupt): for user, password, lm_hash, ntlm_hash in interruptible_iter(creds, self.interrupt):
creds_for_log = get_credential_string([user, password, lm_hash, ntlm_hash]) creds_for_log = get_credential_string([user, password, lm_hash, ntlm_hash])
try: try:

View File

@ -14,7 +14,7 @@ from infection_monkey.telemetry.attack.t1105_telem import T1105Telem
from infection_monkey.telemetry.attack.t1222_telem import T1222Telem from infection_monkey.telemetry.attack.t1222_telem import T1222Telem
from infection_monkey.utils.brute_force import generate_identity_secret_pairs from infection_monkey.utils.brute_force import generate_identity_secret_pairs
from infection_monkey.utils.commands import build_monkey_commandline from infection_monkey.utils.commands import build_monkey_commandline
from infection_monkey.utils.threading import interruptable_iter from infection_monkey.utils.threading import interruptible_iter
from infection_monkey.utils.timer import Timer from infection_monkey.utils.timer import Timer
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -49,7 +49,7 @@ class SSHExploiter(HostExploiter):
secrets=self.options["credentials"]["exploit_ssh_keys"], secrets=self.options["credentials"]["exploit_ssh_keys"],
) )
ssh_key_pairs_iterator = interruptable_iter( ssh_key_pairs_iterator = interruptible_iter(
user_ssh_key_pairs, user_ssh_key_pairs,
self.interrupt, self.interrupt,
"SSH exploiter has been interrupted", "SSH exploiter has been interrupted",
@ -100,7 +100,7 @@ class SSHExploiter(HostExploiter):
secrets=self.options["credentials"]["exploit_password_list"], secrets=self.options["credentials"]["exploit_password_list"],
) )
credentials_iterator = interruptable_iter( credentials_iterator = interruptible_iter(
user_password_pairs, user_password_pairs,
self.interrupt, self.interrupt,
"SSH exploiter has been interrupted", "SSH exploiter has been interrupted",

View File

@ -23,7 +23,7 @@ from infection_monkey.network.tools import tcp_port_to_service
from infection_monkey.telemetry.attack.t1197_telem import T1197Telem from infection_monkey.telemetry.attack.t1197_telem import T1197Telem
from infection_monkey.telemetry.attack.t1222_telem import T1222Telem from infection_monkey.telemetry.attack.t1222_telem import T1222Telem
from infection_monkey.utils.commands import build_monkey_commandline from infection_monkey.utils.commands import build_monkey_commandline
from infection_monkey.utils.threading import interruptable_iter from infection_monkey.utils.threading import interruptible_iter
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# Command used to check if monkeys already exists # Command used to check if monkeys already exists
@ -233,7 +233,7 @@ class WebRCE(HostExploiter):
is found (bool) is found (bool)
:return: None (we append to class variable vulnerable_urls) :return: None (we append to class variable vulnerable_urls)
""" """
for url in interruptable_iter(urls, self.interrupt): for url in interruptible_iter(urls, self.interrupt):
if self.check_if_exploitable(url): if self.check_if_exploitable(url):
self.add_vuln_url(url) self.add_vuln_url(url)
self.vulnerable_urls.append(url) self.vulnerable_urls.append(url)

View File

@ -15,7 +15,7 @@ from infection_monkey.utils.brute_force import (
get_credential_string, get_credential_string,
) )
from infection_monkey.utils.commands import build_monkey_commandline from infection_monkey.utils.commands import build_monkey_commandline
from infection_monkey.utils.threading import interruptable_iter from infection_monkey.utils.threading import interruptible_iter
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -29,7 +29,7 @@ class WmiExploiter(HostExploiter):
def _exploit_host(self) -> ExploiterResultData: def _exploit_host(self) -> ExploiterResultData:
creds = generate_brute_force_combinations(self.options["credentials"]) creds = generate_brute_force_combinations(self.options["credentials"])
intp_creds = interruptable_iter( intp_creds = interruptible_iter(
creds, creds,
self.interrupt, self.interrupt,
"WMI exploiter has been interrupted", "WMI exploiter has been interrupted",

View File

@ -11,7 +11,7 @@ from infection_monkey.network import NetworkInterface
from infection_monkey.telemetry.credentials_telem import CredentialsTelem from infection_monkey.telemetry.credentials_telem import CredentialsTelem
from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger
from infection_monkey.telemetry.post_breach_telem import PostBreachTelem from infection_monkey.telemetry.post_breach_telem import PostBreachTelem
from infection_monkey.utils.threading import create_daemon_thread, interruptable_iter from infection_monkey.utils.threading import create_daemon_thread, interruptible_iter
from infection_monkey.utils.timer import Timer from infection_monkey.utils.timer import Timer
from . import Exploiter, IPScanner, Propagator from . import Exploiter, IPScanner, Propagator
@ -220,7 +220,7 @@ class AutomatedMaster(IMaster):
logger.debug(f"Found {len(plugins)} {plugin_type}(s) to run") logger.debug(f"Found {len(plugins)} {plugin_type}(s) to run")
interrupted_message = f"Received a stop signal, skipping remaining {plugin_type}s" interrupted_message = f"Received a stop signal, skipping remaining {plugin_type}s"
for p in interruptable_iter(plugins, self._stop, interrupted_message): for p in interruptible_iter(plugins, self._stop, interrupted_message):
# TODO: Catch exceptions to prevent thread from crashing # TODO: Catch exceptions to prevent thread from crashing
callback(p) callback(p)

View File

@ -9,7 +9,7 @@ from typing import Callable, Dict, List, Mapping
from infection_monkey.i_puppet import ExploiterResultData, IPuppet from infection_monkey.i_puppet import ExploiterResultData, IPuppet
from infection_monkey.model import VictimHost from infection_monkey.model import VictimHost
from infection_monkey.utils.threading import interruptable_iter, run_worker_threads from infection_monkey.utils.threading import interruptible_iter, run_worker_threads
QUEUE_TIMEOUT = 2 QUEUE_TIMEOUT = 2
@ -112,7 +112,7 @@ class Exploiter:
stop: Event, stop: Event,
): ):
for exploiter in interruptable_iter(exploiters_to_run, stop): for exploiter in interruptible_iter(exploiters_to_run, stop):
exploiter_name = exploiter["name"] exploiter_name = exploiter["name"]
exploiter_results = self._run_exploiter( exploiter_results = self._run_exploiter(
exploiter_name, exploiter["options"], victim_host, current_depth, stop exploiter_name, exploiter["options"], victim_host, current_depth, stop

View File

@ -13,7 +13,7 @@ from infection_monkey.i_puppet import (
PortStatus, PortStatus,
) )
from infection_monkey.network import NetworkAddress from infection_monkey.network import NetworkAddress
from infection_monkey.utils.threading import interruptable_iter, run_worker_threads from infection_monkey.utils.threading import interruptible_iter, run_worker_threads
from . import IPScanResults from . import IPScanResults
@ -98,7 +98,7 @@ class IPScanner:
) -> Dict[str, FingerprintData]: ) -> Dict[str, FingerprintData]:
fingerprint_data = {} fingerprint_data = {}
for f in interruptable_iter(fingerprinters, stop): for f in interruptible_iter(fingerprinters, stop):
fingerprint_data[f["name"]] = self._puppet.fingerprint( fingerprint_data[f["name"]] = self._puppet.fingerprint(
f["name"], ip, ping_scan_data, port_scan_data, f["options"] f["name"], ip, ping_scan_data, port_scan_data, f["options"]
) )

View File

@ -5,7 +5,7 @@ from typing import Callable, List
from infection_monkey.telemetry.file_encryption_telem import FileEncryptionTelem from infection_monkey.telemetry.file_encryption_telem import FileEncryptionTelem
from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger
from infection_monkey.utils.threading import interruptable_iter from infection_monkey.utils.threading import interruptible_iter
from .consts import README_FILE_NAME, README_SRC from .consts import README_FILE_NAME, README_SRC
from .ransomware_options import RansomwareOptions from .ransomware_options import RansomwareOptions
@ -57,7 +57,7 @@ class Ransomware:
interrupted_message = ( interrupted_message = (
"Received a stop signal, skipping remaining files for encryption of ransomware payload" "Received a stop signal, skipping remaining files for encryption of ransomware payload"
) )
for filepath in interruptable_iter(file_list, interrupt, interrupted_message): for filepath in interruptible_iter(file_list, interrupt, interrupted_message):
try: try:
logger.debug(f"Encrypting {filepath}") logger.debug(f"Encrypting {filepath}")
self._encrypt_file(filepath) self._encrypt_file(filepath)

View File

@ -31,14 +31,14 @@ def create_daemon_thread(target: Callable[..., None], name: str, args: Tuple = (
return Thread(target=target, name=name, args=args, daemon=True) return Thread(target=target, name=name, args=args, daemon=True)
def interruptable_iter( def interruptible_iter(
iterator: Iterable, interrupt: Event, log_message: str = None, log_level: int = logging.DEBUG iterator: Iterable, interrupt: Event, log_message: str = None, log_level: int = logging.DEBUG
) -> Any: ) -> Any:
""" """
Wraps an iterator so that the iterator can be interrupted if the `interrupt` Event is set. This Wraps an iterator so that the iterator can be interrupted if the `interrupt` Event is set. This
is a convinient way to make loops interruptable and avoids the need to add an `if` to each and is a convinient way to make loops interruptible and avoids the need to add an `if` to each and
every loop. every loop.
:param Iterable iterator: An iterator that will be made interruptable. :param Iterable iterator: An iterator that will be made interruptible.
:param Event interrupt: A `threading.Event` that, if set, will prevent the remainder of the :param Event interrupt: A `threading.Event` that, if set, will prevent the remainder of the
iterator's items from being processed. iterator's items from being processed.
:param str log_message: A message to be logged if the iterator is interrupted. If `log_message` :param str log_message: A message to be logged if the iterator is interrupted. If `log_message`

View File

@ -3,7 +3,7 @@ from threading import Event, current_thread
from infection_monkey.utils.threading import ( from infection_monkey.utils.threading import (
create_daemon_thread, create_daemon_thread,
interruptable_iter, interruptible_iter,
run_worker_threads, run_worker_threads,
) )
@ -18,10 +18,10 @@ def test_create_daemon_thread_naming():
assert thread.name == "test" assert thread.name == "test"
def test_interruptable_iter(): def test_interruptible_iter():
interrupt = Event() interrupt = Event()
items_from_iterator = [] items_from_iterator = []
test_iterator = interruptable_iter(range(0, 10), interrupt, "Test iterator was interrupted") test_iterator = interruptible_iter(range(0, 10), interrupt, "Test iterator was interrupted")
for i in test_iterator: for i in test_iterator:
items_from_iterator.append(i) items_from_iterator.append(i)
@ -31,10 +31,10 @@ def test_interruptable_iter():
assert items_from_iterator == [0, 1, 2, 3] assert items_from_iterator == [0, 1, 2, 3]
def test_interruptable_iter_not_interrupted(): def test_interruptible_iter_not_interrupted():
interrupt = Event() interrupt = Event()
items_from_iterator = [] items_from_iterator = []
test_iterator = interruptable_iter(range(0, 5), interrupt, "Test iterator was interrupted") test_iterator = interruptible_iter(range(0, 5), interrupt, "Test iterator was interrupted")
for i in test_iterator: for i in test_iterator:
items_from_iterator.append(i) items_from_iterator.append(i)
@ -42,10 +42,10 @@ def test_interruptable_iter_not_interrupted():
assert items_from_iterator == [0, 1, 2, 3, 4] assert items_from_iterator == [0, 1, 2, 3, 4]
def test_interruptable_iter_interrupted_before_used(): def test_interruptible_iter_interrupted_before_used():
interrupt = Event() interrupt = Event()
items_from_iterator = [] items_from_iterator = []
test_iterator = interruptable_iter( test_iterator = interruptible_iter(
range(0, 5), interrupt, "Test iterator was interrupted", logging.INFO range(0, 5), interrupt, "Test iterator was interrupted", logging.INFO
) )