forked from p15670423/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 logging
|
||||||
|
import threading
|
||||||
|
|
||||||
from impacket.dcerpc.v5.dcom import wmi
|
from impacket.dcerpc.v5.dcom import wmi
|
||||||
from impacket.dcerpc.v5.dcom.wmi import DCERPCSessionError
|
from impacket.dcerpc.v5.dcom.wmi import DCERPCSessionError
|
||||||
|
@ -8,6 +9,11 @@ from impacket.dcerpc.v5.dtypes import NULL
|
||||||
logger = logging.getLogger(__name__)
|
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):
|
class AccessDeniedException(Exception):
|
||||||
def __init__(self, host, username, password, domain):
|
def __init__(self, host, username, password, domain):
|
||||||
super(AccessDeniedException, self).__init__(
|
super(AccessDeniedException, self).__init__(
|
||||||
|
@ -77,7 +83,8 @@ class WmiTools(object):
|
||||||
def dcom_wrap(func):
|
def dcom_wrap(func):
|
||||||
def _wrapper(*args, **kwarg):
|
def _wrapper(*args, **kwarg):
|
||||||
try:
|
try:
|
||||||
return func(*args, **kwarg)
|
with lock:
|
||||||
|
return func(*args, **kwarg)
|
||||||
finally:
|
finally:
|
||||||
WmiTools.dcom_cleanup()
|
WmiTools.dcom_cleanup()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue