From 5608bb3f11031997f50724bdae0facdefb80f31b Mon Sep 17 00:00:00 2001 From: vakaris_zilius Date: Wed, 7 Sep 2022 08:27:27 +0000 Subject: [PATCH] Common, Agent: Rename get_plain_text to get_plaintext --- monkey/common/credentials/credentials.py | 2 +- monkey/infection_monkey/exploit/mssqlexec.py | 4 ++-- .../exploit/powershell_utils/powershell_client.py | 4 ++-- monkey/infection_monkey/exploit/smbexec.py | 8 ++++---- monkey/infection_monkey/exploit/sshexec.py | 4 ++-- monkey/infection_monkey/exploit/tools/smb_tools.py | 8 ++++---- monkey/infection_monkey/exploit/wmiexec.py | 8 ++++---- .../unit_tests/common/credentials/test_credentials.py | 4 ++-- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/monkey/common/credentials/credentials.py b/monkey/common/credentials/credentials.py index d924a2562..09d869876 100644 --- a/monkey/common/credentials/credentials.py +++ b/monkey/common/credentials/credentials.py @@ -11,7 +11,7 @@ Secret = Union[Password, LMHash, NTHash, SSHKeypair] Identity = Username -def get_plain_text(secret: Union[SecretStr, SecretBytes, None, str]) -> Optional[str]: +def get_plaintext(secret: Union[SecretStr, SecretBytes, None, str]) -> Optional[str]: if isinstance(secret, (SecretStr, SecretBytes)): return secret.get_secret_value() else: diff --git a/monkey/infection_monkey/exploit/mssqlexec.py b/monkey/infection_monkey/exploit/mssqlexec.py index b1d700945..b037c782a 100644 --- a/monkey/infection_monkey/exploit/mssqlexec.py +++ b/monkey/infection_monkey/exploit/mssqlexec.py @@ -6,7 +6,7 @@ from typing import Sequence, Tuple import pymssql from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT -from common.credentials.credentials import get_plain_text +from common.credentials.credentials import get_plaintext from common.utils.exceptions import FailedExploitationError from infection_monkey.exploit.HostExploiter import HostExploiter from infection_monkey.exploit.tools.helpers import get_agent_dst_path @@ -112,7 +112,7 @@ class MSSQLExploiter(HostExploiter): conn = pymssql.connect( host, user, - get_plain_text(password), + get_plaintext(password), port=port, login_timeout=self.LOGIN_TIMEOUT, timeout=self.QUERY_TIMEOUT, diff --git a/monkey/infection_monkey/exploit/powershell_utils/powershell_client.py b/monkey/infection_monkey/exploit/powershell_utils/powershell_client.py index 8113026e7..0ea71c6f1 100644 --- a/monkey/infection_monkey/exploit/powershell_utils/powershell_client.py +++ b/monkey/infection_monkey/exploit/powershell_utils/powershell_client.py @@ -11,7 +11,7 @@ from pypsrp.powershell import PowerShell, RunspacePool from typing_extensions import Protocol from urllib3 import connectionpool -from common.credentials.credentials import get_plain_text +from common.credentials.credentials import get_plaintext from infection_monkey.exploit.powershell_utils.auth_options import AuthOptions from infection_monkey.exploit.powershell_utils.credentials import Credentials, SecretType @@ -43,7 +43,7 @@ def format_password(credentials: Credentials) -> Optional[str]: if credentials.secret_type == SecretType.CACHED: return None - plaintext_secret = get_plain_text(credentials.secret) + plaintext_secret = get_plaintext(credentials.secret) if credentials.secret_type == SecretType.PASSWORD: return plaintext_secret diff --git a/monkey/infection_monkey/exploit/smbexec.py b/monkey/infection_monkey/exploit/smbexec.py index 778a4fb36..272f150eb 100644 --- a/monkey/infection_monkey/exploit/smbexec.py +++ b/monkey/infection_monkey/exploit/smbexec.py @@ -4,7 +4,7 @@ from impacket.dcerpc.v5 import scmr, transport from impacket.dcerpc.v5.scmr import DCERPCSessionError from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT -from common.credentials.credentials import get_plain_text +from common.credentials.credentials import get_plaintext from common.utils.attack_utils import ScanStatus, UsageEnum from infection_monkey.exploit.HostExploiter import HostExploiter from infection_monkey.exploit.tools.helpers import get_agent_dst_path @@ -110,10 +110,10 @@ class SMBExploiter(HostExploiter): # This method exists only for selected protocol sequences. rpctransport.set_credentials( user, - get_plain_text(password), + get_plaintext(password), "", - get_plain_text(lm_hash), - get_plain_text(ntlm_hash), + get_plaintext(lm_hash), + get_plaintext(ntlm_hash), None, ) rpctransport.set_kerberos(SMBExploiter.USE_KERBEROS) diff --git a/monkey/infection_monkey/exploit/sshexec.py b/monkey/infection_monkey/exploit/sshexec.py index ab96794a2..69b29c813 100644 --- a/monkey/infection_monkey/exploit/sshexec.py +++ b/monkey/infection_monkey/exploit/sshexec.py @@ -5,7 +5,7 @@ from pathlib import PurePath import paramiko from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT, MEDIUM_REQUEST_TIMEOUT -from common.credentials.credentials import get_plain_text +from common.credentials.credentials import get_plaintext from common.utils import Timer from common.utils.attack_utils import ScanStatus from common.utils.exceptions import FailedExploitationError @@ -60,7 +60,7 @@ class SSHExploiter(HostExploiter): for user, ssh_key_pair in ssh_key_pairs_iterator: # Creating file-like private key for paramiko - pkey = io.StringIO(get_plain_text(ssh_key_pair["private_key"])) + pkey = io.StringIO(get_plaintext(ssh_key_pair["private_key"])) ssh_string = "%s@%s" % (user, self.host.ip_addr) ssh = paramiko.SSHClient() diff --git a/monkey/infection_monkey/exploit/tools/smb_tools.py b/monkey/infection_monkey/exploit/tools/smb_tools.py index d143da84e..c9ac254e1 100644 --- a/monkey/infection_monkey/exploit/tools/smb_tools.py +++ b/monkey/infection_monkey/exploit/tools/smb_tools.py @@ -10,7 +10,7 @@ from impacket.smb3structs import SMB2_DIALECT_002, SMB2_DIALECT_21 from impacket.smbconnection import SMB_DIALECT, SMBConnection from pydantic import SecretStr -from common.credentials.credentials import get_plain_text +from common.credentials.credentials import get_plaintext from common.utils.attack_utils import ScanStatus from infection_monkey.network.tools import get_interface_to_target from infection_monkey.telemetry.attack.t1105_telem import T1105Telem @@ -218,10 +218,10 @@ class SmbTools(object): try: smb.login( username, - get_plain_text(password), + get_plaintext(password), "", - get_plain_text(lm_hash), - get_plain_text(ntlm_hash), + get_plaintext(lm_hash), + get_plaintext(ntlm_hash), ) except Exception as exc: logger.error(f'Error while logging into {host} using user "{username}": {exc}') diff --git a/monkey/infection_monkey/exploit/wmiexec.py b/monkey/infection_monkey/exploit/wmiexec.py index e79d18d25..6c5b189f7 100644 --- a/monkey/infection_monkey/exploit/wmiexec.py +++ b/monkey/infection_monkey/exploit/wmiexec.py @@ -5,7 +5,7 @@ import traceback from impacket.dcerpc.v5.rpcrt import DCERPCException -from common.credentials.credentials import get_plain_text +from common.credentials.credentials import get_plaintext from infection_monkey.exploit.HostExploiter import HostExploiter from infection_monkey.exploit.tools.helpers import get_agent_dst_path from infection_monkey.exploit.tools.smb_tools import SmbTools @@ -48,10 +48,10 @@ class WmiExploiter(HostExploiter): wmi_connection.connect( self.host, user, - get_plain_text(password), + get_plaintext(password), None, - get_plain_text(lm_hash), - get_plain_text(ntlm_hash), + get_plaintext(lm_hash), + get_plaintext(ntlm_hash), ) except AccessDeniedException: self.report_login_attempt(False, user, password, lm_hash, ntlm_hash) diff --git a/monkey/tests/unit_tests/common/credentials/test_credentials.py b/monkey/tests/unit_tests/common/credentials/test_credentials.py index 79b727a15..09d68a4c3 100644 --- a/monkey/tests/unit_tests/common/credentials/test_credentials.py +++ b/monkey/tests/unit_tests/common/credentials/test_credentials.py @@ -17,7 +17,7 @@ from tests.data_for_tests.propagation_credentials import ( from common.base_models import InfectionMonkeyBaseModel from common.credentials import Credentials -from common.credentials.credentials import get_plain_text +from common.credentials.credentials import get_plaintext @pytest.mark.parametrize( @@ -69,4 +69,4 @@ _hidden = [PASSWORD_1, PRIVATE_KEY, LM_HASH, "", "already_plaintext", Path("C:\\ @pytest.mark.parametrize("expected, hidden", list(zip(_plaintext, _hidden))) def test_get_plain_text(expected, hidden): - assert expected == get_plain_text(hidden) + assert expected == get_plaintext(hidden)