From 735aac9c0d1431cf7c94c51d83e5bf13ebf89eab Mon Sep 17 00:00:00 2001 From: Ace Pace Date: Mon, 11 May 2020 14:28:08 +0300 Subject: [PATCH 1/2] Remove pywin32 requirement, it's a subset requirement of wmi. --- monkey/infection_monkey/requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/monkey/infection_monkey/requirements.txt b/monkey/infection_monkey/requirements.txt index 858e5652b..fe72d1ee0 100644 --- a/monkey/infection_monkey/requirements.txt +++ b/monkey/infection_monkey/requirements.txt @@ -14,7 +14,6 @@ ipaddress # Causes pip to error with: # Could not find a version that satisfies the requirement pywin32 (from wmi->-r /src/infection_monkey/requirements.txt (line 12)) (from versions: none) wmi==1.4.9 -pywin32 ; sys_platform == 'win32' pymssql<3.0 pyftpdlib WinSys-3.x From 1f111735458849f12e49165ff578e6df23217c91 Mon Sep 17 00:00:00 2001 From: Ace Pace Date: Mon, 11 May 2020 14:34:04 +0300 Subject: [PATCH 2/2] Remove reg_utils, unused file. Moved WMI imports to be gated behind win32 check. Set wmi package to be installed only on win32 platform. The mongo_utils and wmi_utils modules are only imported by the windows_info_collector which is only imported if we're on windows. --- monkey/common/utils/mongo_utils.py | 6 ++++-- monkey/common/utils/reg_utils.py | 25 ------------------------ monkey/infection_monkey/requirements.txt | 2 +- 3 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 monkey/common/utils/reg_utils.py diff --git a/monkey/common/utils/mongo_utils.py b/monkey/common/utils/mongo_utils.py index 854109b30..4c5a7f669 100644 --- a/monkey/common/utils/mongo_utils.py +++ b/monkey/common/utils/mongo_utils.py @@ -1,5 +1,7 @@ -import wmi -import win32com +import sys +if sys.platform == 'win32': + import win32com + import wmi __author__ = 'maor.rayzin' diff --git a/monkey/common/utils/reg_utils.py b/monkey/common/utils/reg_utils.py deleted file mode 100644 index fad92df5e..000000000 --- a/monkey/common/utils/reg_utils.py +++ /dev/null @@ -1,25 +0,0 @@ -import winreg - -from common.utils.mongo_utils import MongoUtils - -__author__ = 'maor.rayzin' - - -class RegUtils: - - def __init__(self): - # Static class - pass - - @staticmethod - def get_reg_key(subkey_path, store=winreg.HKEY_LOCAL_MACHINE): - key = winreg.ConnectRegistry(None, store) - subkey = winreg.OpenKey(key, subkey_path) - - d = dict([winreg.EnumValue(subkey, i)[:2] for i in range(winreg.QueryInfoKey(subkey)[0])]) - d = MongoUtils.fix_obj_for_mongo(d) - - subkey.Close() - key.Close() - - return d diff --git a/monkey/infection_monkey/requirements.txt b/monkey/infection_monkey/requirements.txt index fe72d1ee0..7cbb5369f 100644 --- a/monkey/infection_monkey/requirements.txt +++ b/monkey/infection_monkey/requirements.txt @@ -13,7 +13,7 @@ ipaddress # See breaking change here: https://github.com/tjguk/wmi/commit/dcf8e3eca79bb8c0101ffb83e25c066b0ba9e16d # Causes pip to error with: # Could not find a version that satisfies the requirement pywin32 (from wmi->-r /src/infection_monkey/requirements.txt (line 12)) (from versions: none) -wmi==1.4.9 +wmi==1.4.9 ; sys_platform == 'win32' pymssql<3.0 pyftpdlib WinSys-3.x