Update to metasploit_data_models 0.7.1

[#47979793]
unstable
Luke Imhoff 2013-04-26 13:14:38 -05:00
parent 9207ed6532
commit 249a09cd52
15 changed files with 303 additions and 244 deletions

View File

@ -7,12 +7,12 @@ gem 'activerecord'
# Needed for some admin modules (scrutinizer_add_user.rb)
gem 'json'
# Database models shared between framework and Pro.
gem 'metasploit_data_models', '~> 0.6.14'
gem 'metasploit_data_models', '~> 0.7.1'
# Needed by msfgui and other rpc components
gem 'msgpack'
# Needed by anemone crawler
gem 'nokogiri'
# Needed for module caching in Mdm::ModuleDetails
# Needed for module caching in Mdm::Module::Details
gem 'pg', '>= 0.11'
# Needed by anemone crawler
gem 'robots'

View File

@ -23,7 +23,7 @@ GEM
i18n (0.6.1)
json (1.7.7)
metaclass (0.0.1)
metasploit_data_models (0.6.14)
metasploit_data_models (0.7.1)
activerecord (>= 3.2.13)
activesupport
pg
@ -65,7 +65,7 @@ DEPENDENCIES
database_cleaner
factory_girl (>= 4.1.0)
json
metasploit_data_models (~> 0.6.14)
metasploit_data_models (~> 0.7.1)
msgpack
nokogiri
pcaprub

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130228214900) do
ActiveRecord::Schema.define(:version => 20130412175040) do
create_table "api_keys", :force => true do |t|
t.text "token"
@ -223,26 +223,26 @@ ActiveRecord::Schema.define(:version => 20130228214900) do
end
create_table "module_actions", :force => true do |t|
t.integer "module_detail_id"
t.integer "detail_id"
t.text "name"
end
add_index "module_actions", ["module_detail_id"], :name => "index_module_actions_on_module_detail_id"
add_index "module_actions", ["detail_id"], :name => "index_module_actions_on_module_detail_id"
create_table "module_archs", :force => true do |t|
t.integer "module_detail_id"
t.integer "detail_id"
t.text "name"
end
add_index "module_archs", ["module_detail_id"], :name => "index_module_archs_on_module_detail_id"
add_index "module_archs", ["detail_id"], :name => "index_module_archs_on_module_detail_id"
create_table "module_authors", :force => true do |t|
t.integer "module_detail_id"
t.integer "detail_id"
t.text "name"
t.text "email"
end
add_index "module_authors", ["module_detail_id"], :name => "index_module_authors_on_module_detail_id"
add_index "module_authors", ["detail_id"], :name => "index_module_authors_on_module_detail_id"
create_table "module_details", :force => true do |t|
t.datetime "mtime"
@ -268,34 +268,34 @@ ActiveRecord::Schema.define(:version => 20130228214900) do
add_index "module_details", ["refname"], :name => "index_module_details_on_refname"
create_table "module_mixins", :force => true do |t|
t.integer "module_detail_id"
t.integer "detail_id"
t.text "name"
end
add_index "module_mixins", ["module_detail_id"], :name => "index_module_mixins_on_module_detail_id"
add_index "module_mixins", ["detail_id"], :name => "index_module_mixins_on_module_detail_id"
create_table "module_platforms", :force => true do |t|
t.integer "module_detail_id"
t.integer "detail_id"
t.text "name"
end
add_index "module_platforms", ["module_detail_id"], :name => "index_module_platforms_on_module_detail_id"
add_index "module_platforms", ["detail_id"], :name => "index_module_platforms_on_module_detail_id"
create_table "module_refs", :force => true do |t|
t.integer "module_detail_id"
t.integer "detail_id"
t.text "name"
end
add_index "module_refs", ["module_detail_id"], :name => "index_module_refs_on_module_detail_id"
add_index "module_refs", ["detail_id"], :name => "index_module_refs_on_module_detail_id"
add_index "module_refs", ["name"], :name => "index_module_refs_on_name"
create_table "module_targets", :force => true do |t|
t.integer "module_detail_id"
t.integer "detail_id"
t.integer "index"
t.text "name"
end
add_index "module_targets", ["module_detail_id"], :name => "index_module_targets_on_module_detail_id"
add_index "module_targets", ["detail_id"], :name => "index_module_targets_on_module_detail_id"
create_table "nexpose_consoles", :force => true do |t|
t.datetime "created_at", :null => false

View File

@ -780,7 +780,7 @@ class DBManager
if session.via_exploit == "exploit/multi/handler" and sess_data[:datastore]['ParentModule']
mod_fullname = sess_data[:datastore]['ParentModule']
mod_name = ::Mdm::ModuleDetail.find_by_fullname(mod_fullname).name
mod_name = ::Mdm::Module::Detail.find_by_fullname(mod_fullname).name
else
mod_name = mod.name
mod_fullname = mod.fullname

View File

@ -363,14 +363,14 @@ class Export
# directly, it is the caller's responsibility to add an opening and closing
# tag to report_file around the call to {#extract_module_detail_info}.
#
# Writes a module_detail element to the report_file for each
# Mdm::ModuleDetail.
# Writes a module_detail element to the report_file for each
# Mdm::Module::Detail.
#
# @param report_file [#write, #flush] IO stream to which to write the
# module_detail elements.
# @return [void]
def extract_module_detail_info(report_file)
Mdm::ModuleDetail.all.each do |m|
Mdm:Module::Detail.all.each do |m|
report_file.write("<module_detail>\n")
m_id = m.attributes["id"]

