From d9ee377945f69b53a4821835e934ee410a061d31 Mon Sep 17 00:00:00 2001 From: vakaris_zilius Date: Thu, 10 Mar 2022 10:18:35 +0000 Subject: [PATCH] Agent: fix access denied error handling in wmi_tools.py --- monkey/infection_monkey/exploit/tools/wmi_tools.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/monkey/infection_monkey/exploit/tools/wmi_tools.py b/monkey/infection_monkey/exploit/tools/wmi_tools.py index ab0afdb89..682dfee60 100644 --- a/monkey/infection_monkey/exploit/tools/wmi_tools.py +++ b/monkey/infection_monkey/exploit/tools/wmi_tools.py @@ -64,9 +64,13 @@ class WmiTools(object): wmi.CLSID_WbemLevel1Login, wmi.IID_IWbemLevel1Login ) except Exception as exc: - dcom.disconnect() + try: + dcom.disconnect() + except KeyError: + # No connection to disconnect + pass - if "rpc_s_access_denied" == exc: + if "rpc_s_access_denied" == exc.error_string: raise AccessDeniedException(host, username, password, domain) raise