metasploit_data_models 0.7.0 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +1 -0
  3. data/app/models/mdm/host.rb +352 -26
  4. data/app/models/mdm/loot.rb +72 -7
  5. data/app/models/mdm/{module_action.rb → module/action.rb} +3 -3
  6. data/app/models/mdm/{module_arch.rb → module/arch.rb} +3 -3
  7. data/app/models/mdm/{module_author.rb → module/author.rb} +3 -3
  8. data/app/models/mdm/module/detail.rb +280 -0
  9. data/app/models/mdm/{module_mixin.rb → module/mixin.rb} +3 -3
  10. data/app/models/mdm/{module_platform.rb → module/platform.rb} +3 -3
  11. data/app/models/mdm/module/ref.rb +48 -0
  12. data/app/models/mdm/{module_target.rb → module/target.rb} +3 -3
  13. data/app/models/mdm/note.rb +61 -6
  14. data/app/models/mdm/ref.rb +39 -1
  15. data/app/models/mdm/service.rb +85 -7
  16. data/app/models/mdm/session.rb +100 -6
  17. data/app/models/mdm/vuln.rb +104 -24
  18. data/db/migrate/20130228214900_change_required_columns_to_null_false_in_web_vulns.rb +1 -17
  19. data/db/migrate/20130412154159_change_foreign_key_in_module_actions.rb +25 -0
  20. data/db/migrate/20130412171844_change_foreign_key_in_module_archs.rb +25 -0
  21. data/db/migrate/20130412173121_change_foreign_key_in_module_authors.rb +25 -0
  22. data/db/migrate/20130412173640_change_foreign_key_in_module_mixins.rb +25 -0
  23. data/db/migrate/20130412174254_change_foreign_key_in_module_platforms.rb +25 -0
  24. data/db/migrate/20130412174719_change_foreign_key_in_module_refs.rb +25 -0
  25. data/db/migrate/20130412175040_change_foreign_key_in_module_targets.rb +25 -0
  26. data/db/migrate/20130430151353_change_required_columns_to_null_false_in_hosts.rb +11 -0
  27. data/db/migrate/20130430162145_enforce_address_uniqueness_in_workspace_in_hosts.rb +23 -0
  28. data/lib/mdm/module.rb +4 -0
  29. data/lib/metasploit_data_models.rb +1 -0
  30. data/lib/metasploit_data_models/change_required_columns_to_null_false.rb +23 -0
  31. data/lib/metasploit_data_models/version.rb +1 -1
  32. data/spec/app/models/mdm/host_spec.rb +411 -0
  33. data/spec/app/models/mdm/host_tag_spec.rb +13 -0
  34. data/spec/app/models/mdm/{module_action_spec.rb → module/action_spec.rb} +6 -6
  35. data/spec/app/models/mdm/{module_arch_spec.rb → module/arch_spec.rb} +6 -6
  36. data/spec/app/models/mdm/{module_author_spec.rb → module/author_spec.rb} +6 -6
  37. data/spec/app/models/mdm/{module_detail_spec.rb → module/detail_spec.rb} +101 -11
  38. data/spec/app/models/mdm/{module_mixin_spec.rb → module/mixin_spec.rb} +6 -6
  39. data/spec/app/models/mdm/{module_platform_spec.rb → module/platform_spec.rb} +6 -6
  40. data/spec/app/models/mdm/module/ref_spec.rb +62 -0
  41. data/spec/app/models/mdm/{module_target_spec.rb → module/target_spec.rb} +6 -6
  42. data/spec/app/models/mdm/ref_spec.rb +62 -0
  43. data/spec/app/models/mdm/tag_spec.rb +13 -0
  44. data/spec/app/models/mdm/vuln_ref_spec.rb +13 -0
  45. data/spec/app/models/mdm/vuln_spec.rb +231 -0
  46. data/spec/dummy/db/schema.rb +20 -20
  47. data/spec/factories/mdm/host_tags.rb +9 -0
  48. data/spec/factories/mdm/hosts.rb +65 -0
  49. data/spec/factories/mdm/module/actions.rb +14 -0
  50. data/spec/factories/mdm/module/archs.rb +14 -0
  51. data/spec/factories/mdm/{module_authors.rb → module/authors.rb} +4 -4
  52. data/spec/factories/mdm/module/details.rb +66 -0
  53. data/spec/factories/mdm/module/mixins.rb +14 -0
  54. data/spec/factories/mdm/module/platforms.rb +14 -0
  55. data/spec/factories/mdm/module/refs.rb +14 -0
  56. data/spec/factories/mdm/{module_targets.rb → module/targets.rb} +3 -3
  57. data/spec/factories/mdm/refs.rb +9 -0
  58. data/spec/factories/mdm/tags.rb +14 -0
  59. data/spec/factories/mdm/vuln_refs.rb +4 -0
  60. data/spec/factories/mdm/vulns.rb +20 -0
  61. metadata +78 -45
  62. data/app/models/mdm/module_detail.rb +0 -59
  63. data/app/models/mdm/module_ref.rb +0 -24
  64. data/spec/app/models/mdm/module_ref_spec.rb +0 -38
  65. data/spec/factories/mdm/module_actions.rb +0 -14
  66. data/spec/factories/mdm/module_archs.rb +0 -14
  67. data/spec/factories/mdm/module_details.rb +0 -9
  68. data/spec/factories/mdm/module_mixins.rb +0 -14
  69. data/spec/factories/mdm/module_platforms.rb +0 -14
  70. data/spec/factories/mdm/module_refs.rb +0 -14