View File

@ -317,7 +317,7 @@ class DBManager
# @note Does nothing unless {#migrated} is +true+ and {#modules_caching} is
# +false+.
#
# Destroys all Mdm::ModuleDetails in the database.
# Destroys all Mdm::Module::Details in the database.
#
# @return [void]
def purge_all_module_details
@ -325,14 +325,14 @@ class DBManager
return if self.modules_caching
::ActiveRecord::Base.connection_pool.with_connection do
Mdm::ModuleDetail.destroy_all
Mdm::Module::Detail.destroy_all
end
end
# Destroys the old Mdm::ModuleDetail and creates a new Mdm::ModuleDetail for
# any module with an Mdm::ModuleDetail where the modification time of the
# Mdm::ModuleDetail#file differs from the Mdm::ModuleDetail#mtime. If the
# Mdm::ModuleDetail#file no only exists on disk, then the Mdm::ModuleDetail
# Destroys the old Mdm::Module::Detail and creates a new Mdm::Module::Detail for
# any module with an Mdm::Module::Detail where the modification time of the
# Mdm::Module::Detail#file differs from the Mdm::Module::Detail#mtime. If the
# Mdm::Module::Detail#file no only exists on disk, then the Mdm::Module::Detail
# is just destroyed without a new one being created.
#
# @return [void]
@ -350,7 +350,7 @@ class DBManager
refresh = []
skipped = []
Mdm::ModuleDetail.find_each do |md|
Mdm::Module::Detail.find_each do |md|
unless md.ready
refresh << md
@ -401,7 +401,7 @@ class DBManager
self.framework.cache_thread = nil
end
# Creates an Mdm::ModuleDetail from a module instance.
# Creates an Mdm::Module::Detail from a module instance.
#
# @param module_instance [Msf::Module] a metasploit module instance.
# @return [void]
@ -411,7 +411,7 @@ class DBManager
ActiveRecord::Base.connection_pool.with_connection do
info = module_to_details_hash(module_instance)
bits = info.delete(:bits) || []
module_detail = Mdm::ModuleDetail.create(info)
module_detail = Mdm::Module::Detail.create(info)
bits.each do |args|
otype, vals = args
@ -437,8 +437,8 @@ class DBManager
end
end
# Destroys Mdm::ModuleDetail if one exists for the given
# Mdm::ModuleDetail#mtype and Mdm::ModuleDetail#refname.
# Destroys Mdm::Module::Detail if one exists for the given
# Mdm::Module::Detail#mtype and Mdm::Module::Detail#refname.
#
# @param mtype [String] module type.
# @param refname [String] module reference name.
@ -447,7 +447,7 @@ class DBManager
return if not self.migrated
ActiveRecord::Base.connection_pool.with_connection do
Mdm::ModuleDetail.where(:mtype => mtype, :refname => refname).destroy_all
Mdm::Module::Detail.where(:mtype => mtype, :refname => refname).destroy_all
end
end
@ -538,7 +538,18 @@ class DBManager
res
end
# Wraps values in +'%'+ for Arel::Prediciation#matches_any and other match* methods that map to SQL +'LIKE'+ or
# +'ILIKE'+
#
# @param values [Set<String>, #each] a list of strings.
# @return [Arrray<String>] strings wrapped like %<string>%
def match_values(values)
wrapped_values = values.collect { |value|
"%#{value}%"
}
wrapped_values
end
# This provides a standard set of search filters for every module.
#
@ -561,97 +572,135 @@ class DBManager
#
# @param search_string [String] a string of space separated keyword pairs or
# free form text.
# @return [false] if search_string is +nil+
# @return [Array<Mdm::ModuleDetail>] module details that matched
# @return [[]] if search_string is +nil+
# @return [ActiveRecord::Relation] module details that matched
# +search_string+
def search_modules(search_string)
return false if not search_string
search_string ||= ''
search_string += " "
search_string += " "
# Split search terms by space, but allow quoted strings
terms = Shellwords.shellwords(search_string)
terms.delete('')
# Split search terms by space, but allow quoted strings
terms = Shellwords.shellwords(search_string)
terms.delete('')
# All terms are either included or excluded
value_set_by_keyword = Hash.new { |hash, keyword|
hash[keyword] = Set.new
}
# All terms are either included or excluded
res = {}
terms.each do |term|
keyword, value = term.split(':', 2)
terms.each do |t|
f,v = t.split(":", 2)
if not v
v = f
f = 'text'
end
next if v.length == 0
f.downcase!
v.downcase!
res[f] ||= [ ]
res[f] << v
end
unless value
value = keyword
keyword = 'text'
end
::ActiveRecord::Base.connection_pool.with_connection {
unless value.empty?
keyword.downcase!
where_q = []
where_v = []
value_set = value_set_by_keyword[keyword]
value_set.add value
end
end
res.keys.each do |kt|
res[kt].each do |kv|
kv = kv.downcase
case kt
when 'text'
xv = "%#{kv}%"
where_q << ' ( ' +
'module_details.fullname ILIKE ? OR module_details.name ILIKE ? OR module_details.description ILIKE ? OR ' +
'module_authors.name ILIKE ? OR module_actions.name ILIKE ? OR module_archs.name ILIKE ? OR ' +
'module_targets.name ILIKE ? OR module_platforms.name ILIKE ? OR module_refs.name ILIKE ?' +
') '
where_v << [ xv, xv, xv, xv, xv, xv, xv, xv, xv ]
when 'name'
xv = "%#{kv}%"
where_q << ' ( module_details.fullname ILIKE ? OR module_details.name ILIKE ? ) '
where_v << [ xv, xv ]
when 'author'
xv = "%#{kv}%"
where_q << ' ( module_authors.name ILIKE ? OR module_authors.email ILIKE ? ) '
where_v << [ xv, xv ]
when 'os','platform'
xv = "%#{kv}%"
where_q << ' ( module_platforms.name ILIKE ? OR module_targets.name ILIKE ? ) '
where_v << [ xv, xv ]
when 'type'
where_q << ' ( module_details.mtype = ? ) '
where_v << [ kv ]
when 'app'
where_q << ' ( module_details.stance = ? )'
where_v << [ ( kv == "client") ? "passive" : "active" ]
when 'ref'
where_q << ' ( module_refs.name ILIKE ? )'
where_v << [ '%' + kv + '%' ]
when 'cve','bid','osvdb','edb'
where_q << ' ( module_refs.name = ? )'
where_v << [ kt.upcase + '-' + kv ]
query = Mdm::Module::Detail.scoped
end
end
end
ActiveRecord::Base.connection_pool.with_connection do
# Although AREL supports taking the union or two queries, the ActiveRecord where syntax only supports
# intersection, so creating the where clause has to be delayed until all conditions can be or'd together and
# passed to one call ot where.
union_conditions = []
qry = Mdm::ModuleDetail.select("DISTINCT(module_details.*)").
joins(
"LEFT OUTER JOIN module_authors ON module_details.id = module_authors.module_detail_id " +
"LEFT OUTER JOIN module_actions ON module_details.id = module_actions.module_detail_id " +
"LEFT OUTER JOIN module_archs ON module_details.id = module_archs.module_detail_id " +
"LEFT OUTER JOIN module_refs ON module_details.id = module_refs.module_detail_id " +
"LEFT OUTER JOIN module_targets ON module_details.id = module_targets.module_detail_id " +
"LEFT OUTER JOIN module_platforms ON module_details.id = module_platforms.module_detail_id "
).
where(where_q.join(" AND "), *(where_v.flatten)).
# Compatibility for Postgres installations prior to 9.1 - doesn't have support for wildcard group by clauses
group("module_details.id, module_details.mtime, module_details.file, module_details.mtype, module_details.refname, module_details.fullname, module_details.name, module_details.rank, module_details.description, module_details.license, module_details.privileged, module_details.disclosure_date, module_details.default_target, module_details.default_action, module_details.stance, module_details.ready")
value_set_by_keyword.each do |keyword, value_set|
case keyword
when 'author'
formatted_values = match_values(value_set)
res = qry.all
query = query.includes(:authors)
module_authors = Mdm::Module::Author.arel_table
union_conditions << module_authors[:email].matches_any(formatted_values)
union_conditions << module_authors[:name].matches_any(formatted_values)
when 'name'
formatted_values = match_values(value_set)
}
end
module_details = Mdm::Module::Detail.arel_table
union_conditions << module_details[:fullname].matches_any(formatted_values)
union_conditions << module_details[:name].matches_any(formatted_values)
when 'os', 'platform'
formatted_values = match_values(value_set)
query = query.includes(:platforms)
union_conditions << Mdm::Module::Platform.arel_table[:name].matches_any(formatted_values)
query = query.includes(:targets)
union_conditions << Mdm::Module::Target.arel_table[:name].matches_any(formatted_values)
when 'text'
formatted_values = match_values(value_set)
module_details = Mdm::Module::Detail.arel_table
union_conditions << module_details[:description].matches_any(formatted_values)
union_conditions << module_details[:fullname].matches_any(formatted_values)
union_conditions << module_details[:name].matches_any(formatted_values)
query = query.includes(:actions)
union_conditions << Mdm::Module::Action.arel_table[:name].matches_any(formatted_values)
query = query.includes(:archs)
union_conditions << Mdm::Module::Arch.arel_table[:name].matches_any(formatted_values)
query = query.includes(:authors)
union_conditions << Mdm::Module::Author.arel_table[:name].matches_any(formatted_values)
query = query.includes(:platforms)
union_conditions << Mdm::Module::Platform.arel_table[:name].matches_any(formatted_values)
query = query.includes(:refs)
union_conditions << Mdm::Module::Ref.arel_table[:name].matches_any(formatted_values)
query = query.includes(:targets)
union_conditions << Mdm::Module::Target.arel_table[:name].matches_any(formatted_values)
when 'type'
formatted_values = match_values(value_set)
union_conditions << Mdm::Module::Detail.arel_table[:mtype].matches_any(formatted_values)
when 'app'
formatted_values = value_set.collect { |value|
formatted_value = 'active'
if value == 'client'
formatted_value = 'passive'
end
formatted_value
}
union_conditions << Mdm::Module::Detail.arel_table[:stance].eq_any(formatted_values)
when 'ref'
formatted_values = match_values(value_set)
query = query.includes(:refs)
union_conditions << Mdm::Module::Ref.arel_table[:name].matches_any(formatted_values)
when 'cve', 'bid', 'osvdb', 'edb'
formatted_values = value_set.collect { |value|
prefix = keyword.upcase
"#{prefix}-#{value}"
}
query = query.includes(:refs)
union_conditions << Mdm::Module::Ref.arel_table[:name].eq_any(formatted_values)
end
end
unioned_conditions = union_conditions.inject { |union, condition|
union.or(condition)
}
query = query.where(unioned_conditions).uniq
end
query
end
end
end

