2828REG_VALUE_TYPE_UNICODE_STRING_SEQUENCE = 7
2929REG_VALUE_TYPE_64BIT_LE = 11
3030
31- # Setup file logger
32- if "wcc_logger" not in globals ():
33- wcc_logger = logging .getLogger ("WCC" )
34- wcc_logger .propagate = False
35- log_filename = nxc_logger .init_log_file ()
36- log_filename = log_filename .replace ("log_" , "wcc_" )
37- wcc_logger .setLevel (logging .INFO )
38- wcc_file_handler = logging .FileHandler (log_filename )
39- wcc_file_handler .setFormatter (logging .Formatter ("%(asctime)s [%(levelname)s] %(message)s" ))
40- wcc_logger .addHandler (wcc_file_handler )
41-
4231
4332class ConfigCheck :
4433 """Class for performing the checks and holding the results"""
@@ -75,7 +64,7 @@ def run(self):
7564 def log (self , context ):
7665 result = "passed" if self .ok else "did not pass"
7766 reasons = ", " .join (self .reasons )
78- wcc_logger .info (f'{ self .connection .host } : Check "{ self .name } " { result } because: { reasons } ' )
67+ self . module . wcc_logger .info (f'{ self .connection .host } : Check "{ self .name } " { result } because: { reasons } ' )
7968 if self .module .quiet :
8069 return
8170
@@ -99,6 +88,19 @@ class NXCModule:
9988 supported_protocols = ["smb" ]
10089 opsec_safe = True
10190 multiple_hosts = True
91+
92+ def __init__ (self ):
93+ self .context = None
94+ self .module_options = None
95+
96+ self .wcc_logger = logging .getLogger ("WCC" )
97+ self .wcc_logger .propagate = False
98+ log_filename = nxc_logger .init_log_file ()
99+ log_filename = log_filename .replace ("log_" , "wcc_" )
100+ self .wcc_logger .setLevel (logging .INFO )
101+ wcc_file_handler = logging .FileHandler (log_filename )
102+ wcc_file_handler .setFormatter (logging .Formatter ("%(asctime)s [%(levelname)s] %(message)s" ))
103+ self .wcc_logger .addHandler (wcc_file_handler )
102104
103105 def options (self , context , module_options ):
104106 """
@@ -156,15 +158,9 @@ def __init__(self, context, connection):
156158 self .dce = remoteOps ._RemoteOperations__rrp
157159
158160 def run (self ):
159- # Prepare checks
160161 self .init_checks ()
161-
162- # Perform checks
163162 self .check_config ()
164-
165- # Check methods #
166- #################
167-
163+
168164 def init_checks (self ):
169165 # Declare the checks to do and how to do them
170166 self .checks = [
@@ -483,9 +479,6 @@ def check_applocker(self):
483479
484480 return success , reasons
485481
486- # Methods for getting values from the remote registry #
487- #######################################################
488-
489482 def _open_root_key (self , dce , connection , root_key ):
490483 ans = None
491484 retries = 1
@@ -595,9 +588,6 @@ def get_value(subkey_handle, dwIndex=0):
595588 return data
596589 return DCERPCSessionError (error_code = ERROR_OBJECT_NOT_FOUND )
597590
598- # Methods for getting values from SAMR and SCM #
599- ################################################
600-
601591 def get_service (self , service_name , connection ):
602592 """Get the service status and configuration for specified service"""
603593 remoteOps = RemoteOperations (smbConnection = connection .conn , doKerberos = False )
@@ -645,23 +635,15 @@ def ls(self, smb, path="\\", share="C$"):
645635 self .context .log .error (f"ls(): C:\\ { path } { e } \n " )
646636 return file_listing
647637
648-
649- # Comparison operators #
650- ########################
651-
652-
653638def le (reg_sz_string , number ):
654639 return int (reg_sz_string [:- 1 ]) <= number
655640
656-
657641def in_ (obj , seq ):
658642 return obj in seq
659643
660-
661644def startswith (string , start ):
662645 return string .startswith (start )
663646
664-
665647def not_ (boolean_operator ):
666648 def wrapper (* args , ** kwargs ):
667649 return not boolean_operator (* args , ** kwargs )
0 commit comments