cleanup(ruff): finish cleaning up E722 (do not euse bare except)

main
Marshall Hallenbeck 2023-10-06 12:47:49 -04:00
parent b38ad265af
commit 389b381584
9 changed files with 27 additions and 31 deletions

View File

@ -136,7 +136,7 @@ class rdp(connection):
if "Reason:" not in str(e):
try:
info_domain = self.conn.get_extra_info()
except:
except Exception:
pass
else:
self.domain = info_domain["dnsdomainname"]

View File

@ -421,7 +421,7 @@ class smb(connection):
if self.args.continue_on_success and self.signing:
try:
self.conn.logoff()
except:
except Exception:
pass
self.create_conn_obj()
@ -496,7 +496,7 @@ class smb(connection):
if self.args.continue_on_success and self.signing:
try:
self.conn.logoff()
except:
except Exception:
pass
self.create_conn_obj()
return True
@ -561,7 +561,7 @@ class smb(connection):
if self.args.continue_on_success and self.signing:
try:
self.conn.logoff()
except:
except Exception:
pass
self.create_conn_obj()
return True
@ -638,12 +638,12 @@ class smb(connection):
dce = rpctransport.get_dce_rpc()
try:
dce.connect()
except:
except Exception:
pass
else:
try:
dce.bind(scmr.MSRPC_UUID_SCMR)
except:
except Exception:
pass
try:
# 0xF003F - SC_MANAGER_ALL_ACCESS
@ -682,7 +682,7 @@ class smb(connection):
exec_method = WMIEXEC(self.host if not self.kerberos else self.hostname + "." + self.domain, self.smb_share_name, self.username, self.password, self.domain, self.conn, self.kerberos, self.aesKey, self.kdcHost, self.hash, self.args.share, logger=self.logger, timeout=self.args.dcom_timeout, tries=self.args.get_output_tries)
self.logger.info("Executed command via wmiexec")
break
except:
except Exception:
self.logger.debug("Error executing command via wmiexec, traceback:")
self.logger.debug(format_exc())
continue
@ -691,7 +691,7 @@ class smb(connection):
exec_method = MMCEXEC(self.host if not self.kerberos else self.hostname + "." + self.domain, self.smb_share_name, self.username, self.password, self.domain, self.conn, self.args.share, self.hash, self.logger, self.args.get_output_tries, self.args.dcom_timeout)
self.logger.info("Executed command via mmcexec")
break
except:
except Exception:
self.logger.debug("Error executing command via mmcexec, traceback:")
self.logger.debug(format_exc())
continue
@ -700,7 +700,7 @@ class smb(connection):
exec_method = TSCH_EXEC(self.host if not self.kerberos else self.hostname + "." + self.domain, self.smb_share_name, self.username, self.password, self.domain, self.kerberos, self.aesKey, self.kdcHost, self.hash, self.logger, self.args.get_output_tries, self.args.share)
self.logger.info("Executed command via atexec")
break
except:
except Exception:
self.logger.debug("Error executing command via atexec, traceback:")
self.logger.debug(format_exc())
continue
@ -709,7 +709,7 @@ class smb(connection):
exec_method = SMBEXEC(self.host if not self.kerberos else self.hostname + "." + self.domain, self.smb_share_name, self.conn, self.args.port, self.username, self.password, self.domain, self.kerberos, self.aesKey, self.kdcHost, self.hash, self.args.share, self.args.port, self.logger, self.args.get_output_tries)
self.logger.info("Executed command via smbexec")
break
except:
except Exception:
self.logger.debug("Error executing command via smbexec, traceback:")
self.logger.debug(format_exc())
continue
@ -887,7 +887,7 @@ class smb(connection):
if session.sesi10_cname.find(self.local_ip) == -1:
self.logger.highlight(f"{session.sesi10_cname:<25} User:{session.sesi10_username}")
return sessions
except:
except Exception:
pass
def disks(self):
@ -1435,7 +1435,7 @@ class smb(connection):
if self.pvkbytes is None and self.no_da is None and self.args.local_auth is False:
try:
results = self.db.get_domain_backupkey(self.domain)
except:
except Exception:
self.logger.fail(
"Your version of nxcdb is not up to date, run nxcdb and create a new workspace: \
'workspace create dpapi' then re-run the dpapi option"
@ -1701,7 +1701,7 @@ class smb(connection):
add_ntds_hash.added_to_db += 1
return
raise
except:
except Exception:
self.logger.debug("Dumped hash is not NTLM, not adding to db for now ;)")
else:
self.logger.debug("Dumped hash is a computer account, not adding to db")

View File

@ -85,7 +85,7 @@ class navigator(DatabaseNavigator):
try:
os = host[4].decode()
except:
except Exception:
os = host[4]
try:
smbv1 = host[6]
@ -310,7 +310,7 @@ class navigator(DatabaseNavigator):
try:
os = host[4].decode()
except:
except Exception:
os = host[4]
try:
dc = host[5]

View File

@ -100,7 +100,7 @@ class MMCEXEC:
)
try:
iInterface = self.__dcom.CoCreateInstanceEx(string_to_bin("49B2791A-B1AE-4C90-9B8E-E860BA07F889"), IID_IDispatch)
except:
except Exception:
# Make it force break function
self.__dcom.disconnect()
flag, self.__stringBinding = dcom_FirewallChecker(iInterface, self.__timeout)