View File

@ -92,22 +92,22 @@ module Msf::ModuleManager::Cache
# @return (see #module_info_by_path_from_database!)
attr_accessor :module_info_by_path
# Return a module info from Mdm::ModuleDetails in database.
# Return a module info from Mdm::Module::Details in database.
#
# @note Also sets module_set(module_type)[module_reference_name] to Msf::SymbolicModule if it is not already set.
#
# @return [Hash{String => Hash{Symbol => Object}}] Maps path (Mdm::ModuleDetail#file) to module information. Module
# information is a Hash derived from Mdm::ModuleDetail. It includes :modification_time, :parent_path, :type,
# @return [Hash{String => Hash{Symbol => Object}}] Maps path (Mdm::Module::Detail#file) to module information. Module
# information is a Hash derived from Mdm::Module::Detail. It includes :modification_time, :parent_path, :type,
# :reference_name.
def module_info_by_path_from_database!
self.module_info_by_path = {}
if framework_migrated?
ActiveRecord::Base.connection_pool.with_connection do
# TODO record module parent_path in {Mdm::ModuleDetail} so it does not need to be derived from file.
# Use find_each so Mdm::ModuleDetails are returned in batches, which will
# TODO record module parent_path in Mdm::Module::Detail so it does not need to be derived from file.
# Use find_each so Mdm::Module::Details are returned in batches, which will
# handle the growing number of modules better than all.each.
Mdm::ModuleDetail.find_each do |module_detail|
Mdm::Module::Detail.find_each do |module_detail|
path = module_detail.file
type = module_detail.mtype
reference_name = module_detail.refname

