Agent: Improve variable names in MimikatzCredentialCollector

This commit is contained in:
Mike Salvatore 2022-07-18 08:26:49 -04:00
parent acf12c2de1
commit 302803b779
1 changed files with 18 additions and 18 deletions

View File

@ -14,32 +14,32 @@ logger = logging.getLogger(__name__)
class MimikatzCredentialCollector(ICredentialCollector):
def collect_credentials(self, options=None) -> Sequence[Credentials]:
logger.info("Attempting to collect windows credentials with pypykatz.")
creds = pypykatz_handler.get_windows_creds()
logger.info(f"Pypykatz gathered {len(creds)} credentials.")
return MimikatzCredentialCollector._to_credentials(creds)
windows_credentials = pypykatz_handler.get_windows_creds()
logger.info(f"Pypykatz gathered {len(windows_credentials)} credentials.")
return MimikatzCredentialCollector._to_credentials(windows_credentials)
@staticmethod
def _to_credentials(win_creds: Sequence[WindowsCredentials]) -> [Credentials]:
all_creds = []
for win_cred in win_creds:
def _to_credentials(windows_credentials: Sequence[WindowsCredentials]) -> [Credentials]:
credentials = []
for wc in windows_credentials:
identity = None
# Mimikatz picks up users created by the Monkey even if they're successfully deleted
# since it picks up creds from the registry. The newly created users are not removed
# from the registry until a reboot of the system, hence this check.
if win_cred.username and not win_cred.username.startswith(USERNAME_PREFIX):
identity = Username(win_cred.username)
if wc.username and not wc.username.startswith(USERNAME_PREFIX):
identity = Username(wc.username)
if win_cred.password:
password = Password(win_cred.password)
all_creds.append(Credentials(identity, password))
if wc.password:
password = Password(wc.password)
credentials.append(Credentials(identity, password))
if win_cred.lm_hash:
lm_hash = LMHash(lm_hash=win_cred.lm_hash)
all_creds.append(Credentials(identity, lm_hash))
if wc.lm_hash:
lm_hash = LMHash(lm_hash=wc.lm_hash)
credentials.append(Credentials(identity, lm_hash))
if win_cred.ntlm_hash:
ntlm_hash = NTHash(nt_hash=win_cred.ntlm_hash)
all_creds.append(Credentials(identity, ntlm_hash))
if wc.ntlm_hash:
ntlm_hash = NTHash(nt_hash=wc.ntlm_hash)
credentials.append(Credentials(identity, ntlm_hash))
return all_creds
return credentials