Common, Agent: Rename get_plain_text to get_plaintext

This commit is contained in:
vakaris_zilius 2022-09-07 08:27:27 +00:00
parent 6e254c71d7
commit 5608bb3f11
8 changed files with 21 additions and 21 deletions

View File

@ -11,7 +11,7 @@ Secret = Union[Password, LMHash, NTHash, SSHKeypair]
Identity = Username 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)): if isinstance(secret, (SecretStr, SecretBytes)):
return secret.get_secret_value() return secret.get_secret_value()
else: else:

View File

@ -6,7 +6,7 @@ from typing import Sequence, Tuple
import pymssql import pymssql
from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT 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 common.utils.exceptions import FailedExploitationError
from infection_monkey.exploit.HostExploiter import HostExploiter from infection_monkey.exploit.HostExploiter import HostExploiter
from infection_monkey.exploit.tools.helpers import get_agent_dst_path from infection_monkey.exploit.tools.helpers import get_agent_dst_path
@ -112,7 +112,7 @@ class MSSQLExploiter(HostExploiter):
conn = pymssql.connect( conn = pymssql.connect(
host, host,
user, user,
get_plain_text(password), get_plaintext(password),
port=port, port=port,
login_timeout=self.LOGIN_TIMEOUT, login_timeout=self.LOGIN_TIMEOUT,
timeout=self.QUERY_TIMEOUT, timeout=self.QUERY_TIMEOUT,

View File

@ -11,7 +11,7 @@ from pypsrp.powershell import PowerShell, RunspacePool
from typing_extensions import Protocol from typing_extensions import Protocol
from urllib3 import connectionpool 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.auth_options import AuthOptions
from infection_monkey.exploit.powershell_utils.credentials import Credentials, SecretType 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: if credentials.secret_type == SecretType.CACHED:
return None return None
plaintext_secret = get_plain_text(credentials.secret) plaintext_secret = get_plaintext(credentials.secret)
if credentials.secret_type == SecretType.PASSWORD: if credentials.secret_type == SecretType.PASSWORD:
return plaintext_secret return plaintext_secret

View File

@ -4,7 +4,7 @@ from impacket.dcerpc.v5 import scmr, transport
from impacket.dcerpc.v5.scmr import DCERPCSessionError from impacket.dcerpc.v5.scmr import DCERPCSessionError
from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT 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 common.utils.attack_utils import ScanStatus, UsageEnum
from infection_monkey.exploit.HostExploiter import HostExploiter from infection_monkey.exploit.HostExploiter import HostExploiter
from infection_monkey.exploit.tools.helpers import get_agent_dst_path 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. # This method exists only for selected protocol sequences.
rpctransport.set_credentials( rpctransport.set_credentials(
user, user,
get_plain_text(password), get_plaintext(password),
"", "",
get_plain_text(lm_hash), get_plaintext(lm_hash),
get_plain_text(ntlm_hash), get_plaintext(ntlm_hash),
None, None,
) )
rpctransport.set_kerberos(SMBExploiter.USE_KERBEROS) rpctransport.set_kerberos(SMBExploiter.USE_KERBEROS)

View File

@ -5,7 +5,7 @@ from pathlib import PurePath
import paramiko import paramiko
from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT, MEDIUM_REQUEST_TIMEOUT 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 import Timer
from common.utils.attack_utils import ScanStatus from common.utils.attack_utils import ScanStatus
from common.utils.exceptions import FailedExploitationError from common.utils.exceptions import FailedExploitationError
@ -60,7 +60,7 @@ class SSHExploiter(HostExploiter):
for user, ssh_key_pair in ssh_key_pairs_iterator: for user, ssh_key_pair in ssh_key_pairs_iterator:
# Creating file-like private key for paramiko # 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_string = "%s@%s" % (user, self.host.ip_addr)
ssh = paramiko.SSHClient() ssh = paramiko.SSHClient()

View File

@ -10,7 +10,7 @@ from impacket.smb3structs import SMB2_DIALECT_002, SMB2_DIALECT_21
from impacket.smbconnection import SMB_DIALECT, SMBConnection from impacket.smbconnection import SMB_DIALECT, SMBConnection
from pydantic import SecretStr 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 common.utils.attack_utils import ScanStatus
from infection_monkey.network.tools import get_interface_to_target from infection_monkey.network.tools import get_interface_to_target
from infection_monkey.telemetry.attack.t1105_telem import T1105Telem from infection_monkey.telemetry.attack.t1105_telem import T1105Telem
@ -218,10 +218,10 @@ class SmbTools(object):
try: try:
smb.login( smb.login(
username, username,
get_plain_text(password), get_plaintext(password),
"", "",
get_plain_text(lm_hash), get_plaintext(lm_hash),
get_plain_text(ntlm_hash), get_plaintext(ntlm_hash),
) )
except Exception as exc: except Exception as exc:
logger.error(f'Error while logging into {host} using user "{username}": {exc}') logger.error(f'Error while logging into {host} using user "{username}": {exc}')

View File

@ -5,7 +5,7 @@ import traceback
from impacket.dcerpc.v5.rpcrt import DCERPCException 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.HostExploiter import HostExploiter
from infection_monkey.exploit.tools.helpers import get_agent_dst_path from infection_monkey.exploit.tools.helpers import get_agent_dst_path
from infection_monkey.exploit.tools.smb_tools import SmbTools from infection_monkey.exploit.tools.smb_tools import SmbTools
@ -48,10 +48,10 @@ class WmiExploiter(HostExploiter):
wmi_connection.connect( wmi_connection.connect(
self.host, self.host,
user, user,
get_plain_text(password), get_plaintext(password),
None, None,
get_plain_text(lm_hash), get_plaintext(lm_hash),
get_plain_text(ntlm_hash), get_plaintext(ntlm_hash),
) )
except AccessDeniedException: except AccessDeniedException:
self.report_login_attempt(False, user, password, lm_hash, ntlm_hash) self.report_login_attempt(False, user, password, lm_hash, ntlm_hash)

View File

@ -17,7 +17,7 @@ from tests.data_for_tests.propagation_credentials import (
from common.base_models import InfectionMonkeyBaseModel from common.base_models import InfectionMonkeyBaseModel
from common.credentials import Credentials from common.credentials import Credentials
from common.credentials.credentials import get_plain_text from common.credentials.credentials import get_plaintext
@pytest.mark.parametrize( @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))) @pytest.mark.parametrize("expected, hidden", list(zip(_plaintext, _hidden)))
def test_get_plain_text(expected, hidden): def test_get_plain_text(expected, hidden):
assert expected == get_plain_text(hidden) assert expected == get_plaintext(hidden)