Skip to content

Commit bc92b43

Browse files
committed
Update to metasploit_data_models 0.11.0
[#47979793]
1 parent a5648a8 commit bc92b43

File tree

9 files changed

+64
-112
lines changed

9 files changed

+64
-112
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ group :db do
1515
# Needed for Msf::DbManager
1616
gem 'activerecord'
1717
# Database models shared between framework and Pro.
18-
gem 'metasploit_data_models', '~> 0.7.1'
18+
gem 'metasploit_data_models', '~> 0.11.0'
1919
# Needed for module caching in Mdm::ModuleDetails
2020
gem 'pg', '>= 0.11'
2121
end

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ GEM
2323
i18n (0.6.1)
2424
json (1.7.7)
2525
metaclass (0.0.1)
26-
metasploit_data_models (0.7.1)
26+
metasploit_data_models (0.11.0)
2727
activerecord (>= 3.2.13)
2828
activesupport
2929
pg
@@ -65,7 +65,7 @@ DEPENDENCIES
6565
database_cleaner
6666
factory_girl (>= 4.1.0)
6767
json
68-
metasploit_data_models (~> 0.7.1)
68+
metasploit_data_models (~> 0.11.0)
6969
msgpack
7070
nokogiri
7171
pcaprub

Rakefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ else
3636
task :default => :spec
3737
end
3838

39+
# Require yard before loading metasploit_data_models rake tasks as the yard tasks won't be defined if
40+
# YARD is not defined when yard.rake is loaded.
41+
begin
42+
require 'yard'
43+
rescue LoadError
44+
puts "yard not in bundle, so can't set up yard tasks. " \
45+
"To generate documentation ensure to install the development group."
46+
47+
print_without = true
48+
end
49+
3950
begin
4051
require 'metasploit_data_models'
4152
rescue LoadError
@@ -58,14 +69,6 @@ else
5869
end
5970
end
6071

61-
begin
62-
require 'yard'
63-
rescue LoadError
64-
puts "yard not in bundle, so can't set up yard tasks. " \
65-
"To generate documentation ensure to install the development group."
66-
67-
print_without = true
68-
end
6972

7073

7174
if print_without

db/schema.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended to check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(:version => 20130412175040) do
14+
ActiveRecord::Schema.define(:version => 20130430162145) do
1515

1616
create_table "api_keys", :force => true do |t|
1717
t.text "token"
@@ -135,7 +135,7 @@
135135

136136
create_table "hosts", :force => true do |t|
137137
t.datetime "created_at"
138-
t.string "address", :limit => nil
138+
t.string "address", :limit => nil, :null => false
139139
t.string "mac"
140140
t.string "comm"
141141
t.string "name"
@@ -145,7 +145,7 @@
145145
t.string "os_sp"
146146
t.string "os_lang"
147147
t.string "arch"
148-
t.integer "workspace_id"
148+
t.integer "workspace_id", :null => false
149149
t.datetime "updated_at"
150150
t.text "purpose"
151151
t.string "info", :limit => 65536
@@ -157,14 +157,15 @@
157157
t.integer "service_count", :default => 0
158158
t.integer "host_detail_count", :default => 0
159159
t.integer "exploit_attempt_count", :default => 0
160+
t.integer "cred_count", :default => 0
160161
end
161162

162-
add_index "hosts", ["address"], :name => "index_hosts_on_address"
163163
add_index "hosts", ["name"], :name => "index_hosts_on_name"
164164
add_index "hosts", ["os_flavor"], :name => "index_hosts_on_os_flavor"
165165
add_index "hosts", ["os_name"], :name => "index_hosts_on_os_name"
166166
add_index "hosts", ["purpose"], :name => "index_hosts_on_purpose"
167167
add_index "hosts", ["state"], :name => "index_hosts_on_state"
168+
add_index "hosts", ["workspace_id", "address"], :name => "index_hosts_on_workspace_id_and_address", :unique => true
168169

169170
create_table "hosts_tags", :id => false, :force => true do |t|
170171
t.integer "host_id"

lib/msf/core/db_export.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def create_xml_element(key,value)
370370
# module_detail elements.
371371
# @return [void]
372372
def extract_module_detail_info(report_file)
373-
Mdm:Module::Detail.all.each do |m|
373+
Mdm::Module::Detail.all.each do |m|
374374
report_file.write("<module_detail>\n")
375375
m_id = m.attributes["id"]
376376

lib/msf/core/db_manager.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,16 @@ def update_all_module_details
404404
# Creates an Mdm::Module::Detail from a module instance.
405405
#
406406
# @param module_instance [Msf::Module] a metasploit module instance.
407+
# @raise [ActiveRecord::RecordInvalid] if Hash from {#module_to_details_hash} is invalid attributes for
408+
# Mdm::Module::Detail.
407409
# @return [void]
408410
def update_module_details(module_instance)
409411
return if not self.migrated
410412

411413
ActiveRecord::Base.connection_pool.with_connection do
412414
info = module_to_details_hash(module_instance)
413415
bits = info.delete(:bits) || []
414-
module_detail = Mdm::Module::Detail.create(info)
416+
module_detail = Mdm::Module::Detail.create!(info)
415417

416418
bits.each do |args|
417419
otype, vals = args
@@ -433,7 +435,7 @@ def update_module_details(module_instance)
433435
end
434436

435437
module_detail.ready = true
436-
module_detail.save
438+
module_detail.save!
437439
end
438440
end
439441

@@ -665,7 +667,7 @@ def search_modules(search_string)
665667
union_conditions << Mdm::Module::Detail.arel_table[:mtype].matches_any(formatted_values)
666668
when 'app'
667669
formatted_values = value_set.collect { |value|
668-
formatted_value = 'active'
670+
formatted_value = 'aggressive'
669671

670672
if value == 'client'
671673
formatted_value = 'passive'

spec/factories/mdm/module_details.rb

Lines changed: 5 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,9 @@
1-
FactoryGirl.define do
2-
type_directory_by_type = {
3-
'auxiliary' => 'auxiliary',
4-
'encoder' => 'encoders',
5-
'exploit' => 'exploits',
6-
'nop' => 'nops',
7-
'payload' => 'payloads',
8-
'post' => 'posts'
9-
}
10-
11-
sequence :mdm_module_detail_disclosure_date do |n|
12-
# @todo https://www.pivotaltracker.com/story/show/48450593
13-
Date.today - n
14-
end
15-
16-
sequence :mdm_module_detail_description do |n|
17-
"Module Description #{n}"
18-
end
19-
20-
sequence :mdm_module_detail_license do |n|
21-
"Module License v#{n}"
22-
end
23-
24-
privileges = [false, true]
25-
privilege_count = privileges.length
26-
27-
sequence :mdm_module_detail_privileged do |n|
28-
privileges[n % privilege_count]
29-
end
30-
31-
sequence :mdm_module_detail_mtime do |n|
32-
Time.now.utc - n.seconds
33-
end
34-
35-
types = type_directory_by_type.keys
36-
type_count = types.length
37-
38-
sequence :mdm_module_detail_mtype do |n|
39-
types[n % type_count]
40-
end
41-
42-
sequence :mdm_module_detail_name do |n|
43-
"Module Name #{n}"
44-
end
45-
46-
sequence :mdm_module_detail_rank do |n|
47-
100 * (n % 7)
48-
end
49-
50-
stances = ['active', 'passive']
51-
sequence :mdm_module_detail_stance, stances.cycle
52-
end
53-
54-
modules_pathname = Metasploit::Framework.root.join('modules')
55-
type_directory_by_type = {
56-
'auxiliary' => 'auxiliary',
57-
'encoder' => 'encoders',
58-
'exploit' => 'exploits',
59-
'nop' => 'nops',
60-
'payload' => 'payloads',
61-
'post' => 'posts'
62-
}
63-
641
FactoryGirl.modify do
652
factory :mdm_module_detail do
66-
description { generate :mdm_module_detail_description }
67-
disclosure_date { generate :mdm_module_detail_disclosure_date }
68-
license { generate :mdm_module_detail_license }
69-
mtime { generate :mdm_module_detail_mtime }
70-
mtype { generate :mdm_module_detail_mtype }
71-
privileged { generate :mdm_module_detail_privileged }
72-
name { generate :mdm_module_detail_name }
73-
rank { generate :mdm_module_detail_rank }
74-
refname { generate :mdm_module_detail_refname }
75-
fullname { "#{mtype}/#{refname}" }
76-
stance { generate :mdm_module_detail_stance }
77-
78-
file {
79-
type_directory = type_directory_by_type[mtype]
80-
81-
modules_pathname.join(
82-
type_directory,
83-
"#{refname}.rb"
84-
).to_path
85-
}
3+
ignore do
4+
root {
5+
Metasploit::Framework.root
6+
}
7+
end
868
end
879
end

spec/lib/msf/db_manager_spec.rb

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def purge_all_module_details
265265

266266
context 'with session responds to arch' do
267267
let(:arch) do
268-
'Arch'
268+
FactoryGirl.generate :mdm_host_arch
269269
end
270270

271271
before(:each) do
@@ -828,7 +828,7 @@ def remove_module_details
828828
end
829829

830830
before(:each) do
831-
['active', 'passive'].each do |stance|
831+
Mdm::Module::Detail::STANCES.each do |stance|
832832
FactoryGirl.create(:mdm_module_detail, :stance => stance)
833833
end
834834
end
@@ -852,11 +852,11 @@ def remove_module_details
852852
'server'
853853
end
854854

855-
it "should match Mdm::Module::Detail#stance 'active'" do
855+
it "should match Mdm::Module::Detail#stance 'aggressive'" do
856856
module_details.count.should > 0
857857

858858
module_details.all? { |module_detail|
859-
module_detail.stance == 'active'
859+
module_detail.stance == 'aggressive'
860860
}.should be_true
861861
end
862862
end
@@ -1469,8 +1469,8 @@ def loader.load_error(module_path, error)
14691469
update_module_details
14701470
end
14711471

1472-
it 'should call module_to_details_hash to get Mdm::Module::Detail attributs and association attributes' do
1473-
db_manager.should_receive(:module_to_details_hash).and_return({})
1472+
it 'should call module_to_details_hash to get Mdm::Module::Detail attributes and association attributes' do
1473+
db_manager.should_receive(:module_to_details_hash).and_call_original
14741474

14751475
update_module_details
14761476
end
@@ -1485,10 +1485,26 @@ def loader.load_error(module_path, error)
14851485
context 'module_to_details_hash' do
14861486
let(:module_to_details_hash) do
14871487
{
1488-
:refname => module_reference_name
1488+
:mtype => module_type,
1489+
:privileged => privileged,
1490+
:rank => rank,
1491+
:refname => module_reference_name,
1492+
:stance => stance
14891493
}
14901494
end
14911495

1496+
let(:privileged) do
1497+
FactoryGirl.generate :mdm_module_detail_privileged
1498+
end
1499+
1500+
let(:rank) do
1501+
FactoryGirl.generate :mdm_module_detail_rank
1502+
end
1503+
1504+
let(:stance) do
1505+
FactoryGirl.generate :mdm_module_detail_stance
1506+
end
1507+
14921508
before(:each) do
14931509
db_manager.stub(
14941510
:module_to_details_hash
@@ -1508,8 +1524,12 @@ def loader.load_error(module_path, error)
15081524
update_module_details
15091525
end
15101526

1527+
its(:mtype) { should == module_type }
1528+
its(:privileged) { should == privileged }
1529+
its(:rank) { should == rank }
15111530
its(:ready) { should == true }
15121531
its(:refname) { should == module_reference_name }
1532+
its(:stance) { should == stance }
15131533
end
15141534

15151535
context 'with :bits' do

spec/support/shared/examples/msf/db_manager/export/extract_module_detail_info_module_detail_child.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
module_detail.send(attribute_name)
1010
end
1111

12-
it "should have Mdm::Module::Detail##{attribute_name} present" do
13-
attribute.should be_present
12+
it "should not have Mdm::Module::Detail##{attribute_name} nil" do
13+
attribute.should_not be_nil
1414
end
1515

1616
it "should have Mdm::Module::Detail##{attribute_name} for #{child_node_name} content" do
17-
child_node.content.should == attribute.to_s
17+
if attribute == false
18+
child_node.content.should be_blank
19+
else
20+
child_node.content.should == attribute.to_s
21+
end
1822
end
1923
end

0 commit comments

Comments
 (0)