@@ -163,13 +163,19 @@ def clear(self, ClassName_StoreOutput=None):
163
163
class_Method .remove_Class (ClassName = ClassName_StoreOutput , return_iWbemServices = False )
164
164
165
165
class EXEC_COMMAND_SHELL (cmd .Cmd ):
166
- def __init__ (self , iWbemLevel1Login , dcom , codec ):
166
+ def __init__ (self , iWbemLevel1Login , dcom , codec , addr ):
167
167
cmd .Cmd .__init__ (self )
168
- self .codec = codec
169
168
self .dcom = dcom
169
+ self .codec = codec
170
+ self .hostname = addr
171
+ self .save_Path = 'save/' + self .hostname
172
+ self .save_fileName = str (int (time .time ())) + ".txt"
173
+ self .logging = False
174
+ self .interval = 5
170
175
self .cwd = 'C:\Windows\System32'
171
176
self .prompt = "%s>" % self .cwd
172
177
self .intro = '[!] Launching semi-interactive shell - Careful what you execute'
178
+
173
179
self .iWbemLevel1Login = iWbemLevel1Login
174
180
self .executer = executeVBS_Toolkit (self .iWbemLevel1Login )
175
181
self .ClassName_StoreOutput = "Win32_OSRecoveryConfigurationDataBackup"
@@ -179,16 +185,48 @@ def __init__(self, iWbemLevel1Login, dcom, codec):
179
185
self .iWbemServices_Reuse_cimv2 = class_Method .check_ClassStatus (self .ClassName_StoreOutput , return_iWbemServices = True )
180
186
self .iWbemServices_Reuse_subscription = None
181
187
188
+ def do_help (self , line ):
189
+ print ("""
190
+ delay {seconds} - set interval time in command execution (default is 5 seconds).
191
+ logging - logging everythings.
192
+ exit - exit.
193
+ """ )
194
+
195
+ def do_logging (self , line ):
196
+ print ("[+] Start logging." )
197
+ print ("[+] Save command result to: {}/{}" .format (self .save_Path , self .save_fileName ))
198
+ self .logging = True
199
+
200
+ def do_delay (self , seconds ):
201
+ print ("[+] Set interval time to: %s" % str (seconds ))
202
+ self .interval = int (seconds )
203
+
182
204
def do_exit (self , line ):
183
205
self .dcom .disconnect ()
184
206
sys .exit (1 )
185
207
186
- def process_Result (self , result ):
208
+ def interval_Timer (self , seconds ):
209
+ for i in range (seconds ,0 ,- 1 ):
210
+ print (f"[+] Waiting { i } s for next step." , end = "\r " , flush = True )
211
+ time .sleep (1 )
212
+ print ("\r \n [+] Results: \r \n " )
213
+
214
+ def save_ToFile (self , content ):
215
+ if os .path .exists (self .save_Path ) == False :
216
+ os .makedirs (self .save_Path , exist_ok = True )
217
+
218
+ with open ("{}/{}" .format (self .save_Path , self .save_fileName ), 'a+' ) as f : f .write (content )
219
+
220
+ def process_Result (self , result , command ):
187
221
tmp_list = re .split (r'\[COMMAND\]|\[PATH\]' ,result )
188
222
self .cwd = tmp_list [2 ].strip ('\r \n ' ).lstrip ()
189
223
cmd_Result = tmp_list [1 ].strip ('\r \n ' ).lstrip ()
190
224
self .prompt = "%s>" % self .cwd
191
225
print (cmd_Result + "\r \n " )
226
+
227
+ if self .logging == True :
228
+ content = "{} {}\r \n \r \n {}\r \n \r \n " .format (self .prompt , command , cmd_Result )
229
+ self .save_ToFile (content )
192
230
193
231
def default (self , line ):
194
232
FileName = str (uuid .uuid4 ()) + ".log"
@@ -207,15 +245,12 @@ def default(self, line):
207
245
tag , self .iWbemServices_Reuse_subscription = self .executer .ExecuteVBS (vbs_content = vbs , returnTag = True , BlockVerbose = True , iWbemServices = self .iWbemServices_Reuse_subscription ,return_iWbemServices = True )
208
246
209
247
# Wait 5 seconds for next step.
210
- for i in range (5 ,0 ,- 1 ):
211
- print (f"[+] Waiting { i } s for next step." , end = "\r " , flush = True )
212
- time .sleep (1 )
213
- print ("\r \n [+] Results: \r \n " )
214
-
248
+ self .interval_Timer (self .interval )
249
+
215
250
self .executer .remove_Event (tag , BlockVerbose = True , iWbemServices = self .iWbemServices_Reuse_subscription )
216
251
217
252
command_ResultObject , resp = self .iWbemServices_Reuse_cimv2 .GetObject ('{}.CreationClassName="{}"' .format (self .ClassName_StoreOutput , CMD_instanceID ))
218
253
record = dict (command_ResultObject .getProperties ())
219
254
result = base64 .b64decode (record ['DebugOptions' ]['value' ]).decode (self .codec , errors = 'replace' )
220
- self .process_Result (result )
255
+ self .process_Result (result , line )
221
256
0 commit comments