View File

@ -201,7 +201,7 @@ class SMBEXEC:
try:
self.logger.debug(f"Remote service {self.__serviceName} started.")
scmr.hRStartServiceW(self.__scmr, service)
except:
except Exception:
pass
self.logger.debug(f"Remote service {self.__serviceName} deleted.")
scmr.hRDeleteService(self.__scmr, service)
@ -233,5 +233,5 @@ class SMBEXEC:
scmr.hRDeleteService(self.__scmr, service)
scmr.hRControlService(self.__scmr, service, scmr.SERVICE_CONTROL_STOP)
scmr.hRCloseServiceHandle(self.__scmr, service)
except:
except Exception:
pass

View File

@ -102,7 +102,7 @@ class WMIEXEC:
try:
self.logger.debug("Executing remote")
self.execute_remote(data)
except:
except Exception:
self.cd("\\")
self.execute_remote(data)

View File

@ -72,12 +72,8 @@ class winrm(connection):
try:
smb_conn.logoff()
except:
except Exception:
pass
# except Exception as e:
# self.logger.fail(
# f"Error retrieving host domain: {e} specify one manually with the '-d' flag"
# )
if self.args.domain:
self.domain = self.args.domain
@ -317,7 +313,7 @@ class winrm(connection):
def execute(self, payload=None, get_output=False):
try:
r = self.conn.execute_cmd(self.args.execute, encoding=self.args.codec)
except:
except Exception:
self.logger.info("Cannot execute command, probably because user is not local admin, but" " powershell command should be ok!")
r = self.conn.execute_ps(self.args.execute)
self.logger.success("Executed command")

View File

@ -42,7 +42,7 @@ class navigator(DatabaseNavigator):
try:
os = host[5].decode()
except:
except Exception:
os = host[5]
links = self.db.get_admin_relations(host_id=host_id)
@ -84,7 +84,7 @@ class navigator(DatabaseNavigator):
try:
os = host[5].decode()
except:
except Exception:
os = host[5]
data.append([host_id, ip, port, hostname, domain, os])

View File

@ -116,7 +116,7 @@ class wmi(connection):
self.conn.connect()
self.conn.send(packet.get_packet())
buffer = self.conn.recv()
except:
except Exception:
buffer = 0
if buffer != 0:
@ -130,17 +130,17 @@ class wmi(connection):
if av_pairs[ntlm.NTLMSSP_AV_HOSTNAME][1] is not None:
try:
self.hostname = av_pairs[ntlm.NTLMSSP_AV_HOSTNAME][1].decode("utf-16le")
except:
except Exception:
self.hostname = self.host
if av_pairs[ntlm.NTLMSSP_AV_DNS_DOMAINNAME][1] is not None:
try:
self.domain = av_pairs[ntlm.NTLMSSP_AV_DNS_DOMAINNAME][1].decode("utf-16le")
except:
except Exception:
self.domain = self.args.domain
if av_pairs[ntlm.NTLMSSP_AV_DNS_HOSTNAME][1] is not None:
try:
self.fqdn = av_pairs[ntlm.NTLMSSP_AV_DNS_HOSTNAME][1].decode("utf-16le")
except:
except Exception:
pass
if "Version" in ntlmChallenge.fields:
version = ntlmChallenge["Version"]