forked from p34709852/monkey
Agent: add lock to wmi tools
impacket libraries used for WMI are not designed for multithreading
This commit is contained in:
parent
16535e06c7
commit
3dc8ef606c
|
@ -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,6 +83,7 @@ class WmiTools(object):
|
|||
def dcom_wrap(func):
|
||||
def _wrapper(*args, **kwarg):
|
||||
try:
|
||||
with lock:
|
||||
return func(*args, **kwarg)
|
||||
finally:
|
||||
WmiTools.dcom_cleanup()
|
||||
|
|
Loading…
Reference in New Issue