diff --git a/nxc/protocols/rdp.py b/nxc/protocols/rdp.py index 0f1721152..dd50e7070 100644 --- a/nxc/protocols/rdp.py +++ b/nxc/protocols/rdp.py @@ -136,7 +136,7 @@ def create_conn_obj(self): if "Reason:" not in str(e): try: info_domain = self.conn.get_extra_info() - except: + except Exception: pass else: self.domain = info_domain["dnsdomainname"] diff --git a/nxc/protocols/smb.py b/nxc/protocols/smb.py index 0736cbe7d..0eb3bd896 100755 --- a/nxc/protocols/smb.py +++ b/nxc/protocols/smb.py @@ -421,7 +421,7 @@ def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="", 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 @@ def plaintext_login(self, domain, username, password): 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 @@ def hash_login(self, domain, username, ntlm_hash): 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 @@ def check_if_admin(self): 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 @@ def execute(self, payload=None, get_output=False, methods=None): 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 @@ def execute(self, payload=None, get_output=False, methods=None): 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 @@ def execute(self, payload=None, get_output=False, methods=None): 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 @@ def execute(self, payload=None, get_output=False, methods=None): 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 @@ def sessions(self): 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 @@ def dpapi(self): 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 @@ def add_ntds_hash(ntds_hash, host_id): 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") diff --git a/nxc/protocols/smb/db_navigator.py b/nxc/protocols/smb/db_navigator.py index 837ce9a8b..0a38d10cf 100644 --- a/nxc/protocols/smb/db_navigator.py +++ b/nxc/protocols/smb/db_navigator.py @@ -85,7 +85,7 @@ def display_hosts(self, hosts): try: os = host[4].decode() - except: + except Exception: os = host[4] try: smbv1 = host[6] @@ -310,7 +310,7 @@ def do_hosts(self, line): try: os = host[4].decode() - except: + except Exception: os = host[4] try: dc = host[5] diff --git a/nxc/protocols/smb/mmcexec.py b/nxc/protocols/smb/mmcexec.py index fd8b6cac2..bd4f7ba59 100644 --- a/nxc/protocols/smb/mmcexec.py +++ b/nxc/protocols/smb/mmcexec.py @@ -100,7 +100,7 @@ def __init__(self, host, share_name, username, password, domain, smbconnection, ) 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) diff --git a/nxc/protocols/smb/smbexec.py b/nxc/protocols/smb/smbexec.py index d2b42d979..c36e0206a 100755 --- a/nxc/protocols/smb/smbexec.py +++ b/nxc/protocols/smb/smbexec.py @@ -201,7 +201,7 @@ def execute_fileless(self, data): 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 @@ def finish(self): scmr.hRDeleteService(self.__scmr, service) scmr.hRControlService(self.__scmr, service, scmr.SERVICE_CONTROL_STOP) scmr.hRCloseServiceHandle(self.__scmr, service) - except: + except Exception: pass diff --git a/nxc/protocols/smb/wmiexec.py b/nxc/protocols/smb/wmiexec.py index 8158b8cd9..c4d95a2e1 100755 --- a/nxc/protocols/smb/wmiexec.py +++ b/nxc/protocols/smb/wmiexec.py @@ -102,7 +102,7 @@ def execute_handler(self, data): try: self.logger.debug("Executing remote") self.execute_remote(data) - except: + except Exception: self.cd("\\") self.execute_remote(data) diff --git a/nxc/protocols/winrm.py b/nxc/protocols/winrm.py index 6f2ce343a..b94175de2 100644 --- a/nxc/protocols/winrm.py +++ b/nxc/protocols/winrm.py @@ -72,12 +72,8 @@ def enum_host_info(self): 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 @@ def hash_login(self, domain, username, ntlm_hash): 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") diff --git a/nxc/protocols/winrm/db_navigator.py b/nxc/protocols/winrm/db_navigator.py index b99cc8d72..286bc3c85 100644 --- a/nxc/protocols/winrm/db_navigator.py +++ b/nxc/protocols/winrm/db_navigator.py @@ -42,7 +42,7 @@ def display_hosts(self, hosts): 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 @@ def do_hosts(self, line): try: os = host[5].decode() - except: + except Exception: os = host[5] data.append([host_id, ip, port, hostname, domain, os]) diff --git a/nxc/protocols/wmi.py b/nxc/protocols/wmi.py index d0f98c481..42e38e7f0 100644 --- a/nxc/protocols/wmi.py +++ b/nxc/protocols/wmi.py @@ -116,7 +116,7 @@ def enum_host_info(self): 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 @@ def enum_host_info(self): 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"]