From 5c872a67c3b94490abf75ac5131ea6eefa381aee Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 18 Feb 2022 08:01:49 -0500 Subject: [PATCH] Agent: Simplify generate_username_password_or_ntlm_hash_combinations() --- monkey/infection_monkey/utils/brute_force.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/monkey/infection_monkey/utils/brute_force.py b/monkey/infection_monkey/utils/brute_force.py index e353bd8d9..ff74d9712 100644 --- a/monkey/infection_monkey/utils/brute_force.py +++ b/monkey/infection_monkey/utils/brute_force.py @@ -1,4 +1,4 @@ -from itertools import product +from itertools import chain, product from typing import Any, Iterable, Tuple @@ -18,11 +18,8 @@ def generate_username_password_or_ntlm_hash_combinations( Returns all combinations of the configurations users and passwords or lm/ntlm hashes :return: """ - cred_list = [] - for cred in product(usernames, passwords, [""], [""]): - cred_list.append(cred) - for cred in product(usernames, [""], lm_hashes, [""]): - cred_list.append(cred) - for cred in product(usernames, [""], [""], nt_hashes): - cred_list.append(cred) - return cred_list + return chain( + product(usernames, passwords, [""], [""]), + product(usernames, [""], lm_hashes, [""]), + product(usernames, [""], [""], nt_hashes), + )