cleanup(ruff): finish cleaning up E722 (do not euse bare except)
parent
b38ad265af
commit
389b381584
|
@ -136,7 +136,7 @@ class rdp(connection):
|
||||||
if "Reason:" not in str(e):
|
if "Reason:" not in str(e):
|
||||||
try:
|
try:
|
||||||
info_domain = self.conn.get_extra_info()
|
info_domain = self.conn.get_extra_info()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.domain = info_domain["dnsdomainname"]
|
self.domain = info_domain["dnsdomainname"]
|
||||||
|
|
|
@ -421,7 +421,7 @@ class smb(connection):
|
||||||
if self.args.continue_on_success and self.signing:
|
if self.args.continue_on_success and self.signing:
|
||||||
try:
|
try:
|
||||||
self.conn.logoff()
|
self.conn.logoff()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self.create_conn_obj()
|
self.create_conn_obj()
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ class smb(connection):
|
||||||
if self.args.continue_on_success and self.signing:
|
if self.args.continue_on_success and self.signing:
|
||||||
try:
|
try:
|
||||||
self.conn.logoff()
|
self.conn.logoff()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self.create_conn_obj()
|
self.create_conn_obj()
|
||||||
return True
|
return True
|
||||||
|
@ -561,7 +561,7 @@ class smb(connection):
|
||||||
if self.args.continue_on_success and self.signing:
|
if self.args.continue_on_success and self.signing:
|
||||||
try:
|
try:
|
||||||
self.conn.logoff()
|
self.conn.logoff()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self.create_conn_obj()
|
self.create_conn_obj()
|
||||||
return True
|
return True
|
||||||
|
@ -638,12 +638,12 @@ class smb(connection):
|
||||||
dce = rpctransport.get_dce_rpc()
|
dce = rpctransport.get_dce_rpc()
|
||||||
try:
|
try:
|
||||||
dce.connect()
|
dce.connect()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
dce.bind(scmr.MSRPC_UUID_SCMR)
|
dce.bind(scmr.MSRPC_UUID_SCMR)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
# 0xF003F - SC_MANAGER_ALL_ACCESS
|
# 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)
|
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")
|
self.logger.info("Executed command via wmiexec")
|
||||||
break
|
break
|
||||||
except:
|
except Exception:
|
||||||
self.logger.debug("Error executing command via wmiexec, traceback:")
|
self.logger.debug("Error executing command via wmiexec, traceback:")
|
||||||
self.logger.debug(format_exc())
|
self.logger.debug(format_exc())
|
||||||
continue
|
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)
|
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")
|
self.logger.info("Executed command via mmcexec")
|
||||||
break
|
break
|
||||||
except:
|
except Exception:
|
||||||
self.logger.debug("Error executing command via mmcexec, traceback:")
|
self.logger.debug("Error executing command via mmcexec, traceback:")
|
||||||
self.logger.debug(format_exc())
|
self.logger.debug(format_exc())
|
||||||
continue
|
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)
|
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")
|
self.logger.info("Executed command via atexec")
|
||||||
break
|
break
|
||||||
except:
|
except Exception:
|
||||||
self.logger.debug("Error executing command via atexec, traceback:")
|
self.logger.debug("Error executing command via atexec, traceback:")
|
||||||
self.logger.debug(format_exc())
|
self.logger.debug(format_exc())
|
||||||
continue
|
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)
|
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")
|
self.logger.info("Executed command via smbexec")
|
||||||
break
|
break
|
||||||
except:
|
except Exception:
|
||||||
self.logger.debug("Error executing command via smbexec, traceback:")
|
self.logger.debug("Error executing command via smbexec, traceback:")
|
||||||
self.logger.debug(format_exc())
|
self.logger.debug(format_exc())
|
||||||
continue
|
continue
|
||||||
|
@ -887,7 +887,7 @@ class smb(connection):
|
||||||
if session.sesi10_cname.find(self.local_ip) == -1:
|
if session.sesi10_cname.find(self.local_ip) == -1:
|
||||||
self.logger.highlight(f"{session.sesi10_cname:<25} User:{session.sesi10_username}")
|
self.logger.highlight(f"{session.sesi10_cname:<25} User:{session.sesi10_username}")
|
||||||
return sessions
|
return sessions
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def disks(self):
|
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:
|
if self.pvkbytes is None and self.no_da is None and self.args.local_auth is False:
|
||||||
try:
|
try:
|
||||||
results = self.db.get_domain_backupkey(self.domain)
|
results = self.db.get_domain_backupkey(self.domain)
|
||||||
except:
|
except Exception:
|
||||||
self.logger.fail(
|
self.logger.fail(
|
||||||
"Your version of nxcdb is not up to date, run nxcdb and create a new workspace: \
|
"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"
|
'workspace create dpapi' then re-run the dpapi option"
|
||||||
|
@ -1701,7 +1701,7 @@ class smb(connection):
|
||||||
add_ntds_hash.added_to_db += 1
|
add_ntds_hash.added_to_db += 1
|
||||||
return
|
return
|
||||||
raise
|
raise
|
||||||
except:
|
except Exception:
|
||||||
self.logger.debug("Dumped hash is not NTLM, not adding to db for now ;)")
|
self.logger.debug("Dumped hash is not NTLM, not adding to db for now ;)")
|
||||||
else:
|
else:
|
||||||
self.logger.debug("Dumped hash is a computer account, not adding to db")
|
self.logger.debug("Dumped hash is a computer account, not adding to db")
|
||||||
|
|
|
@ -85,7 +85,7 @@ class navigator(DatabaseNavigator):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os = host[4].decode()
|
os = host[4].decode()
|
||||||
except:
|
except Exception:
|
||||||
os = host[4]
|
os = host[4]
|
||||||
try:
|
try:
|
||||||
smbv1 = host[6]
|
smbv1 = host[6]
|
||||||
|
@ -310,7 +310,7 @@ class navigator(DatabaseNavigator):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os = host[4].decode()
|
os = host[4].decode()
|
||||||
except:
|
except Exception:
|
||||||
os = host[4]
|
os = host[4]
|
||||||
try:
|
try:
|
||||||
dc = host[5]
|
dc = host[5]
|
||||||
|
|
|
@ -100,7 +100,7 @@ class MMCEXEC:
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
iInterface = self.__dcom.CoCreateInstanceEx(string_to_bin("49B2791A-B1AE-4C90-9B8E-E860BA07F889"), IID_IDispatch)
|
iInterface = self.__dcom.CoCreateInstanceEx(string_to_bin("49B2791A-B1AE-4C90-9B8E-E860BA07F889"), IID_IDispatch)
|
||||||
except:
|
except Exception:
|
||||||
# Make it force break function
|
# Make it force break function
|
||||||
self.__dcom.disconnect()
|
self.__dcom.disconnect()
|
||||||
flag, self.__stringBinding = dcom_FirewallChecker(iInterface, self.__timeout)
|
flag, self.__stringBinding = dcom_FirewallChecker(iInterface, self.__timeout)
|
||||||
|
|
|
@ -201,7 +201,7 @@ class SMBEXEC:
|
||||||
try:
|
try:
|
||||||
self.logger.debug(f"Remote service {self.__serviceName} started.")
|
self.logger.debug(f"Remote service {self.__serviceName} started.")
|
||||||
scmr.hRStartServiceW(self.__scmr, service)
|
scmr.hRStartServiceW(self.__scmr, service)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self.logger.debug(f"Remote service {self.__serviceName} deleted.")
|
self.logger.debug(f"Remote service {self.__serviceName} deleted.")
|
||||||
scmr.hRDeleteService(self.__scmr, service)
|
scmr.hRDeleteService(self.__scmr, service)
|
||||||
|
@ -233,5 +233,5 @@ class SMBEXEC:
|
||||||
scmr.hRDeleteService(self.__scmr, service)
|
scmr.hRDeleteService(self.__scmr, service)
|
||||||
scmr.hRControlService(self.__scmr, service, scmr.SERVICE_CONTROL_STOP)
|
scmr.hRControlService(self.__scmr, service, scmr.SERVICE_CONTROL_STOP)
|
||||||
scmr.hRCloseServiceHandle(self.__scmr, service)
|
scmr.hRCloseServiceHandle(self.__scmr, service)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -102,7 +102,7 @@ class WMIEXEC:
|
||||||
try:
|
try:
|
||||||
self.logger.debug("Executing remote")
|
self.logger.debug("Executing remote")
|
||||||
self.execute_remote(data)
|
self.execute_remote(data)
|
||||||
except:
|
except Exception:
|
||||||
self.cd("\\")
|
self.cd("\\")
|
||||||
self.execute_remote(data)
|
self.execute_remote(data)
|
||||||
|
|
||||||
|
|
|
@ -72,12 +72,8 @@ class winrm(connection):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
smb_conn.logoff()
|
smb_conn.logoff()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
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:
|
if self.args.domain:
|
||||||
self.domain = self.args.domain
|
self.domain = self.args.domain
|
||||||
|
@ -317,7 +313,7 @@ class winrm(connection):
|
||||||
def execute(self, payload=None, get_output=False):
|
def execute(self, payload=None, get_output=False):
|
||||||
try:
|
try:
|
||||||
r = self.conn.execute_cmd(self.args.execute, encoding=self.args.codec)
|
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!")
|
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)
|
r = self.conn.execute_ps(self.args.execute)
|
||||||
self.logger.success("Executed command")
|
self.logger.success("Executed command")
|
||||||
|
|
|
@ -42,7 +42,7 @@ class navigator(DatabaseNavigator):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os = host[5].decode()
|
os = host[5].decode()
|
||||||
except:
|
except Exception:
|
||||||
os = host[5]
|
os = host[5]
|
||||||
|
|
||||||
links = self.db.get_admin_relations(host_id=host_id)
|
links = self.db.get_admin_relations(host_id=host_id)
|
||||||
|
@ -84,7 +84,7 @@ class navigator(DatabaseNavigator):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os = host[5].decode()
|
os = host[5].decode()
|
||||||
except:
|
except Exception:
|
||||||
os = host[5]
|
os = host[5]
|
||||||
|
|
||||||
data.append([host_id, ip, port, hostname, domain, os])
|
data.append([host_id, ip, port, hostname, domain, os])
|
||||||
|
|
|
@ -116,7 +116,7 @@ class wmi(connection):
|
||||||
self.conn.connect()
|
self.conn.connect()
|
||||||
self.conn.send(packet.get_packet())
|
self.conn.send(packet.get_packet())
|
||||||
buffer = self.conn.recv()
|
buffer = self.conn.recv()
|
||||||
except:
|
except Exception:
|
||||||
buffer = 0
|
buffer = 0
|
||||||
|
|
||||||
if buffer != 0:
|
if buffer != 0:
|
||||||
|
@ -130,17 +130,17 @@ class wmi(connection):
|
||||||
if av_pairs[ntlm.NTLMSSP_AV_HOSTNAME][1] is not None:
|
if av_pairs[ntlm.NTLMSSP_AV_HOSTNAME][1] is not None:
|
||||||
try:
|
try:
|
||||||
self.hostname = av_pairs[ntlm.NTLMSSP_AV_HOSTNAME][1].decode("utf-16le")
|
self.hostname = av_pairs[ntlm.NTLMSSP_AV_HOSTNAME][1].decode("utf-16le")
|
||||||
except:
|
except Exception:
|
||||||
self.hostname = self.host
|
self.hostname = self.host
|
||||||
if av_pairs[ntlm.NTLMSSP_AV_DNS_DOMAINNAME][1] is not None:
|
if av_pairs[ntlm.NTLMSSP_AV_DNS_DOMAINNAME][1] is not None:
|
||||||
try:
|
try:
|
||||||
self.domain = av_pairs[ntlm.NTLMSSP_AV_DNS_DOMAINNAME][1].decode("utf-16le")
|
self.domain = av_pairs[ntlm.NTLMSSP_AV_DNS_DOMAINNAME][1].decode("utf-16le")
|
||||||
except:
|
except Exception:
|
||||||
self.domain = self.args.domain
|
self.domain = self.args.domain
|
||||||
if av_pairs[ntlm.NTLMSSP_AV_DNS_HOSTNAME][1] is not None:
|
if av_pairs[ntlm.NTLMSSP_AV_DNS_HOSTNAME][1] is not None:
|
||||||
try:
|
try:
|
||||||
self.fqdn = av_pairs[ntlm.NTLMSSP_AV_DNS_HOSTNAME][1].decode("utf-16le")
|
self.fqdn = av_pairs[ntlm.NTLMSSP_AV_DNS_HOSTNAME][1].decode("utf-16le")
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if "Version" in ntlmChallenge.fields:
|
if "Version" in ntlmChallenge.fields:
|
||||||
version = ntlmChallenge["Version"]
|
version = ntlmChallenge["Version"]
|
||||||
|
|
Loading…
Reference in New Issue