diff --git a/cme/modules/rdp.py b/cme/modules/rdp.py index 73995668..28f49d99 100644 --- a/cme/modules/rdp.py +++ b/cme/modules/rdp.py @@ -108,10 +108,7 @@ class CMEModule: else: context.log.fail(str(e)) pass - try: wmi_rdp._rdp_WMI__dcom.disconnect() - except: - pass class rdp_SMB: def __init__(self, context, connection): @@ -262,11 +259,8 @@ class rdp_WMI: self.__iWbemLevel1Login = wmi.IWbemLevel1Login(iInterface) except Exception as e: self.logger.fail(f'Unexpected wmi error: {str(e)}, please try to use "-o" with "METHOD=smb"') - try: - self.__dcom.disconnect() - except: - pass - + self.__dcom.disconnect() + def rdp_Wrapper(self, action, old=False): if old == False: # According to this document: https://learn.microsoft.com/en-us/windows/win32/termserv/win32-tslogonsetting diff --git a/cme/protocols/smb.py b/cme/protocols/smb.py index 805d4771..6f96d5c0 100755 --- a/cme/protocols/smb.py +++ b/cme/protocols/smb.py @@ -1241,10 +1241,7 @@ class smb(connection): self.logger.fail(error_msg) if not flag else self.logger.debug(error_msg) # Make it force break function - try: - dcom.disconnect() - except: - pass + dcom.disconnect() iWbemLevel1Login = IWbemLevel1Login(iInterface) iWbemServices= iWbemLevel1Login.NTLMLogin(namespace , NULL, NULL) iWbemLevel1Login.RemRelease() @@ -1265,11 +1262,7 @@ class smb(connection): raise e else: break - try: dcom.disconnect() - except: - pass - return records if records else False def spider( diff --git a/cme/protocols/smb/mmcexec.py b/cme/protocols/smb/mmcexec.py index 0696117d..4ab99c76 100644 --- a/cme/protocols/smb/mmcexec.py +++ b/cme/protocols/smb/mmcexec.py @@ -111,11 +111,8 @@ class MMCEXEC: error_msg = "MMCEXEC: Dcom initialization failed: can't get target stringbinding, maybe cause by IPv6 or any other issues, please check your target again" self.logger.fail(error_msg) if not flag else self.logger.debug(error_msg) - try: - # Make it force break function - self.__dcom.disconnect() - except: - pass + # Make it force break function + self.__dcom.disconnect() iMMC = IDispatch(iInterface) resp = iMMC.GetIDsOfNames(("Document",)) @@ -182,8 +179,8 @@ class MMCEXEC: dispParams["cNamedArgs"] = 0 self.__quit[0].Invoke(self.__quit[1], 0x409, DISPATCH_METHOD, dispParams, 0, [], []) - except: - pass + except Exception as e: + self.logger.fail(f"Unexpect dcom error when doing exit() function in mmcexec: {str(e)}") return True def execute_remote(self, data): diff --git a/cme/protocols/smb/wmiexec.py b/cme/protocols/smb/wmiexec.py index e5053f99..419ed4fb 100755 --- a/cme/protocols/smb/wmiexec.py +++ b/cme/protocols/smb/wmiexec.py @@ -83,10 +83,7 @@ class WMIEXEC: self.logger.fail(error_msg) if not flag else self.logger.debug(error_msg) # Make it force break function - try: - self.__dcom.disconnect() - except: - pass + self.__dcom.disconnect() iWbemLevel1Login = wmi.IWbemLevel1Login(iInterface) iWbemServices = iWbemLevel1Login.NTLMLogin("//./root/cimv2", NULL, NULL) iWbemLevel1Login.RemRelease()