View File

@ -28,7 +28,7 @@ describe Msf::DBManager::Export do
export.extract_module_detail_info(report_file)
end
context 'with Mdm::ModuleDetails' do
context 'with Mdm::Module::Details' do
let(:document) do
Nokogiri::XML(report_file.string)
end
@ -54,7 +54,7 @@ describe Msf::DBManager::Export do
report_file.write("</root>")
end
it 'should have module_detail tag for each Mdm::ModuleDetail' do
it 'should have module_detail tag for each Mdm::Module::Detail' do
nodes = root.xpath('module_detail')
nodes.length.should == module_detail_count
@ -72,11 +72,11 @@ describe Msf::DBManager::Export do
it_should_behave_like 'Msf::DBManager::Export#extract_module_detail_info module_detail child', 'description'
context '/disclosure-date' do
it 'should have Mdm::ModuleDetail#disclosure_date present' do
it 'should have Mdm::Module::Detail#disclosure_date present' do
module_detail.disclosure_date.should be_present
end
it 'should have Mdm::ModuleDetail#disclosure_date from disclosure-date content' do
it 'should have Mdm::Module::Detail#disclosure_date from disclosure-date content' do
node = module_detail_node.at_xpath('disclosure-date')
Date.parse(node.content).should == module_detail.disclosure_date
@ -97,7 +97,7 @@ describe Msf::DBManager::Export do
end
end
context 'without Mdm::ModuleDetails' do
context 'without Mdm::Module::Details' do
it 'should not write anything to report_file' do
extract_module_detail_info

View File

