diff --git a/monkey/infection_monkey/exploit/tools/wmi_tools.py b/monkey/infection_monkey/exploit/tools/wmi_tools.py index b7eaf8675..99fda3141 100644 --- a/monkey/infection_monkey/exploit/tools/wmi_tools.py +++ b/monkey/infection_monkey/exploit/tools/wmi_tools.py @@ -1,4 +1,5 @@ import logging +import threading from impacket.dcerpc.v5.dcom import wmi from impacket.dcerpc.v5.dcom.wmi import DCERPCSessionError @@ -8,6 +9,11 @@ from impacket.dcerpc.v5.dtypes import NULL logger = logging.getLogger(__name__) +# Due to the limitations of impacket library we should only run one WmiConnection at a time +# See comments in https://github.com/guardicore/monkey/pull/1766 +lock = threading.Lock() + + class AccessDeniedException(Exception): def __init__(self, host, username, password, domain): super(AccessDeniedException, self).__init__( @@ -77,7 +83,8 @@ class WmiTools(object): def dcom_wrap(func): def _wrapper(*args, **kwarg): try: - return func(*args, **kwarg) + with lock: + return func(*args, **kwarg) finally: WmiTools.dcom_cleanup()