refactor remaining flake8-simplify (SIM) issues
parent
cd1b4680ab
commit
adeddb756e
|
@ -108,6 +108,6 @@ class NXCModule:
|
|||
if self.regex.search(description):
|
||||
conditionPasswordPolicy = True
|
||||
|
||||
if (self.FILTER == conditionFilter) and (self.PASSWORDPOLICY == conditionPasswordPolicy):
|
||||
if (conditionFilter == self.FILTER) and (conditionPasswordPolicy == self.PASSWORDPOLICY):
|
||||
answersFiltered.append([answer[0], description])
|
||||
return answersFiltered
|
||||
|
|
|
@ -127,8 +127,8 @@ class NXCModule:
|
|||
except Exception as e:
|
||||
context.log.fail(f"[OPSEC] Error deleting lsass.dmp file on share {self.share}: {e}")
|
||||
|
||||
h_in = open(self.dir_result + machine_name, "rb")
|
||||
h_out = open(self.dir_result + machine_name + ".decode", "wb")
|
||||
h_in = open(self.dir_result + machine_name, "rb") # noqa: SIM115
|
||||
h_out = open(self.dir_result + machine_name + ".decode", "wb") # noqa: SIM115
|
||||
|
||||
bytes_in = bytearray(h_in.read())
|
||||
bytes_in_len = len(bytes_in)
|
||||
|
|
|
@ -125,43 +125,16 @@ class NXCModule:
|
|||
continue
|
||||
for rdg_cred in rdcman_file.rdg_creds:
|
||||
if rdg_cred.type in ["cred", "logon", "server"]:
|
||||
if rdg_cred.type == "server":
|
||||
log_text = "{} - {}:{}".format(rdg_cred.server_name, rdg_cred.username, rdg_cred.password.decode("latin-1"))
|
||||
else:
|
||||
log_text = "{}:{}".format(rdg_cred.username, rdg_cred.password.decode("latin-1"))
|
||||
context.log.highlight("[{}][{}] {}".format(rdcman_file.winuser, rdg_cred.profile_name, log_text))
|
||||
log_text = "{} - {}:{}".format(rdg_cred.server_name, rdg_cred.username, rdg_cred.password.decode("latin-1")) if rdg_cred.type == "server" else "{}:{}".format(rdg_cred.username, rdg_cred.password.decode("latin-1"))
|
||||
context.log.highlight(f"[{rdcman_file.winuser}][{rdg_cred.profile_name}] {log_text}")
|
||||
|
||||
for rdgfile in rdgfiles:
|
||||
if rdgfile is None:
|
||||
continue
|
||||
for rdg_cred in rdgfile.rdg_creds:
|
||||
if rdg_cred.type == "cred":
|
||||
context.log.highlight(
|
||||
"[{}][{}] {}:{}".format(
|
||||
rdgfile.winuser,
|
||||
rdg_cred.profile_name,
|
||||
rdg_cred.username,
|
||||
rdg_cred.password.decode("latin-1"),
|
||||
)
|
||||
)
|
||||
elif rdg_cred.type == "logon":
|
||||
context.log.highlight(
|
||||
"[{}][{}] {}:{}".format(
|
||||
rdgfile.winuser,
|
||||
rdg_cred.profile_name,
|
||||
rdg_cred.username,
|
||||
rdg_cred.password.decode("latin-1"),
|
||||
)
|
||||
)
|
||||
elif rdg_cred.type == "server":
|
||||
context.log.highlight(
|
||||
"[{}][{}] {} - {}:{}".format(
|
||||
rdgfile.winuser,
|
||||
rdg_cred.profile_name,
|
||||
rdg_cred.server_name,
|
||||
rdg_cred.username,
|
||||
rdg_cred.password.decode("latin-1"),
|
||||
)
|
||||
)
|
||||
log_text = "{}:{}".format(rdg_cred.username, rdg_cred.password.decode("latin-1"))
|
||||
if rdg_cred.type == "server":
|
||||
log_text = f"{rdg_cred.server_name} - {log_text}"
|
||||
context.log.highlight(f"[{rdgfile.winuser}][{rdg_cred.profile_name}] {log_text}")
|
||||
except Exception as e:
|
||||
context.log.debug(f"Could not loot RDCMan secrets: {e}")
|
||||
|
|
|
@ -96,7 +96,7 @@ class NXCModule:
|
|||
logfile = Path.home().joinpath(".nxc").joinpath("logs").joinpath(logfile)
|
||||
|
||||
self.context.log.info(f"Creating log file '{logfile}'")
|
||||
self.log_file = open(logfile, "w")
|
||||
self.log_file = open(logfile, "w") # noqa: SIM115
|
||||
self.append_to_log("User:", "Description:")
|
||||
|
||||
def delete_log_file(self):
|
||||
|
|
|
@ -280,7 +280,7 @@ class ldap(connection):
|
|||
if not self.domain:
|
||||
self.domain = self.hostname
|
||||
|
||||
try:
|
||||
try: # noqa: SIM105
|
||||
# DC's seem to want us to logoff first, windows workstations sometimes reset the connection
|
||||
self.conn.logoff()
|
||||
except Exception:
|
||||
|
@ -670,14 +670,7 @@ class ldap(connection):
|
|||
return True
|
||||
|
||||
def create_conn_obj(self):
|
||||
if not self.args.no_smb:
|
||||
if self.create_smbv1_conn():
|
||||
return True
|
||||
elif self.create_smbv3_conn():
|
||||
return True
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
return bool(self.args.no_smb or self.create_smbv1_conn() or self.create_smbv3_conn())
|
||||
|
||||
def get_sid(self):
|
||||
self.logger.highlight(f"Domain SID {self.sid_domain}")
|
||||
|
|
|
@ -60,7 +60,7 @@ class mssql(connection):
|
|||
|
||||
def enum_host_info(self):
|
||||
# this try pass breaks module http server, more info https://github.com/byt3bl33d3r/CrackMapExec/issues/363
|
||||
try:
|
||||
try: # noqa: SIM105
|
||||
# Probably a better way of doing this, grab our IP from the socket
|
||||
self.local_ip = str(self.conn.socket).split()[2].split("=")[1].split(":")[0]
|
||||
except Exception:
|
||||
|
|
|
@ -607,12 +607,8 @@ class smb(connection):
|
|||
return False
|
||||
return True
|
||||
|
||||
def create_conn_obj(self, kdc=""):
|
||||
if self.create_smbv1_conn(kdc):
|
||||
return True
|
||||
elif self.create_smbv3_conn(kdc):
|
||||
return True
|
||||
return False
|
||||
def create_conn_obj(self):
|
||||
return bool(self.create_smbv1_conn() or self.create_smbv3_conn())
|
||||
|
||||
def check_if_admin(self):
|
||||
rpctransport = SMBTransport(self.conn.getRemoteHost(), 445, r"\svcctl", smb_connection=self.conn)
|
||||
|
@ -1397,7 +1393,7 @@ class smb(connection):
|
|||
|
||||
if self.args.pvk is not None:
|
||||
try:
|
||||
self.pvkbytes = open(self.args.pvk, "rb").read()
|
||||
self.pvkbytes = open(self.args.pvk, "rb").read() # noqa: SIM115
|
||||
self.logger.success(f"Loading domain backupkey from {self.args.pvk}")
|
||||
except Exception as e:
|
||||
self.logger.fail(str(e))
|
||||
|
|
|
@ -104,8 +104,9 @@ class SMBSpider:
|
|||
return
|
||||
|
||||
for result in filelist:
|
||||
# this can potentially be refactored
|
||||
if result.is_directory() and result.get_longname() not in [".", ".."]:
|
||||
if subfolder == "*":
|
||||
if subfolder == "*": # noqa: SIM114
|
||||
self._spider(
|
||||
subfolder.replace("*", "") + result.get_longname(),
|
||||
depth - 1 if depth else None,
|
||||
|
|
Loading…
Reference in New Issue