@ -62,10 +62,10 @@ describe Msf::DBManager do
true
end
it 'should not destroy Mdm::ModuleDetails' do
it 'should not destroy Mdm::Module::Details' do
expect {
purge_all_module_details
}.to_not change(Mdm::ModuleDetail, :count)
}.to_not change(Mdm::Module::Detail, :count)
end
end
@ -78,19 +78,19 @@ describe Msf::DBManager do
purge_all_module_details
end
it 'should destroy all Mdm::ModuleDetails' do
it 'should destroy all Mdm::Module::Details' do
expect {
purge_all_module_details
}.to change(Mdm::ModuleDetail, :count).by(-module_detail_count)
}.to change(Mdm::Module::Detail, :count).by(-module_detail_count)
end
end
end
context 'without migrated' do
it 'should not destroy Mdm::ModuleDetails' do
it 'should not destroy Mdm::Module::Details' do
expect {
purge_all_module_details
}.to_not change(Mdm::ModuleDetail, :count)
}.to_not change(Mdm::Module::Detail, :count)
end
end
end
@ -779,7 +779,7 @@ describe Msf::DBManager do
FactoryGirl.create(:mdm_module_detail)
end
context 'with matching Mdm::ModuleDetail' do
context 'with matching Mdm::Module::Detail' do
let(:mtype) do
module_detail.mtype
end
@ -788,34 +788,38 @@ describe Msf::DBManager do
module_detail.refname
end
it 'should destroy Mdm::ModuleDetail' do
it 'should destroy Mdm::Module::Detail' do
expect {
remove_module_details
}.to change(Mdm::ModuleDetail, :count).by(-1)
}.to change(Mdm::Module::Detail, :count).by(-1)
end
end
context 'without matching Mdm::ModuleDetail' do
it 'should not destroy Mdm::ModuleDetail' do
context 'without matching Mdm::Module::Detail' do
it 'should not destroy Mdm::Module::Detail' do
expect {
remove_module_details
}.to_not change(Mdm::ModuleDetail, :count)
}.to_not change(Mdm::Module::Detail, :count)
end
end
end
context 'without migrated' do
it 'should not destroy Mdm::ModuleDetail' do
it 'should not destroy Mdm::Module::Detail' do
expect {
remove_module_details
}.to_not change(Mdm::ModuleDetail, :count)
}.to_not change(Mdm::Module::Detail, :count)
end
end
end
context '#search_modules' do
subject(:module_details) do
db_manager.search_modules(search_string)
subject(:search_modules) do
db_manager.search_modules(search_string)
end
let(:module_details) do
search_modules.to_a
end
context 'with app keyword' do
@ -834,7 +838,7 @@ describe Msf::DBManager do
'client'
end
it "should match Mdm::ModuleDetail#stance 'passive'" do
it "should match Mdm::Module::Detail#stance 'passive'" do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -848,7 +852,7 @@ describe Msf::DBManager do
'server'
end
it "should match Mdm::ModuleDetail#stance 'active'" do
it "should match Mdm::Module::Detail#stance 'active'" do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -872,12 +876,12 @@ describe Msf::DBManager do
module_authors.first
end
context 'with Mdm::ModuleAuthor#email' do
context 'with Mdm::Module::Author#email' do
let(:author) do
target_module_author.email
end
it 'should match Mdm::ModuleAuthor#email' do
it 'should match Mdm::Module::Author#email' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -888,13 +892,13 @@ describe Msf::DBManager do
end
end
context 'with Mdm::ModuleAuthor#name' do
context 'with Mdm::Module::Author#name' do
let(:author) do
# use inspect to quote space in name
target_module_author.name.inspect
end
it 'should match Mdm::ModuleAuthor#name' do
it 'should match Mdm::Module::Author#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -906,9 +910,9 @@ describe Msf::DBManager do
end
end
it_should_behave_like 'Msf::DBManager#search_modules Mdm::ModuleRef#name keyword', :bid
it_should_behave_like 'Msf::DBManager#search_modules Mdm::ModuleRef#name keyword', :cve
it_should_behave_like 'Msf::DBManager#search_modules Mdm::ModuleRef#name keyword', :edb
it_should_behave_like 'Msf::DBManager#search_modules Mdm::Module::Ref#name keyword', :bid
it_should_behave_like 'Msf::DBManager#search_modules Mdm::Module::Ref#name keyword', :cve
it_should_behave_like 'Msf::DBManager#search_modules Mdm::Module::Ref#name keyword', :edb
context 'with name keyword' do
let(:search_string) do
@ -923,12 +927,12 @@ describe Msf::DBManager do
existing_module_details.first
end
context 'with Mdm::ModuleDetail#fullname' do
context 'with Mdm::Module::Detail#fullname' do
let(:name) do
target_module_detail.fullname
end
it 'should match Mdm::ModuleDetail#fullname' do
it 'should match Mdm::Module::Detail#fullname' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -937,12 +941,13 @@ describe Msf::DBManager do
end
end
context 'with Mdm::moduleDetail#name' do
context 'with Mdm::Module::Detail#name' do
let(:name) do
target_module_detail.name
# use inspect so spaces are inside quotes
target_module_detail.name.inspect
end
it 'should match Mdm::ModuleDetail#name' do
it 'should match Mdm::Module::Detail#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -952,11 +957,11 @@ describe Msf::DBManager do
end
end
it_should_behave_like 'Msf::DBManager#search_modules Mdm::ModulePlatform#name or Mdm::ModuleTarget#name keyword', :os
it_should_behave_like 'Msf::DBManager#search_modules Mdm::Module::Platform#name or Mdm::Module::Target#name keyword', :os
it_should_behave_like 'Msf::DBManager#search_modules Mdm::ModuleRef#name keyword', :osvdb
it_should_behave_like 'Msf::DBManager#search_modules Mdm::Module::Ref#name keyword', :osvdb
it_should_behave_like 'Msf::DBManager#search_modules Mdm::ModulePlatform#name or Mdm::ModuleTarget#name keyword', :platform
it_should_behave_like 'Msf::DBManager#search_modules Mdm::Module::Platform#name or Mdm::Module::Target#name keyword', :platform
context 'with ref keyword' do
let(:ref) do
@ -964,19 +969,20 @@ describe Msf::DBManager do
end
let(:search_string) do
"ref:#{ref}"
# use inspect to quote spaces in string
"ref:#{ref.inspect}"
end
let!(:module_ref) do
FactoryGirl.create(:mdm_module_ref)
end
context 'with Mdm::ModuleRef#name' do
context 'with Mdm::Module::Ref#name' do
let(:ref) do
module_ref.name
end
it 'should match Mdm::ModuleRef#name' do
it 'should match Mdm::Module::Ref#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -987,8 +993,8 @@ describe Msf::DBManager do
end
end
context 'without Mdm::moduleRef#name' do
it 'should not match Mdm::ModuleRef#name' do
context 'without Mdm::Module::Ref#name' do
it 'should not match Mdm::Module::Ref#name' do
module_details.count.should == 0
end
end
@ -1011,12 +1017,12 @@ describe Msf::DBManager do
FactoryGirl.create_list(:mdm_module_detail, 2)
end
context 'with Mdm::ModuleRef#name' do
context 'with Mdm::Module::Ref#name' do
let(:type) do
target_module_detail.mtype
end
it 'should match Mdm::ModuleDetail#mtype' do
it 'should match Mdm::Module::Detail#mtype' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -1025,15 +1031,15 @@ describe Msf::DBManager do
end
end
context 'without Mdm::ModuleDetail#mtype' do
it 'should not match Mdm::ModuleDetail#mtype' do
context 'without Mdm::Module::Detail#mtype' do
it 'should not match Mdm::Module::Detail#mtype' do
module_details.count.should == 0
end
end
end
context 'without keyword' do
context 'with Mdm::ModuleAction#name' do
context 'with Mdm::Module::Action#name' do
let(:search_string) do
module_action.name
end
@ -1042,7 +1048,7 @@ describe Msf::DBManager do
FactoryGirl.create(:mdm_module_action)
end
it 'should match Mdm::ModuleAction#name' do
it 'should match Mdm::Module::Action#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -1053,7 +1059,7 @@ describe Msf::DBManager do
end
end
context 'with Mdm::ModuleArch#name' do
context 'with Mdm::Module::Arch#name' do
let(:search_string) do
module_arch.name
end
@ -1062,7 +1068,7 @@ describe Msf::DBManager do
FactoryGirl.create(:mdm_module_arch)
end
it 'should match Mdm::ModuleArch#name' do
it 'should match Mdm::Module::Arch#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -1073,7 +1079,7 @@ describe Msf::DBManager do
end
end
context 'with Mdm::ModuleAuthor#name' do
context 'with Mdm::Module::Author#name' do
let(:search_string) do
module_author.name
end
@ -1082,7 +1088,7 @@ describe Msf::DBManager do
FactoryGirl.create(:mdm_module_author)
end
it 'should match Mdm::ModuleAuthor#name' do
it 'should match Mdm::Module::Author#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -1093,7 +1099,7 @@ describe Msf::DBManager do
end
end
context 'with Mdm::ModuleDetail' do
context 'with Mdm::Module::Detail' do
let(:target_module_detail) do
all_module_details.first
end
@ -1104,14 +1110,15 @@ describe Msf::DBManager do
context 'with #description' do
let(:search_string) do
target_module_detail.description
# use inspect to quote spaces in string
target_module_detail.description.inspect
end
it 'should match Mdm::ModuleDetail#description' do
it 'should match Mdm::Module::Detail#description' do
module_details.count.should == 1
module_details.all? { |module_detail|
module_detail.description == search_string
module_detail.description == target_module_detail.description
}.should be_true
end
end
@ -1121,7 +1128,7 @@ describe Msf::DBManager do
target_module_detail.fullname
end
it 'should match Mdm::ModuleDetail#fullname' do
it 'should match Mdm::Module::Detail#fullname' do
module_details.count.should == 1
module_details.all? { |module_detail|
@ -1132,20 +1139,21 @@ describe Msf::DBManager do
context 'with #name' do
let(:search_string) do
target_module_detail.name
# use inspect to quote spaces in string
target_module_detail.name.inspect
end
it 'should match Mdm::ModuleDetail#name' do
it 'should match Mdm::Module::Detail#name' do
module_details.count.should == 1
module_details.all? { |module_detail|
module_detail.name == search_string
module_detail.name == target_module_detail.name
}.should be_true
end
end
end
context 'with Mdm::ModulePlatform#name' do
context 'with Mdm::Module::Platform#name' do
let(:search_string) do
module_platform.name
end
@ -1154,7 +1162,7 @@ describe Msf::DBManager do
FactoryGirl.create(:mdm_module_platform)
end
it 'should match Mdm::ModulePlatform#name' do
it 'should match Mdm::Module::Platform#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -1165,7 +1173,7 @@ describe Msf::DBManager do
end
end
context 'with Mdm::ModuleRef#name' do
context 'with Mdm::Module::Ref#name' do
let(:search_string) do
module_ref.name
end
@ -1174,7 +1182,7 @@ describe Msf::DBManager do
FactoryGirl.create(:mdm_module_ref)
end
it 'should match Mdm::ModuleRef#name' do
it 'should match Mdm::Module::Ref#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -1185,7 +1193,7 @@ describe Msf::DBManager do
end
end
context 'with Mdm::ModuleTarget#name' do
context 'with Mdm::Module::Target#name' do
let(:search_string) do
module_target.name
end
@ -1194,7 +1202,7 @@ describe Msf::DBManager do
FactoryGirl.create(:mdm_module_target)
end
it 'should match Mdm::ModuleTarget#name' do
it 'should match Mdm::Module::Target#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -1282,7 +1290,7 @@ describe Msf::DBManager do
ActiveRecord::Base.connection_pool.should_receive(:with_connection).ordered.and_call_original
end
context 'with Mdm::ModuleDetails' do
context 'with Mdm::Module::Details' do
let(:module_pathname) do
parent_pathname.join(
'exploits',
@ -1332,8 +1340,8 @@ describe Msf::DBManager do
true
end
context 'with existing Mdm::ModuleDetail#file' do
context 'with same Mdm::ModuleDetail#mtime and File.mtime' do
context 'with existing Mdm::Module::Detail#file' do
context 'with same Mdm::Module::Detail#mtime and File.mtime' do
it 'should not update module details' do
db_manager.should_not_receive(:update_module_details)
@ -1341,7 +1349,7 @@ describe Msf::DBManager do
end
end
context 'without same Mdm::ModuleDetail#mtime and File.mtime' do
context 'without same Mdm::Module::Detail#mtime and File.mtime' do
let(:modification_time) do
# +1 as rand can return 0 and the time must be different for
# this context.
@ -1353,7 +1361,7 @@ describe Msf::DBManager do
end
# Emulates a module being removed or renamed
context 'without existing Mdm::ModuleDetail#file' do
context 'without existing Mdm::Module::Detail#file' do
# have to compute modification manually since the
# `module_pathname` refers to a non-existent file and
# `module_pathname.mtime` would error.
@ -1461,16 +1469,16 @@ describe Msf::DBManager do
update_module_details
end
it 'should call module_to_details_hash to get Mdm::ModuleDetail attributs and association attributes' do
it 'should call module_to_details_hash to get Mdm::Module::Detail attributs and association attributes' do
db_manager.should_receive(:module_to_details_hash).and_return({})
update_module_details
end
it 'should create an Mdm::ModuleDetail' do
it 'should create an Mdm::Module::Detail' do
expect {
update_module_details
}.to change(Mdm::ModuleDetail, :count).by(1)
}.to change(Mdm::Module::Detail, :count).by(1)
end
@ -1491,9 +1499,9 @@ describe Msf::DBManager do
)
end
context 'Mdm::ModuleDetail' do
context 'Mdm::Module::Detail' do
subject(:module_detail) do
Mdm::ModuleDetail.last
Mdm::Module::Detail.last
end
before(:each) do
@ -1527,19 +1535,19 @@ describe Msf::DBManager do
]
end
it 'should create an Mdm::ModuleAction' do
it 'should create an Mdm::Module::Action' do
expect {
update_module_details
}.to change(Mdm::ModuleAction, :count).by(1)
}.to change(Mdm::Module::Action, :count).by(1)
end
context 'Mdm::ModuleAction' do
context 'Mdm::Module::Action' do
subject(:module_action) do
module_detail.actions.last
end
let(:module_detail) do
Mdm::ModuleDetail.last
Mdm::Module::Detail.last
end
before(:each) do
@ -1564,19 +1572,19 @@ describe Msf::DBManager do
]
end
it 'should create an Mdm::ModuleArch' do
it 'should create an Mdm::Module::Arch' do
expect {
update_module_details
}.to change(Mdm::ModuleArch, :count).by(1)
}.to change(Mdm::Module::Arch, :count).by(1)
end
context 'Mdm::ModuleArch' do
context 'Mdm::Module::Arch' do
subject(:module_arch) do
module_detail.archs.last
end
let(:module_detail) do
Mdm::ModuleDetail.last
Mdm::Module::Detail.last
end
before(:each) do
@ -1606,19 +1614,19 @@ describe Msf::DBManager do
]
end
it 'should create an Mdm::ModuleAuthor' do
it 'should create an Mdm::Module::Author' do
expect {
update_module_details
}.to change(Mdm::ModuleAuthor, :count).by(1)
}.to change(Mdm::Module::Author, :count).by(1)
end
context 'Mdm::ModuleAuthor' do
context 'Mdm::Module::Author' do
subject(:module_author) do
module_detail.authors.last
end
let(:module_detail) do
Mdm::ModuleDetail.last
Mdm::Module::Detail.last
end
before(:each) do
@ -1644,19 +1652,19 @@ describe Msf::DBManager do
FactoryGirl.generate :mdm_module_platform_name
end
it 'should create an Mdm::ModulePlatform' do
it 'should create an Mdm::Module::Platform' do
expect {
update_module_details
}.to change(Mdm::ModulePlatform, :count).by(1)
}.to change(Mdm::Module::Platform, :count).by(1)
end
context 'Mdm::ModulePlatform' do
context 'Mdm::Module::Platform' do
subject(:module_platform) do
module_detail.platforms.last
end
let(:module_detail) do
Mdm::ModuleDetail.last
Mdm::Module::Detail.last
end
before(:each) do
@ -1681,19 +1689,19 @@ describe Msf::DBManager do
FactoryGirl.generate :mdm_module_ref_name
end
it 'should create an Mdm::ModuleRef' do
it 'should create an Mdm::Module::Ref' do
expect {
update_module_details
}.to change(Mdm::ModuleRef, :count).by(1)
}.to change(Mdm::Module::Ref, :count).by(1)
end
context 'Mdm::ModuleRef' do
context 'Mdm::Module::Ref' do
subject(:module_ref) do
module_detail.refs.last
end
let(:module_detail) do
Mdm::ModuleDetail.last
Mdm::Module::Detail.last
end
before(:each) do
@ -1723,19 +1731,19 @@ describe Msf::DBManager do
FactoryGirl.generate :mdm_module_target_name
end
it 'should create an Mdm::ModuleTarget' do
it 'should create an Mdm::Module::Target' do
expect {
update_module_details
}.to change(Mdm::ModuleTarget, :count).by(1)
}.to change(Mdm::Module::Target, :count).by(1)
end
context 'Mdm::ModuleTarget' do
context 'Mdm::Module::Target' do
subject(:module_target) do
module_detail.targets.last
end
let(:module_detail) do
Mdm::ModuleDetail.last
Mdm::Module::Detail.last
end
before(:each) do
@ -1751,10 +1759,10 @@ describe Msf::DBManager do
end
context 'without migrated' do
it 'should not create an Mdm::ModuleDetail' do
it 'should not create an Mdm::Module::Detail' do
expect {
update_module_details
}.to_not change(Mdm::ModuleDetail, :count)
}.to_not change(Mdm::Module::Detail, :count)
end
end
end