@@ -1,18 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mdm::ModuleArch do
3
+ describe Mdm::Module::Arch do
4
4
  context 'associations' do
5
- it { should belong_to(:module_detail).class_name('Mdm::ModuleDetail') }
5
+ it { should belong_to(:detail).class_name('Mdm::Module::Detail') }
6
6
  end
7
7
 
8
8
  context 'database' do
9
9
  context 'columns' do
10
- it { should have_db_column(:module_detail_id).of_type(:integer) }
10
+ it { should have_db_column(:detail_id).of_type(:integer) }
11
11
  it { should have_db_column(:name).of_type(:text) }
12
12
  end
13
13
 
14
14
  context 'indices' do
15
- it { should have_db_index(:module_detail_id) }
15
+ it { should have_db_index(:detail_id) }
16
16
  end
17
17
  end
18
18
 
@@ -27,12 +27,12 @@ describe Mdm::ModuleArch do
27
27
  end
28
28
 
29
29
  context 'mass assignment security' do
30
- it { should_not allow_mass_assignment_of(:module_detail_id) }
30
+ it { should_not allow_mass_assignment_of(:detail_id) }
31
31
  it { should allow_mass_assignment_of(:name) }
32
32
  end
33
33
 
34
34
  context 'validations' do
35
- it { should validate_presence_of(:module_detail) }
35
+ it { should validate_presence_of(:detail) }
36
36
  it { should validate_presence_of(:name) }
37
37
  end
38
38
  end
@@ -1,19 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mdm::ModuleAuthor do
3
+ describe Mdm::Module::Author do
4
4
  context 'associations' do
5
- it { should belong_to(:module_detail).class_name('Mdm::ModuleDetail') }
5
+ it { should belong_to(:detail).class_name('Mdm::Module::Detail') }
6
6
  end
7
7
 
8
8
  context 'database' do
9
9
  context 'columns' do
10
- it { should have_db_column(:module_detail_id).of_type(:integer) }
10
+ it { should have_db_column(:detail_id).of_type(:integer) }
11
11
  it { should have_db_column(:name).of_type(:text) }
12
12
  it { should have_db_column(:email).of_type(:text) }
13
13
  end
14
14
 
15
15
  context 'indices' do
16
- it { should have_db_index(:module_detail_id) }
16
+ it { should have_db_index(:detail_id) }
17
17
  end
18
18
  end
19
19
 
@@ -37,14 +37,14 @@ describe Mdm::ModuleAuthor do
37
37
  end
38
38
 
39
39
  context 'mass assignment security' do
40
- it { should_not allow_mass_assignment_of(:module_detail_id) }
40
+ it { should_not allow_mass_assignment_of(:detail_id) }
41
41
  it { should allow_mass_assignment_of(:email) }
42
42
  it { should allow_mass_assignment_of(:name) }
43
43
  end
44
44
 
45
45
  context 'validations' do
46
+ it { should validate_presence_of(:detail) }
46
47
  it { should_not validate_presence_of(:email) }
47
- it { should validate_presence_of(:module_detail) }
48
48
  it { should validate_presence_of(:name) }
49
49
  end
50
50
  end
@@ -1,18 +1,97 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mdm::ModuleDetail do
3
+ describe Mdm::Module::Detail do
4
4
  subject(:module_detail) do
5
5
  FactoryGirl.build(:mdm_module_detail)
6
6
  end
7
7
 
