@@ -180,32 +180,30 @@ def bootstrap(datastore = {}, handler = nil)
180180 print_warning ( 'Meterpreter start up operations have been aborted. Use the session at your own risk.' )
181181 return nil
182182 end
183- # Unhook the process prior to loading stdapi to reduce logging/inspection by any AV/PSP
184- if datastore [ 'AutoUnhookProcess' ] == true
185- console . run_single ( 'load unhook' )
186- console . run_single ( 'unhook_pe' )
187- end
188-
189- unless datastore [ 'AutoLoadStdapi' ] == false
190-
191- session . load_stdapi
192-
193- unless datastore [ 'AutoSystemInfo' ] == false
194- session . load_session_info
195- end
196-
197- # only load priv on native windows
198- # TODO: abstract this too, to remove windows stuff
199- if session . platform == 'windows' && [ ARCH_X86 , ARCH_X64 ] . include? ( session . arch )
200- session . load_priv rescue nil
201- end
202- end
203-
183+ extensions = datastore [ 'AutoLoadExtensions' ] &.delete ( ' ' ) . split ( ',' ) || [ ]
184+
185+ # BEGIN: This should be removed on MSF 7
186+ # Unhook the process prior to loading stdapi to reduce logging/inspection by any AV/PSP (by default unhook is first, see meterpreter_options/windows.rb)
187+ extensions . push ( 'unhook' ) if datastore [ 'AutoUnhookProcess' ] && session . platform == 'windows'
188+ extensions . push ( 'stdapi' ) if datastore [ 'AutoLoadStdapi' ]
189+ extensions . push ( 'priv' ) if datastore [ 'AutoLoadStdapi' ] && session . platform == 'windows'
190+ extensions . push ( 'android' ) if session . platform == 'android'
191+ extensions = extensions . uniq
192+ # END
193+ original = console . disable_output
194+ console . disable_output = true
204195 # TODO: abstract this a little, perhaps a "post load" function that removes
205196 # platform-specific stuff?
206- if session . platform == 'android'
207- session . load_android
197+ extensions . each do |extension |
198+ begin
199+ console . run_single ( "load #{ extension } " )
200+ console . run_single ( 'unhook_pe' ) if extension == 'unhook'
201+ session . load_session_info if extension == 'stdapi' && datastore [ 'AutoSystemInfo' ]
202+ rescue => e
203+ print_warning ( "Failed loading extension #{ extension } " )
204+ end
208205 end
206+ console . disable_output = original
209207
210208 [ 'InitialAutoRunScript' , 'AutoRunScript' ] . each do |key |
211209 unless datastore [ key ] . nil? || datastore [ key ] . empty?
0 commit comments