diff --git a/lib/msf/core/db_manager/module_cache.rb b/lib/msf/core/db_manager/module_cache.rb index cf2b2a99c6..b489ec8437 100644 --- a/lib/msf/core/db_manager/module_cache.rb +++ b/lib/msf/core/db_manager/module_cache.rb @@ -198,7 +198,7 @@ module Msf::DBManager::ModuleCache ActiveRecord::Base.connection_pool.with_connection do @query = Mdm::Module::Detail.all - + @archs = Set.new @authors = Set.new @names = Set.new @@ -207,10 +207,10 @@ module Msf::DBManager::ModuleCache @stances = Set.new @text = Set.new @types = Set.new - + value_set_by_keyword.each do |keyword, value_set| formatted_values = match_values(value_set) - + case keyword when 'app' formatted_values = value_set.collect { |value| @@ -244,7 +244,7 @@ module Msf::DBManager::ModuleCache end end end - + @query = @query.module_arch( @archs.to_a.flatten ) if @archs.any? @query = @query.module_author( @authors.to_a.flatten ) if @authors.any? @query = @query.module_name( @names.to_a.flatten ) if @names.any? @@ -253,7 +253,7 @@ module Msf::DBManager::ModuleCache @query = @query.module_type( @types.to_a.flatten ) if @types.any? @query = @query.module_stance( @stances.to_a.flatten ) if @stances.any? @query = @query.module_ref( @refs.to_a.flatten ) if @refs.any? - + @query.uniq end @@ -371,4 +371,4 @@ module Msf::DBManager::ModuleCache module_detail.save! end end -end \ No newline at end of file +end diff --git a/lib/msf/core/framework.rb b/lib/msf/core/framework.rb index b8e797c8ec..16fb498e54 100644 --- a/lib/msf/core/framework.rb +++ b/lib/msf/core/framework.rb @@ -229,6 +229,44 @@ class Framework } end + def search(match, verbose: true) + # Check if the database is usable + use_db = true + if @db + if !(@db.migrated && @db.modules_cached) + if verbose + print_warning("Module database cache not built yet, using slow search") + end + use_db = false + end + else + if verbose + print_warning("Database not connected, using slow search") + end + use_db = false + end + + # Used the database for search + if use_db + return @db.search_modules(match) + end + + # Do an in-place search + matches = [] + [ @exploits, @auxiliary, @post, @payloads, @nops, @encoders ].each do |mset| + mset.each do |m| + begin + o = mset.create(m[0]) + if o && !o.search_filter(match) + matches << o + end + rescue + end + end + end + matches + end + protected # @!attribute options diff --git a/lib/msf/ui/console/command_dispatcher/modules.rb b/lib/msf/ui/console/command_dispatcher/modules.rb index f065468eab..85601d0498 100644 --- a/lib/msf/ui/console/command_dispatcher/modules.rb +++ b/lib/msf/ui/console/command_dispatcher/modules.rb @@ -401,49 +401,9 @@ module Msf end } - matching_modules = [] - - # Check if the database is usable - use_db = true - if framework.db - if !(framework.db.migrated && framework.db.modules_cached) - print_warning("Module database cache not built yet, using slow search") - use_db = false - end - else - print_warning("Database not connected, using slow search") - use_db = false - end - - # Do the actual search - if use_db - framework.db.search_modules(match).each do |o| - matching_modules << o - end - else - [ - framework.exploits, - framework.auxiliary, - framework.post, - framework.payloads, - framework.nops, - framework.encoders - ].each do |mset| - mset.each do |m| - begin - o = mset.create(m[0]) - if o && !o.search_filter(match) - matching_modules << o - end - rescue - end - end - end - end - # Display the table of matches tbl = generate_module_table("Matching Modules", search_term) - matching_modules.each do |o| + framework.search(match, verbose: true).each do |o| tbl << [ o.fullname, o.disclosure_date.nil? ? "" : o.disclosure_date.strftime(DISCLOSURE_DATE_FORMAT), @@ -452,7 +412,6 @@ module Msf ] end print_line(tbl.to_s) - end #