8
+ let(:ranks) do
9
+ [
10
+ 0,
11
+ 100,
12
+ 200,
13
+ 300,
14
+ 400,
15
+ 500,
16
+ 600
17
+ ]
18
+ end
19
+
20
+ let(:stances) do
21
+ [
22
+ 'aggressive',
23
+ 'passive'
24
+ ]
25
+ end
26
+
27
+ let(:types) do
28
+ [
29
+ 'auxiliary',
30
+ 'encoder',
31
+ 'exploit',
32
+ 'nop',
33
+ 'payload',
34
+ 'post'
35
+ ]
36
+ end
37
+
8
38
  context 'associations' do
9
- it { should have_many(:actions).class_name('Mdm::ModuleAction').dependent(:destroy) }
10
- it { should have_many(:archs).class_name('Mdm::ModuleArch').dependent(:destroy) }
11
- it { should have_many(:authors).class_name('Mdm::ModuleAuthor').dependent(:destroy) }
12
- it { should have_many(:mixins).class_name('Mdm::ModuleMixin').dependent(:destroy) }
13
- it { should have_many(:platforms).class_name('Mdm::ModulePlatform').dependent(:destroy) }
14
- it { should have_many(:refs).class_name('Mdm::ModuleRef').dependent(:destroy) }
15
- it { should have_many(:targets).class_name('Mdm::ModuleTarget').dependent(:destroy) }
39
+ it { should have_many(:actions).class_name('Mdm::Module::Action').dependent(:destroy) }
40
+ it { should have_many(:archs).class_name('Mdm::Module::Arch').dependent(:destroy) }
41
+ it { should have_many(:authors).class_name('Mdm::Module::Author').dependent(:destroy) }
42
+ it { should have_many(:mixins).class_name('Mdm::Module::Mixin').dependent(:destroy) }
43
+ it { should have_many(:platforms).class_name('Mdm::Module::Platform').dependent(:destroy) }
44
+ it { should have_many(:refs).class_name('Mdm::Module::Ref').dependent(:destroy) }
45
+ it { should have_many(:targets).class_name('Mdm::Module::Target').dependent(:destroy) }
46
+ end
47
+
48
+ context 'CONSTANTS' do
49
+ context 'DIRECTORY_BY_TYPE' do
50
+ subject(:directory_by_type) do
51
+ described_class::DIRECTORY_BY_TYPE
52
+ end
53
+
54
+ its(['auxiliary']) { should == 'auxiliary' }
55
+ its(['encoder']) { should == 'encoders' }
56
+ its(['exploit']) { should == 'exploits' }
57
+ its(['nop']) { should == 'nops' }
58
+ its(['payload']) { should == 'payloads' }
59
+ its(['post']) { should == 'post' }
60
+ end
61
+
62
+ context 'PRIVILEGES' do
63
+ subject(:privileges) do
64
+ described_class::PRIVILEGES
65
+ end
66
+
67
+ it 'should contain both Boolean values' do
68
+ privileges.should include(false)
69
+ privileges.should include(true)
70
+ end
71
+ end
72
+
73
+ context 'RANK_BY_NAME' do
74
+ subject(:rank_by_name) do
75
+ described_class::RANK_BY_NAME
76
+ end
77
+
78
+ its(['Manual']) { should == 0 }
79
+ its(['Low']) { should == 100 }
80
+ its(['Average']) { should == 200 }
81
+ its(['Normal']) { should == 300 }
82
+ its(['Good']) { should == 400 }
83
+ its(['Great']) { should == 500 }
84
+ its(['Excellent']) { should == 600 }
85
+ end
86
+
87
+ context 'STANCES' do
88
+ subject(:stances) do
89
+ described_class::STANCES
90
+ end
91
+
92
+ it { should include('aggressive') }
93
+ it { should include('passive') }
94
+ end
16
95
  end
17
96
 
18
97
  context 'database' do
@@ -52,7 +131,18 @@ describe Mdm::ModuleDetail do
52
131
  end
53
132
 
54
133
  context 'validations' do
134
+ it { should ensure_inclusion_of(:mtype).in_array(types) }
135
+
136
+ # Because the boolean field will cast most strings to false,
137
+ # ensure_inclusion_of(:privileged).in_array([true, false]) will fail on the disallowed values check.
138
+
139
+ context 'rank' do
140
+ it { should validate_numericality_of(:rank).only_integer }
141
+ it { should ensure_inclusion_of(:rank).in_array(ranks) }
142
+ end
143
+
55
144
  it { should validate_presence_of(:refname) }
145
+ it { should ensure_inclusion_of(:stance).in_array(stances) }
56
146
  end
57
147
 
58
148
  context 'with saved' do
