Agent: Improve logging in SMBExploiter

This commit is contained in:
Mike Salvatore 2022-03-21 07:15:47 -04:00
parent 9b66b98428
commit 89bda5ae87
2 changed files with 16 additions and 10 deletions

View File

@ -9,7 +9,10 @@ from infection_monkey.exploit.tools.helpers import get_agent_dest_path
from infection_monkey.exploit.tools.smb_tools import SmbTools
from infection_monkey.model import DROPPER_CMDLINE_DETACHED_WINDOWS, MONKEY_CMDLINE_DETACHED_WINDOWS
from infection_monkey.telemetry.attack.t1035_telem import T1035Telem
from infection_monkey.utils.brute_force import generate_brute_force_combinations
from infection_monkey.utils.brute_force import (
generate_brute_force_combinations,
get_credential_string,
)
from infection_monkey.utils.commands import build_monkey_commandline
logger = getLogger(__name__)
@ -31,6 +34,8 @@ class SMBExploiter(HostExploiter):
creds = generate_brute_force_combinations(self.options["credentials"])
for user, password, lm_hash, ntlm_hash in creds:
creds_for_log = get_credential_string([user, password, lm_hash, ntlm_hash])
try:
# copy the file remotely using SMB
remote_full_path = SmbTools.copy_file(
@ -46,7 +51,8 @@ class SMBExploiter(HostExploiter):
if remote_full_path is not None:
logger.info(
f'Successfully logged in to {self.host.ip_addr} using user "{user}"'
f"Successfully logged in to {self.host.ip_addr} using SMB "
f"with {creds_for_log}"
)
self.report_login_attempt(True, user, password, lm_hash, ntlm_hash)
self.add_vuln_port(
@ -63,9 +69,9 @@ class SMBExploiter(HostExploiter):
self.report_login_attempt(False, user, password, lm_hash, ntlm_hash)
except Exception as exc:
logger.debug(
"Error when trying to copy file using SMB to {self.host.ip_addr} with user "
f'"{user}":{exc}'
logger.error(
"Error while trying to copy file using SMB to {self.host.ip_addr} with "
f"{creds_for_log}:{exc}"
)
continue

View File

@ -39,7 +39,7 @@ class SmbTools(object):
# skip guest users
if smb.isGuestSession() > 0:
logger.debug(f'Connection to {host} granted guest privileges with user "{username}"')
logger.info(f"Connection to {host} granted guest privileges with {creds_for_log}")
try:
smb.logoff()
@ -122,8 +122,8 @@ class SmbTools(object):
try:
smb.connectTree(share_name)
except Exception as exc:
logger.debug(
"Error connecting tree to share '%s' on victim %r: %s", share_name, host, exc
logger.error(
f'Error connecting tree to share "{share_name}" on victim {host}: {exc}'
)
continue
@ -154,7 +154,7 @@ class SmbTools(object):
break
except Exception as exc:
logger.debug(
logger.error(
"Error uploading monkey to share '%s' on victim %r: %s", share_name, host, exc
)
T1105Telem(
@ -206,7 +206,7 @@ class SmbTools(object):
try:
smb.login(username, password, "", lm_hash, ntlm_hash)
except Exception as exc:
logger.debug(f'Error while logging into {host} using user "{username}": {exc}')
logger.error(f'Error while logging into {host} using user "{username}": {exc}')
return None, dialect
smb.setTimeout(timeout)