@@ -20,13 +20,13 @@ def __init__(self):
2020 self .context = None
2121 self .module_options = None
2222 self .method = "execute"
23- self .limit = 1000
23+ self .limit = None
2424
2525 def options (self , context , module_options ):
2626 """
27- METHOD EventLog method (Execute or RPCCALL)
27+ METHOD EventLog method (Execute or RPCCALL), default: execute
2828 M Alias for METHOD
29- LIMIT Limit of the number of records to be fetched
29+ LIMIT Limit of the number of records to be fetched, default: unlimited
3030 L Alias for LIMIT
3131 """
3232 if "METHOD" in module_options :
@@ -41,8 +41,6 @@ def options(self, context, module_options):
4141 def find_credentials (self , content , context ):
4242 # remove unnecessary words
4343 content = content .replace ("\r \n " , "\n " )
44- content = content .replace ("/add" , "" )
45- content = content .replace ("/active:yes" , "" )
4644
4745 # sort and unique lines
4846 content = "\n " .join (sorted (set (content .split ("\n " ))))
@@ -66,9 +64,16 @@ def find_credentials(self, content, context):
6664 # Extracting credentials
6765 for line in content .split ("\n " ):
6866 for reg in regexps :
69- # verbose context.log.debug("Line: " + line)
70- # verbose context.log.debug("Reg: " + reg)
71- match = re .search (reg , line , re .IGNORECASE )
67+ # Remove unnecessary words
68+ line_stripped = line .replace ("/add" , "" ) \
69+ .replace ("/active:yes" , "" ) \
70+ .replace ("/delete" , "" ) \
71+ .replace ("/domain" , "" ) \
72+ # Remove command lines that were executed with nxc
73+ line_stripped = re .sub (r"1> \\Windows\\Temp\\[\w]{6} 2>&1" , "" , line_stripped )
74+
75+ # Use regex to find credentials
76+ match = re .search (reg , line_stripped , re .IGNORECASE )
7277 if match :
7378 # eleminate false positives
7479 # C:\Windows\system32\svchost.exe -k DcomLaunch -p -s PlugPlay
@@ -92,11 +97,12 @@ def find_credentials(self, content, context):
9297
9398 def on_admin_login (self , context , connection ):
9499 content = ""
95- if self .method [:1 ].lower () == "e" :
100+ if self .method .lower ().startswith ("e" ):
101+ limit_str = f"/c:{ self .limit } " if self .limit is not None else ""
96102 # https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-4688
97103 commands = [
98- f'wevtutil qe Security /c: { self . limit } /f:text /rd:true /q:"*[System[(EventID=4688 )]]" |findstr "Command Line "' ,
99- f'wevtutil qe Microsoft-Windows-Sysmon/Operational /c: { self . limit } /f:text /rd:true /q:"*[System[(EventID=1 )]]" |findstr "ParentCommandLine"'
104+ f'wevtutil qe Microsoft-Windows-Sysmon/Operational { limit_str } /f:text /rd:true /q:"*[System[(EventID=1 )]]" | findstr "ParentCommandLine "' ,
105+ f'wevtutil qe Security { limit_str } /f:text /rd:true /q:"*[System[(EventID=4688 )]]" | findstr "Command Line"' ,
100106 ]
101107 for command in commands :
102108 context .log .debug ("Execute Command: " + command )
@@ -127,7 +133,6 @@ def on_admin_login(self, context, connection):
127133 content += "CommandLine: " + match .group ("CommandLine" ) + "\n "
128134 except Exception as e :
129135 context .log .error (f"Error: { e } " )
130- continue
131136
132137 self .find_credentials (content , context )
133138
@@ -182,7 +187,7 @@ def query(self, path, query, limit):
182187
183188
184189class MSEven6Result :
185- def __init__ (self , conn , handle , limit ):
190+ def __init__ (self , conn , handle , limit = None ):
186191 self ._conn = conn
187192 self ._handle = handle
188193 self ._hardlimit = limit
@@ -192,11 +197,12 @@ def __iter__(self):
192197 return self
193198
194199 def __next__ (self ):
195- self ._hardlimit -= 1
196- if self ._hardlimit < 0 :
197- raise StopIteration
200+ if self ._hardlimit is not None :
201+ self ._hardlimit -= 1
202+ if self ._hardlimit < 0 :
203+ raise StopIteration
198204 if self ._resp is not None and self ._resp ["NumActualRecords" ] == 0 :
199- return None
205+ raise StopIteration
200206
201207 if self ._resp is None or self ._index == self ._resp ["NumActualRecords" ]:
202208 req = even6 .EvtRpcQueryNext ()
0 commit comments