@@ -69,13 +159,13 @@ describe Mdm::ModuleDetail do
69
159
  FactoryGirl.generate :mdm_module_action_name
70
160
  end
71
161
 
72
- it 'should add an Mdm::ModuleAction under the Mdm::ModuleDetail' do
162
+ it 'should add an Mdm::Action under the Mdm::ModuleDetail' do
73
163
  expect {
74
164
  add_action
75
165
  }.to change(module_detail.actions, :length).by(1)
76
166
  end
77
167
 
78
- context 'new Mdm::ModuleAction' do
168
+ context 'new Mdm::Action' do
79
169
  subject(:module_action) do
80
170
  add_action
81
171
 
@@ -287,5 +377,5 @@ describe Mdm::ModuleDetail do
287
377
  its(:name) { should == name }
288
378
  end
289
379
  end
290
- end
380
+ end
291
381
  end
@@ -1,18 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mdm::ModuleMixin do
3
+ describe Mdm::Module::Mixin do
4
4
  context 'associations' do
5
- it { should belong_to(:module_detail).class_name('Mdm::ModuleDetail') }
5
+ it { should belong_to(:detail).class_name('Mdm::Module::Detail') }
6
6
  end
7
7
 
8
8
  context 'database' do
9
9
  context 'columns' do
10
- it { should have_db_column(:module_detail_id).of_type(:integer) }
10
+ it { should have_db_column(:detail_id).of_type(:integer) }
11
11
  it { should have_db_column(:name).of_type(:text) }
12
12
  end
13
13
 
14
14
  context 'indices' do
15
- it { should have_db_index(:module_detail_id) }
15
+ it { should have_db_index(:detail_id) }
16
16
  end
17
17
  end
18
18
 
@@ -27,12 +27,12 @@ describe Mdm::ModuleMixin do
27
27
  end
28
28
 
29
29
  context 'mass assignment security' do
30
- it { should_not allow_mass_assignment_of(:module_detail_id) }
30
+ it { should_not allow_mass_assignment_of(:detail_id) }
31
31
  it { should allow_mass_assignment_of(:name) }
32
32
  end
33
33
 
34
34
  context 'validations' do
35
- it { should validate_presence_of(:module_detail) }
35
+ it { should validate_presence_of(:detail) }
36
36
  it { should validate_presence_of(:name) }
37
37
  end
38
38
  end
@@ -1,18 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mdm::ModulePlatform do
3
+ describe Mdm::Module::Platform do
4
4
  context 'associations' do
5
- it { should belong_to(:module_detail).class_name('Mdm::ModuleDetail') }
5
+ it { should belong_to(:detail).class_name('Mdm::Module::Detail') }
6
6
  end
7
7
 
8
8
  context 'database' do
9
9
  context 'columns' do
10
- it { should have_db_column(:module_detail_id).of_type(:integer) }
10
+ it { should have_db_column(:detail_id).of_type(:integer) }
11
11
  it { should have_db_column(:name).of_type(:text) }
12
12
  end
13
13
 
14
14
  context 'indices' do
15
- it { should have_db_index(:module_detail_id) }
15
+ it { should have_db_index(:detail_id) }
16
16
  end
17
17
  end
18
18
 
@@ -27,12 +27,12 @@ describe Mdm::ModulePlatform do
27
27
  end
28
28
 
29
29
  context 'mass assignment security' do
30
- it { should_not allow_mass_assignment_of(:module_detail_id) }
30
+ it { should_not allow_mass_assignment_of(:detail_id) }
31
31
  it { should allow_mass_assignment_of(:name) }
32
32
  end
33
33
 
34
34
  context 'validations' do
35
- it { should validate_presence_of :module_detail }
35
+ it { should validate_presence_of :detail }
36
36
  it { should validate_presence_of :name }
37
37
  end