View File

@ -42,7 +42,7 @@ describe Msf::Ui::Console::CommandDispatcher::Core do
search_modules_sql
end
context 'with matching Mdm::ModuleDetails' do
context 'with matching Mdm::Module::Details' do
let(:match) do
module_detail.fullname
end

View File

@ -9,11 +9,11 @@ shared_examples_for 'Msf::DBManager::Export#extract_module_detail_info module_de
module_detail.send(attribute_name)
end
it "should have Mdm::ModuleDetail##{attribute_name} present" do
it "should have Mdm::Module::Detail##{attribute_name} present" do
attribute.should be_present
end
it "should have Mdm::ModuleDetail##{attribute_name} for #{child_node_name} content" do
it "should have Mdm::Module::Detail##{attribute_name} for #{child_node_name} content" do
child_node.content.should == attribute.to_s
end
end

View File

@ -1,4 +1,4 @@
shared_examples_for 'Msf::DBManager#search_modules Mdm::ModulePlatform#name or Mdm::ModuleTarget#name keyword' do |keyword|
shared_examples_for 'Msf::DBManager#search_modules Mdm::Module::Platform#name or Mdm::Module::Target#name keyword' do |keyword|
context "with #{keyword} keyword" do
let(:search_string) do
"#{keyword}:#{name}"
@ -12,33 +12,35 @@ shared_examples_for 'Msf::DBManager#search_modules Mdm::ModulePlatform#name or M
FactoryGirl.create(:mdm_module_target)
end
context 'with Mdm::ModulePlatform#name' do
context 'with Mdm::Module::Platform#name' do
let(:name) do
module_platform.name
# use inspect to quote spaces in string
module_platform.name.inspect
end
it 'should find matching Mdm::ModulePlatform#name' do
it 'should find matching Mdm::Module::Platform#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
module_detail.platforms.any? { |module_platform|
module_platform.name == name
module_platform.name == self.module_platform.name
}
}.should be_true
end
end
context 'with Mdm::ModuleTarget#name' do
context 'with Mdm::Module::Target#name' do
let(:name) do
module_target.name
# use inspect to quote spaces in string
module_target.name.inspect
end
it 'should find matching Mdm::ModuleTarget#name' do
it 'should find matching Mdm::Module::Target#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
module_detail.targets.any? { |module_target|
module_target.name == name
module_target.name == self.module_target.name
}
}.should be_true
end

