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.utils.commands import build_monkey_commandline
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
logger = logging.getLogger(__name__)
@ -136,7 +136,7 @@ class Log4ShellExploiter(WebRCE):
# Try to exploit all services,
# because we don't know which services are running and on which ports
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:
logger.debug(

View File

@ -15,7 +15,7 @@ from infection_monkey.model import DROPPER_ARG
from infection_monkey.transport import LockedHTTPServer
from infection_monkey.utils.brute_force import generate_identity_secret_pairs
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__)
@ -214,7 +214,7 @@ class MSSQLExploiter(HostExploiter):
"""
# Main loop
# Iterates on users list
credentials_iterator = interruptable_iter(
credentials_iterator = interruptible_iter(
users_passwords_pairs_list,
self.interrupt,
"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.utils.commands import build_monkey_commandline
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__)
@ -137,7 +137,7 @@ class PowerShellExploiter(HostExploiter):
def _authenticate_via_brute_force(
self, credentials: List[Credentials], auth_options: List[AuthOptions]
) -> 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:
client = PowerShellClient(self.host.ip_addr, creds, opts)
client.connect()

View File

@ -15,7 +15,7 @@ from infection_monkey.utils.brute_force import (
get_credential_string,
)
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__)
@ -35,7 +35,7 @@ class SMBExploiter(HostExploiter):
dest_path = get_agent_dest_path(self.host, self.options)
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])
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.utils.brute_force import generate_identity_secret_pairs
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
logger = logging.getLogger(__name__)
@ -49,7 +49,7 @@ class SSHExploiter(HostExploiter):
secrets=self.options["credentials"]["exploit_ssh_keys"],
)
ssh_key_pairs_iterator = interruptable_iter(
ssh_key_pairs_iterator = interruptible_iter(
user_ssh_key_pairs,
self.interrupt,
"SSH exploiter has been interrupted",
@ -100,7 +100,7 @@ class SSHExploiter(HostExploiter):
secrets=self.options["credentials"]["exploit_password_list"],
)
credentials_iterator = interruptable_iter(
credentials_iterator = interruptible_iter(
user_password_pairs,
self.interrupt,
"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.t1222_telem import T1222Telem
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__)
# Command used to check if monkeys already exists
@ -233,7 +233,7 @@ class WebRCE(HostExploiter):
is found (bool)
: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):
self.add_vuln_url(url)
self.vulnerable_urls.append(url)

View File

@ -15,7 +15,7 @@ from infection_monkey.utils.brute_force import (
get_credential_string,
)
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__)
@ -29,7 +29,7 @@ class WmiExploiter(HostExploiter):
def _exploit_host(self) -> ExploiterResultData:
creds = generate_brute_force_combinations(self.options["credentials"])
intp_creds = interruptable_iter(
intp_creds = interruptible_iter(
creds,
self.interrupt,
"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.messengers.i_telemetry_messenger import ITelemetryMessenger
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 . import Exploiter, IPScanner, Propagator
@ -220,7 +220,7 @@ class AutomatedMaster(IMaster):
logger.debug(f"Found {len(plugins)} {plugin_type}(s) to run")
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
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.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
@ -112,7 +112,7 @@ class Exploiter:
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_results = self._run_exploiter(
exploiter_name, exploiter["options"], victim_host, current_depth, stop

View File

@ -13,7 +13,7 @@ from infection_monkey.i_puppet import (
PortStatus,
)
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
@ -98,7 +98,7 @@ class IPScanner:
) -> Dict[str, FingerprintData]:
fingerprint_data = {}
for f in interruptable_iter(fingerprinters, stop):
for f in interruptible_iter(fingerprinters, stop):
fingerprint_data[f["name"]] = self._puppet.fingerprint(
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.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 .ransomware_options import RansomwareOptions
@ -57,7 +57,7 @@ class Ransomware:
interrupted_message = (
"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:
logger.debug(f"Encrypting {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)
def interruptable_iter(
def interruptible_iter(
iterator: Iterable, interrupt: Event, log_message: str = None, log_level: int = logging.DEBUG
) -> Any:
"""
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.
: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
iterator's items from being processed.
: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 (
create_daemon_thread,
interruptable_iter,
interruptible_iter,
run_worker_threads,
)
@ -18,10 +18,10 @@ def test_create_daemon_thread_naming():
assert thread.name == "test"
def test_interruptable_iter():
def test_interruptible_iter():
interrupt = Event()
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:
items_from_iterator.append(i)
@ -31,10 +31,10 @@ def test_interruptable_iter():
assert items_from_iterator == [0, 1, 2, 3]
def test_interruptable_iter_not_interrupted():
def test_interruptible_iter_not_interrupted():
interrupt = Event()
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:
items_from_iterator.append(i)
@ -42,10 +42,10 @@ def test_interruptable_iter_not_interrupted():
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()
items_from_iterator = []
test_iterator = interruptable_iter(
test_iterator = interruptible_iter(
range(0, 5), interrupt, "Test iterator was interrupted", logging.INFO
)