From a060313d09f91d3c1661270705b48003584acff7 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 1 Sep 2021 13:33:06 -0400 Subject: [PATCH] Agent: Move get_auth_options() to auth_options.py --- monkey/infection_monkey/exploit/powershell.py | 2 +- .../exploit/powershell_utils/auth_options.py | 17 +++++++++++++ .../auth_options_generators.py | 24 ------------------- ...ons_generators.py => test_auth_options.py} | 2 +- 4 files changed, 19 insertions(+), 26 deletions(-) delete mode 100644 monkey/infection_monkey/exploit/powershell_utils/auth_options_generators.py rename monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/{test_auth_options_generators.py => test_auth_options.py} (96%) diff --git a/monkey/infection_monkey/exploit/powershell.py b/monkey/infection_monkey/exploit/powershell.py index 3acc683a7..1765eaa6e 100644 --- a/monkey/infection_monkey/exploit/powershell.py +++ b/monkey/infection_monkey/exploit/powershell.py @@ -17,8 +17,8 @@ from infection_monkey.exploit.powershell_utils.auth_options import ( AUTH_NEGOTIATE, ENCRYPTION_AUTO, AuthOptions, + get_auth_options, ) -from infection_monkey.exploit.powershell_utils.auth_options_generators import get_auth_options from infection_monkey.exploit.powershell_utils.credential_generators import get_credentials from infection_monkey.exploit.powershell_utils.credentials import Credentials from infection_monkey.exploit.powershell_utils.utils import ( diff --git a/monkey/infection_monkey/exploit/powershell_utils/auth_options.py b/monkey/infection_monkey/exploit/powershell_utils/auth_options.py index 50d0e24e5..a9c34e2cf 100644 --- a/monkey/infection_monkey/exploit/powershell_utils/auth_options.py +++ b/monkey/infection_monkey/exploit/powershell_utils/auth_options.py @@ -1,4 +1,7 @@ from dataclasses import dataclass +from typing import List + +from infection_monkey.exploit.powershell_utils.credentials import Credentials AUTH_BASIC = "basic" AUTH_NEGOTIATE = "negotiate" @@ -11,3 +14,17 @@ class AuthOptions: auth_type: str encryption: str ssl: bool + + +def get_auth_options(credentials: List[Credentials], use_ssl: bool) -> List[AuthOptions]: + auth_options = [] + + for creds in credentials: + # Passwordless login only works with SSL false, AUTH_BASIC and ENCRYPTION_NEVER + ssl = False if creds.password == "" else use_ssl + auth_type = AUTH_BASIC if creds.password == "" else AUTH_NEGOTIATE + encryption = ENCRYPTION_NEVER if creds.password == "" else ENCRYPTION_AUTO + + auth_options.append(AuthOptions(auth_type, encryption, ssl)) + + return auth_options diff --git a/monkey/infection_monkey/exploit/powershell_utils/auth_options_generators.py b/monkey/infection_monkey/exploit/powershell_utils/auth_options_generators.py deleted file mode 100644 index 178060d9b..000000000 --- a/monkey/infection_monkey/exploit/powershell_utils/auth_options_generators.py +++ /dev/null @@ -1,24 +0,0 @@ -from typing import List - -from infection_monkey.exploit.powershell_utils.auth_options import ( - AUTH_BASIC, - AUTH_NEGOTIATE, - ENCRYPTION_AUTO, - ENCRYPTION_NEVER, - AuthOptions, -) -from infection_monkey.exploit.powershell_utils.credentials import Credentials - - -def get_auth_options(credentials: List[Credentials], use_ssl: bool) -> List[AuthOptions]: - auth_options = [] - - for creds in credentials: - # Passwordless login only works with SSL false, AUTH_BASIC and ENCRYPTION_NEVER - ssl = False if creds.password == "" else use_ssl - auth_type = AUTH_BASIC if creds.password == "" else AUTH_NEGOTIATE - encryption = ENCRYPTION_NEVER if creds.password == "" else ENCRYPTION_AUTO - - auth_options.append(AuthOptions(auth_type, encryption, ssl)) - - return auth_options diff --git a/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_auth_options_generators.py b/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_auth_options.py similarity index 96% rename from monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_auth_options_generators.py rename to monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_auth_options.py index 7a040d7c8..0a917adac 100644 --- a/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_auth_options_generators.py +++ b/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_auth_options.py @@ -4,8 +4,8 @@ from infection_monkey.exploit.powershell_utils.auth_options import ( AUTH_NEGOTIATE, ENCRYPTION_AUTO, ENCRYPTION_NEVER, + get_auth_options, ) -from infection_monkey.exploit.powershell_utils.auth_options_generators import get_auth_options from infection_monkey.exploit.powershell_utils.credentials import Credentials CREDENTIALS = [