38
38
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::Module::Ref do
4
+ context 'associations' do
5
+ it { should belong_to(:detail).class_name('Mdm::Module::Detail') }
6
+
7
+ # shoulda matchers don't have support for :primary_key option, so need
8
+ # to test this association manually
9
+ context 'refs' do
10
+ context 'with Mdm::Refs' do
11
+ context 'with same name' do
12
+ let(:name) do
13
+ FactoryGirl.generate :mdm_module_ref_name
14
+ end
15
+
16
+ let!(:module_ref) do
17
+ FactoryGirl.create(:mdm_module_ref, :name => name)
18
+ end
19
+
20
+ let!(:ref) do
21
+ FactoryGirl.create(:mdm_ref, :name => name)
22
+ end
23
+
24
+ it 'should have refs in association' do
25
+ module_ref.refs.should =~ [ref]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ context 'database' do
33
+ context 'columns' do
34
+ it { should have_db_column(:detail_id).of_type(:integer) }
35
+ it { should have_db_column(:name) }
36
+ end
37
+
38
+ context 'indices' do
39
+ it { should have_db_column(:detail_id) }
40
+ end
41
+ end
42
+
43
+ context 'factories' do
44
+ context 'mdm_module_ref' do
45
+ subject(:mdm_module_ref) do
46
+ FactoryGirl.build :mdm_module_ref
47
+ end
48
+
49
+ it { should be_valid }
50
+ end
51
+ end
52
+
53
+ context 'mass assignment security' do
54
+ it { should_not allow_mass_assignment_of(:detail_id) }
55
+ it { should allow_mass_assignment_of(:name) }
56
+ end
57
+
58
+ context 'validations' do
59
+ it { should validate_presence_of(:detail) }
60
+ it { should validate_presence_of(:name) }
61
+ end
62
+ end
@@ -1,19 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mdm::ModuleTarget do
3
+ describe Mdm::Module::Target do
4
4
  context 'associations' do
5
- it { should belong_to(:module_detail).class_name('Mdm::ModuleDetail') }
5
+ it { should belong_to(:detail).class_name('Mdm::Module::Detail') }
6
6
  end
7
7
 
8
8
  context 'database' do
9
9
  context 'columns' do
10
+ it { should have_db_column(:detail_id).of_type(:integer) }
10
11
  it { should have_db_column(:index).of_type(:integer) }
11
- it { should have_db_column(:module_detail_id).of_type(:integer) }
12
12
  it { should have_db_column(:name).of_type(:text) }
13
13
  end
14
14
 
15
15
  context 'indices' do
16
- it { should have_db_index(:module_detail_id) }
16
+ it { should have_db_index(:detail_id) }
17
17
  end
18
18
  end
19
19
 
@@ -28,14 +28,14 @@ describe Mdm::ModuleTarget do
28
28
  end
29
29
 
30
30
  context 'mass assignment security' do
31
+ it { should_not allow_mass_assignment_of(:detail_id) }
31
32
  it { should allow_mass_assignment_of(:index) }
32
- it { should_not allow_mass_assignment_of(:module_detail_id) }
33
33
  it { should allow_mass_assignment_of(:name) }
34
34
  end
35
35
 
36
36
  context 'validations' do
37
+ it { should validate_presence_of(:detail) }
37
38
  it { should validate_presence_of(:index) }
38
- it { should validate_presence_of(:module_detail) }
39
39
  it { should validate_presence_of(:name) }
40
40
  end
41
41
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::Ref do
4
+ context 'associations' do
5
+ # shoulda matchers don't have support for :primary_key option, so need to
6
+ # test this association manually
7
+ context 'module_refs' do
8
+ context 'with Mdm::Module::Refs' do
9
+ context 'with same name' do
10
+ let(:name) do
11
+ FactoryGirl.generate :mdm_ref_name
12
+ end
13
+
14
+ let!(:module_ref) do
15
+ FactoryGirl.create(:mdm_module_ref, :name => name)
16
+ end
17
+
18
+ let!(:ref) do
19
+ FactoryGirl.create(:mdm_ref, :name => name)
20
+ end
21
+
22
+ it 'should have module_refs in assocation' do
23
+ ref.module_refs.should =~ [module_ref]
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ # @todo https://www.pivotaltracker.com/story/show/48915453
30
+ it { should have_many(:vulns_refs).class_name('Mdm::VulnRef') }
31
+ end
32
+
33
+ context 'database' do
34
+ context 'columns' do
35
+ it { should have_db_column(:name).of_type(:string) }
36
+ it { should have_db_column(:ref_id).of_type(:integer) }
37
+
38
+ context 'timestamps' do
39
+ it { should have_db_column(:created_at).of_type(:datetime) }
40
+ it { should have_db_column(:updated_at).of_type(:datetime) }
41
+ end
42
+ end
43
+
44
+ context 'indices' do
45
+ it { should have_db_index(:name) }
46
+ end
47
+ end
48
+
49
+ context 'factories' do
50
+ context 'mdm_ref' do
51
+ subject(:mdm_ref) do
52
+ FactoryGirl.build :mdm_ref
53
+ end
54
+
55
+ it { should be_valid }
56
+ end
57
+ end
58
+
59
+ context 'mass assignment security' do
60
+ it { should allow_mass_assignment_of(:name) }
61
+ end
62
+ end