@@ -146,7 +146,7 @@ def packet_enum_tlvs(pkt, tlv_type = None):
146
146
if (tlv_type == None ) or ((tlv [1 ] & ~ TLV_META_TYPE_COMPRESSED ) == tlv_type ):
147
147
val = pkt [offset + 8 :(offset + 8 + (tlv [0 ] - 8 ))]
148
148
if (tlv [1 ] & TLV_META_TYPE_STRING ) == TLV_META_TYPE_STRING :
149
- val = val .split (NULL_BYTE , 1 )[0 ]
149
+ val = str ( val .split (NULL_BYTE , 1 )[0 ])
150
150
elif (tlv [1 ] & TLV_META_TYPE_UINT ) == TLV_META_TYPE_UINT :
151
151
val = struct .unpack ('>I' , val )[0 ]
152
152
elif (tlv [1 ] & TLV_META_TYPE_BOOL ) == TLV_META_TYPE_BOOL :
@@ -190,6 +190,15 @@ def tlv_pack(*args):
190
190
data = struct .pack ('>II' , 8 + len (value ), tlv ['type' ]) + value
191
191
return data
192
192
193
+ #@export
194
+ class MeterpreterFile (object ):
195
+ def __init__ (self , file_obj ):
196
+ self .file_obj = file_obj
197
+
198
+ def __getattr__ (self , name ):
199
+ return getattr (self .file_obj , name )
200
+ export (MeterpreterFile )
201
+
193
202
#@export
194
203
class MeterpreterSocket (object ):
195
204
def __init__ (self , sock ):
@@ -271,6 +280,7 @@ def register_function_windll(self, func):
271
280
return func
272
281
273
282
def add_channel (self , channel ):
283
+ assert (isinstance (channel , (subprocess .Popen , MeterpreterFile , MeterpreterSocket )))
274
284
idx = 0
275
285
while idx in self .channels :
276
286
idx += 1
@@ -392,10 +402,10 @@ def _core_channel_close(self, request, response):
392
402
if channel_id not in self .channels :
393
403
return ERROR_FAILURE , response
394
404
channel = self .channels [channel_id ]
395
- if isinstance (channel , file ):
396
- channel .close ()
397
- elif isinstance (channel , subprocess .Popen ):
405
+ if isinstance (channel , subprocess .Popen ):
398
406
channel .kill ()
407
+ elif isinstance (channel , MeterpreterFile ):
408
+ channel .close ()
399
409
elif isinstance (channel , MeterpreterSocket ):
400
410
channel .close ()
401
411
else :
@@ -411,7 +421,7 @@ def _core_channel_eof(self, request, response):
411
421
return ERROR_FAILURE , response
412
422
channel = self .channels [channel_id ]
413
423
result = False
414
- if isinstance (channel , file ):
424
+ if isinstance (channel , MeterpreterFile ):
415
425
result = channel .tell () >= os .fstat (channel .fileno ()).st_size
416
426
response += tlv_pack (TLV_TYPE_BOOL , result )
417
427
return ERROR_SUCCESS , response
@@ -438,13 +448,13 @@ def _core_channel_read(self, request, response):
438
448
return ERROR_FAILURE , response
439
449
channel = self .channels [channel_id ]
440
450
data = ''
441
- if isinstance (channel , file ):
442
- data = channel .read (length )
443
- elif isinstance (channel , STDProcess ):
451
+ if isinstance (channel , STDProcess ):
444
452
if channel .poll () != None :
445
453
self .handle_dead_resource_channel (channel_id )
446
454
if channel .stdout_reader .is_read_ready ():
447
455
data = channel .stdout_reader .read (length )
456
+ elif isinstance (channel , MeterpreterFile ):
457
+ data = channel .read (length )
448
458
elif isinstance (channel , MeterpreterSocket ):
449
459
data = channel .recv (length )
450
460
else :
@@ -460,13 +470,13 @@ def _core_channel_write(self, request, response):
460
470
return ERROR_FAILURE , response
461
471
channel = self .channels [channel_id ]
462
472
l = len (channel_data )
463
- if isinstance (channel , file ):
464
- channel .write (channel_data )
465
- elif isinstance (channel , subprocess .Popen ):
473
+ if isinstance (channel , subprocess .Popen ):
466
474
if channel .poll () != None :
467
475
self .handle_dead_resource_channel (channel_id )
468
476
return ERROR_FAILURE , response
469
477
channel .stdin .write (channel_data )
478
+ elif isinstance (channel , MeterpreterFile ):
479
+ channel .write (channel_data )
470
480
elif isinstance (channel , MeterpreterSocket ):
471
481
try :
472
482
l = channel .send (channel_data )
@@ -487,7 +497,7 @@ def create_response(self, request):
487
497
reqid_tlv = packet_get_tlv (request , TLV_TYPE_REQUEST_ID )
488
498
resp += tlv_pack (reqid_tlv )
489
499
490
- handler_name = str ( method_tlv ['value' ])
500
+ handler_name = method_tlv ['value' ]
491
501
if handler_name in self .extension_functions :
492
502
handler = self .extension_functions [handler_name ]
493
503
try :
0 commit comments