add a framework-wide search method

bug/bundler_fix
Brent Cook 2017-06-24 15:09:32 -05:00
parent 8eceef18d9
commit e0695cbf9b
3 changed files with 45 additions and 48 deletions

View File

@ -198,7 +198,7 @@ module Msf::DBManager::ModuleCache
ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.connection_pool.with_connection do
@query = Mdm::Module::Detail.all @query = Mdm::Module::Detail.all
@archs = Set.new @archs = Set.new
@authors = Set.new @authors = Set.new
@names = Set.new @names = Set.new
@ -207,10 +207,10 @@ module Msf::DBManager::ModuleCache
@stances = Set.new @stances = Set.new
@text = Set.new @text = Set.new
@types = Set.new @types = Set.new
value_set_by_keyword.each do |keyword, value_set| value_set_by_keyword.each do |keyword, value_set|
formatted_values = match_values(value_set) formatted_values = match_values(value_set)
case keyword case keyword
when 'app' when 'app'
formatted_values = value_set.collect { |value| formatted_values = value_set.collect { |value|
@ -244,7 +244,7 @@ module Msf::DBManager::ModuleCache
end end
end end
end end
@query = @query.module_arch( @archs.to_a.flatten ) if @archs.any? @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_author( @authors.to_a.flatten ) if @authors.any?
@query = @query.module_name( @names.to_a.flatten ) if @names.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_type( @types.to_a.flatten ) if @types.any?
@query = @query.module_stance( @stances.to_a.flatten ) if @stances.any? @query = @query.module_stance( @stances.to_a.flatten ) if @stances.any?
@query = @query.module_ref( @refs.to_a.flatten ) if @refs.any? @query = @query.module_ref( @refs.to_a.flatten ) if @refs.any?
@query.uniq @query.uniq
end end
@ -371,4 +371,4 @@ module Msf::DBManager::ModuleCache
module_detail.save! module_detail.save!
end end
end end
end end

View File

@ -229,6 +229,44 @@ class Framework
} }
end 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 protected
# @!attribute options # @!attribute options

View File

@ -401,49 +401,9 @@ module Msf
end 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 # Display the table of matches
tbl = generate_module_table("Matching Modules", search_term) tbl = generate_module_table("Matching Modules", search_term)
matching_modules.each do |o| framework.search(match, verbose: true).each do |o|
tbl << [ tbl << [
o.fullname, o.fullname,
o.disclosure_date.nil? ? "" : o.disclosure_date.strftime(DISCLOSURE_DATE_FORMAT), o.disclosure_date.nil? ? "" : o.disclosure_date.strftime(DISCLOSURE_DATE_FORMAT),
@ -452,7 +412,6 @@ module Msf
] ]
end end
print_line(tbl.to_s) print_line(tbl.to_s)
end end
# #