@@ -313,6 +313,7 @@ def __init__(self, socket=None):
313
313
self .driver = 'tcp'
314
314
elif HTTP_CONNECTION_URL :
315
315
self .driver = 'http'
316
+ self .last_registered_extension = None
316
317
self .extension_functions = {}
317
318
self .channels = {}
318
319
self .interact_channels = []
@@ -331,6 +332,10 @@ def driver_init_http(self):
331
332
urllib .install_opener (opener )
332
333
self ._http_last_seen = time .time ()
333
334
335
+ def register_extension (self , extension_name ):
336
+ self .last_registered_extension = extension_name
337
+ return self .last_registered_extension
338
+
334
339
def register_function (self , func ):
335
340
self .extension_functions [func .__name__ ] = func
336
341
return func
@@ -485,15 +490,19 @@ def _core_loadlib(self, request, response):
485
490
data_tlv = packet_get_tlv (request , TLV_TYPE_DATA )
486
491
if (data_tlv ['type' ] & TLV_META_TYPE_COMPRESSED ) == TLV_META_TYPE_COMPRESSED :
487
492
return ERROR_FAILURE
488
- preloadlib_methods = list (self .extension_functions .keys ())
493
+
494
+ self .last_registered_extension = None
489
495
symbols_for_extensions = {'meterpreter' :self }
490
496
symbols_for_extensions .update (EXPORTED_SYMBOLS )
491
497
i = code .InteractiveInterpreter (symbols_for_extensions )
492
498
i .runcode (compile (data_tlv ['value' ], '' , 'exec' ))
493
- postloadlib_methods = list (self .extension_functions .keys ())
494
- new_methods = list (filter (lambda x : x not in preloadlib_methods , postloadlib_methods ))
495
- for method in new_methods :
496
- response += tlv_pack (TLV_TYPE_METHOD , method )
499
+ extension_name = self .last_registered_extension
500
+
501
+ if extension_name :
502
+ check_extension = lambda x : x .startswith (extension_name ) or x .startswith ('channel_open_' + extension_name )
503
+ lib_methods = list (filter (check_extension , list (self .extension_functions .keys ())))
504
+ for method in lib_methods :
505
+ response += tlv_pack (TLV_TYPE_METHOD , method )
497
506
return ERROR_SUCCESS , response
498
507
499
508
def _core_shutdown (self , request , response ):
0 commit comments