View File

@ -1,4 +1,4 @@
shared_examples_for 'Msf::DBManager#search_modules Mdm::ModuleRef#name keyword' do |keyword|
shared_examples_for 'Msf::DBManager#search_modules Mdm::Module::Ref#name keyword' do |keyword|
context "with #{keyword} keyword" do
let(keyword) do
1
@ -17,14 +17,14 @@ shared_examples_for 'Msf::DBManager#search_modules Mdm::ModuleRef#name keyword'
end
name_prefix = "#{keyword.to_s.upcase}-"
context_suffix = "Mdm::ModuleRef#name starting with #{name_prefix.inspect}"
context_suffix = "Mdm::Module::Ref#name starting with #{name_prefix.inspect}"
context "with #{context_suffix}" do
let(:name) do
"#{name_prefix}#{send(keyword)}"
end
it 'should match Mdm::ModuleRef#name' do
it 'should match Mdm::Module::Ref#name' do
module_details.count.should > 0
module_details.all? { |module_detail|
@ -36,7 +36,7 @@ shared_examples_for 'Msf::DBManager#search_modules Mdm::ModuleRef#name keyword'
end
context "without #{context_suffix}" do
it 'should not match Mdm::ModuleRef#name' do
it 'should not match Mdm::Module::Ref#name' do
module_details.count.should == 0
end
end

View File

@ -1,9 +1,9 @@
shared_examples_for 'Msf::DBManager#update_all_module_details refresh' do
it 'should destroy Mdm::ModuleDetail' do
it 'should destroy Mdm::Module::Detail' do
expect {
update_all_module_details
}.to change(Mdm::ModuleDetail, :count).by(-1)
}.to change(Mdm::Module::Detail, :count).by(-1)
end
context 'with cached module in Msf::ModuleSet' do
@ -21,13 +21,13 @@ shared_examples_for 'Msf::DBManager#update_all_module_details refresh' do
}
end
it 'should create instance of module corresponding to Mdm::ModuleDetail' do
it 'should create instance of module corresponding to Mdm::Module::Detail' do
module_set.should_receive(:create).with(module_detail.refname)
update_all_module_details
end
it 'should call update_module_details to create a new Mdm::ModuleDetail from the module instance returned by create' do
it 'should call update_module_details to create a new Mdm::Module::Detail from the module instance returned by create' do
db_manager.should_receive(:update_module_details) do |module_instance|
module_instance.should be_a Msf::Module
module_instance.type.should == module_detail.mtype

View File

@ -277,8 +277,8 @@ shared_examples_for 'Msf::ModuleManager::Cache' do
module_info_by_path_from_database!
end
it 'should use ActiveRecord::Batches#find_each to enumerate Mdm::ModuleDetails in batches' do
Mdm::ModuleDetail.should_receive(:find_each)
it 'should use ActiveRecord::Batches#find_each to enumerate Mdm::Module::Details in batches' do
Mdm::Module::Detail.should_receive(:find_each)
module_info_by_path_from_database!
end