metasploit_data_models 0.7.0-java → 0.11.2-java

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 +75 -42
  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
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::Tag do
4
+ context 'factories' do
5
+ context 'mdm_tag' do
6
+ subject(:mdm_tag) do
7
+ FactoryGirl.build(:mdm_tag)
8
+ end
9
+
10
+ it { should be_valid }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::VulnRef do
4
+ context 'factories' do
5
+ context 'mdm_vuln_ref' do
6
+ subject(:mdm_vuln_ref) do
7
+ FactoryGirl.build(:mdm_vuln_ref)
8
+ end
9
+
10
+ it { should be_valid }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,231 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::Vuln do
4
+ subject(:vuln) do
5
+ FactoryGirl.build(:mdm_vuln)
6
+ end
7
+
8
+ context 'associations' do
9
+ it { should belong_to(:host).class_name('Mdm::Host') }
10
+ it { should belong_to(:service).class_name('Mdm::Service') }
11
+ it { should have_many(:module_refs).class_name('Mdm::Module::Ref').through(:refs) }
12
+ # @todo https://www.pivotaltracker.com/story/show/49004623
13
+ it { should have_many(:refs).class_name('Mdm::Ref').through(:vulns_refs) }
14
+ it { should have_many(:vuln_attempts).class_name('Mdm::VulnAttempt').dependent(:destroy) }
15
+ it { should have_many(:vuln_details).class_name('Mdm::VulnDetail').dependent(:destroy) }
16
+ # @todo https://www.pivotaltracker.com/story/show/49004623
17
+ it { should have_many(:vulns_refs).class_name('Mdm::VulnRef').dependent(:destroy) }
18
+
19
+ context 'module_details' do
20
+ it { should have_many(:module_details).class_name('Mdm::Module::Detail').through(:module_refs) }
21
+
22
+ context 'with Mdm::Refs' do
23
+ let(:names) do
24
+ 2.times.collect {
25
+ FactoryGirl.generate :mdm_ref_name
26
+ }
27
+ end
28
+
29
+ let!(:refs) do
30
+ names.collect do |name|
31
+ FactoryGirl.create(:mdm_ref, :name => name)
32
+ end
33
+ end
34
+
35
+ context 'with Mdm::VulnRefs' do
36
+ let!(:vuln_refs) do
37
+ refs.collect { |ref|
38
+ FactoryGirl.create(:mdm_vuln_ref, :ref => ref, :vuln => vuln)
39
+ }
40
+ end
41
+
42
+ context 'with Mdm::Module::Detail' do
43
+ let!(:module_detail) do
44
+ FactoryGirl.create(
45
+ :mdm_module_detail
46
+ )
47
+ end
48
+
49
+ context 'with Mdm::Module::Refs with same names as Mdm::Refs' do
50
+ let!(:module_refs) do
51
+ names.each do |name|
52
+ FactoryGirl.create(
53
+ :mdm_module_ref,
54
+ :detail => module_detail,
55
+ :name => name
56
+ )
57
+ end
58
+ end
59
+
60
+ it 'should list unique Mdm::Module::Detail' do
61
+ vuln.module_details.should =~ [module_detail]
62
+ end
63
+
64
+ it 'should have duplicate Mdm::Module::Details if collected through chain' do
65
+ refs = []
66
+
67
+ # @todo https://www.pivotaltracker.com/story/show/49004623
68
+ vuln.vulns_refs.each do |vuln_ref|
69
+ refs << vuln_ref.ref
70
+ end
71
+
72
+ module_refs = []
73
+
74
+ refs.each do |ref|
75
+ module_refs += ref.module_refs
76
+ end
77
+
78
+ module_details = []
79
+
80
+ module_refs.each do |module_ref|
81
+ module_details << module_ref.detail
82
+ end
83
+
84
+ vuln.module_details.count.should < module_details.length
85
+ module_details.uniq.count.should == vuln.module_details.count
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ context 'database' do
95
+ context 'columns' do
96
+ it { should have_db_column(:exploited_at).of_type(:datetime) }
97
+ it { should have_db_column(:host_id).of_type(:integer) }
98
+ it { should have_db_column(:info).of_type(:string) }
99
+ it { should have_db_column(:name).of_type(:string) }
100
+ it { should have_db_column(:service_id).of_type(:integer) }
101
+
102
+ context 'counter caches' do
103
+ it { should have_db_column(:vuln_attempt_count).of_type(:integer).with_options(:default => 0) }
104
+ it { should have_db_column(:vuln_detail_count).of_type(:integer).with_options(:default => 0) }
105
+ end
106
+
107
+ context 'timestamps' do
108
+ it { should have_db_column(:created_at).of_type(:datetime) }
109
+ it { should have_db_column(:updated_at).of_type(:datetime) }
110
+ end
111
+ end
112
+ end
113
+
114
+ context 'factories' do
115
+ context 'mdm_host_vuln' do
116
+ subject(:mdm_host_vuln) do
117
+ FactoryGirl.build(:mdm_host_vuln)
118
+ end
119
+
120
+ it { should be_valid }
121
+ end
122
+
123
+ context 'mdm_service_vuln' do
124
+ subject(:mdm_service_vuln) do
125
+ FactoryGirl.build(:mdm_service_vuln)
126
+ end
127
+
128
+ it { should be_valid }
129
+ end
130
+
131
+ context 'mdm_vuln' do
132
+ subject(:mdm_vuln) do
133
+ FactoryGirl.build(:mdm_vuln)
134
+ end
135
+
136
+ it { should be_valid }
137
+ end
138
+ end
139
+
140
+ context 'scopes' do
141
+ context 'search' do
142
+ context 'with Mdm::Vuln' do
143
+ subject(:results) do
144
+ described_class.search(query)
145
+ end
146
+
147
+ let!(:vuln) do
148
+ FactoryGirl.create(:mdm_vuln)
149
+ end
150
+
151
+ context 'with Mdm::Ref' do
152
+ let!(:ref) do
153
+ FactoryGirl.create(:mdm_ref)
154
+ end
155
+
156
+ context 'with Mdm::VulnRef' do
157
+ let!(:vuln_ref) do
158
+ FactoryGirl.create(:mdm_vuln_ref, :ref => ref, :vuln => vuln)
159
+ end
160
+
161
+ context 'with query matching Mdm::Ref#name' do
162
+ let(:query) do
163
+ ref.name
164
+ end
165
+
166
+ it 'should match Mdm::Vuln' do
167
+ results.should =~ [vuln]
168
+ end
169
+ end
170
+
171
+ context 'with query matching Mdm::Ref#name' do
172
+ let(:query) do
173
+ "Not #{ref.name}"
174
+ end
175
+
176
+ it 'should not match Mdm::Vuln' do
177
+ results.should be_empty
178
+ end
179
+ end
180
+ end
181
+
182
+ context 'without Mdm::VulnRef' do
183
+ context 'with query matching Mdm::Vuln#name' do
184
+ let(:query) do
185
+ vuln.name
186
+ end
187
+
188
+ it 'should match Mdm::Vuln' do
189
+ results.should =~ [vuln]
190
+ end
191
+ end
192
+
193
+ context 'with query not matching Mdm::Vuln#name' do
194
+ let(:query) do
195
+ "Not #{vuln.name}"
196
+ end
197
+
198
+ it 'should not match Mdm::Vuln' do
199
+ results.should be_empty
200
+ end
201
+ end
202
+
203
+ context 'with query matching Mdm::Vuln#info' do
204
+ let(:query) do
205
+ vuln.info
206
+ end
207
+
208
+ it 'should match Mdm::Vuln' do
209
+ results.should =~ [vuln]
210
+ end
211
+ end
212
+
213
+ context 'without query matching Mdm::Vuln#info' do
214
+ let(:query) do
215
+ "Not #{vuln.info}"
216
+ end
217
+
218
+ it 'should not match Mdm::Vuln' do
219
+ results.should be_empty
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ context 'validations' do
229
+ it { should validate_presence_of :name }
230
+ end
231
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20130423211152) do
14
+ ActiveRecord::Schema.define(:version => 20130430162145) do
15
15
 
16
16
  create_table "api_keys", :force => true do |t|
17
17
  t.text "token"
@@ -135,7 +135,7 @@ ActiveRecord::Schema.define(:version => 20130423211152) do
135
135
 
136
136
  create_table "hosts", :force => true do |t|
137
137
  t.datetime "created_at"
138
- t.string "address"
138
+ t.string "address", :limit => nil, :null => false
139
139
  t.string "mac"
140
140
  t.string "comm"
141
141
  t.string "name"
@@ -145,7 +145,7 @@ ActiveRecord::Schema.define(:version => 20130423211152) do
145
145
  t.string "os_sp"
146
146
  t.string "os_lang"
147
147
  t.string "arch"
148
- t.integer "workspace_id"
148
+ t.integer "workspace_id", :null => false
149
149
  t.datetime "updated_at"
150
150
  t.text "purpose"
151
151
  t.string "info", :limit => 65536
@@ -160,12 +160,12 @@ ActiveRecord::Schema.define(:version => 20130423211152) do
160
160
  t.integer "cred_count", :default => 0
161
161
  end
162
162
 
163
- add_index "hosts", ["address"], :name => "index_hosts_on_address"
164
163
  add_index "hosts", ["name"], :name => "index_hosts_on_name"
165
164
  add_index "hosts", ["os_flavor"], :name => "index_hosts_on_os_flavor"
166
165
  add_index "hosts", ["os_name"], :name => "index_hosts_on_os_name"
167
166
  add_index "hosts", ["purpose"], :name => "index_hosts_on_purpose"
168
167
  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
169
169
 
170
170
  create_table "hosts_tags", :id => false, :force => true do |t|
171
171
  t.integer "host_id"
@@ -224,26 +224,26 @@ ActiveRecord::Schema.define(:version => 20130423211152) do
224
224
  end
225
225
 
226
226
  create_table "module_actions", :force => true do |t|
227
- t.integer "module_detail_id"
227
+ t.integer "detail_id"
228
228
  t.text "name"
229
229
  end
230
230
 
231
- add_index "module_actions", ["module_detail_id"], :name => "index_module_actions_on_module_detail_id"
231
+ add_index "module_actions", ["detail_id"], :name => "index_module_actions_on_module_detail_id"
232
232
 
233
233
  create_table "module_archs", :force => true do |t|
234
- t.integer "module_detail_id"
234
+ t.integer "detail_id"
235
235
  t.text "name"
236
236
  end
237
237
 
238
- add_index "module_archs", ["module_detail_id"], :name => "index_module_archs_on_module_detail_id"
238
+ add_index "module_archs", ["detail_id"], :name => "index_module_archs_on_module_detail_id"
239
239
 
240
240
  create_table "module_authors", :force => true do |t|
241
- t.integer "module_detail_id"
241
+ t.integer "detail_id"
242
242
  t.text "name"
243
243
  t.text "email"
244
244
  end
245
245
 
246
- add_index "module_authors", ["module_detail_id"], :name => "index_module_authors_on_module_detail_id"
246
+ add_index "module_authors", ["detail_id"], :name => "index_module_authors_on_module_detail_id"
247
247
 
248
248
  create_table "module_details", :force => true do |t|
249
249
  t.datetime "mtime"
@@ -269,34 +269,34 @@ ActiveRecord::Schema.define(:version => 20130423211152) do
269
269
  add_index "module_details", ["refname"], :name => "index_module_details_on_refname"
270
270
 
271
271
  create_table "module_mixins", :force => true do |t|
272
- t.integer "module_detail_id"
272
+ t.integer "detail_id"
273
273
  t.text "name"
274
274
  end
275
275
 
276
- add_index "module_mixins", ["module_detail_id"], :name => "index_module_mixins_on_module_detail_id"
276
+ add_index "module_mixins", ["detail_id"], :name => "index_module_mixins_on_module_detail_id"
277
277
 
278
278
  create_table "module_platforms", :force => true do |t|
279
- t.integer "module_detail_id"
279
+ t.integer "detail_id"
280
280
  t.text "name"
281
281
  end
282
282
 
283
- add_index "module_platforms", ["module_detail_id"], :name => "index_module_platforms_on_module_detail_id"
283
+ add_index "module_platforms", ["detail_id"], :name => "index_module_platforms_on_module_detail_id"
284
284
 
285
285
  create_table "module_refs", :force => true do |t|
286
- t.integer "module_detail_id"
286
+ t.integer "detail_id"
287
287
  t.text "name"
288
288
  end
289
289
 
290
- add_index "module_refs", ["module_detail_id"], :name => "index_module_refs_on_module_detail_id"
290
+ add_index "module_refs", ["detail_id"], :name => "index_module_refs_on_module_detail_id"
291
291
  add_index "module_refs", ["name"], :name => "index_module_refs_on_name"
292
292
 
293
293
  create_table "module_targets", :force => true do |t|
294
- t.integer "module_detail_id"
294
+ t.integer "detail_id"
295
295
  t.integer "index"
296
296
  t.text "name"
297
297
  end
298
298
 
299
- add_index "module_targets", ["module_detail_id"], :name => "index_module_targets_on_module_detail_id"
299
+ add_index "module_targets", ["detail_id"], :name => "index_module_targets_on_module_detail_id"
300
300
 
301
301
  create_table "nexpose_consoles", :force => true do |t|
302
302
  t.datetime "created_at", :null => false
@@ -596,7 +596,7 @@ ActiveRecord::Schema.define(:version => 20130423211152) do
596
596
 
597
597
  create_table "wmap_requests", :force => true do |t|
598
598
  t.string "host"
599
- t.string "address"
599
+ t.string "address", :limit => nil
600
600
  t.integer "port"
601
601
  t.integer "ssl"
602
602
  t.string "meth", :limit => 32
@@ -613,7 +613,7 @@ ActiveRecord::Schema.define(:version => 20130423211152) do
613
613
 
614
614
  create_table "wmap_targets", :force => true do |t|
615
615
  t.string "host"
616
- t.string "address"
616
+ t.string "address", :limit => nil
617
617
  t.integer "port"
618
618
  t.integer "ssl"
619
619
  t.integer "selected"
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :mdm_host_tag, :class => Mdm::HostTag do
3
+ #
4
+ # Associations
5
+ #
6
+ association :host, :factory => :mdm_host
7
+ association :tag, :factory => :mdm_tag
8
+ end
9
+ end
@@ -10,9 +10,74 @@ FactoryGirl.define do
10
10
  #
11
11
  address { generate :mdm_ipv4_address }
12
12
  name { generate :mdm_host_name }
13
+
14
+ factory :full_mdm_host do
15
+ arch { generate :mdm_host_arch }
16
+ comm { generate :mdm_host_comm }
17
+ comments { generate :mdm_host_comments }
18
+ info { generate :mdm_host_info }
19
+ mac { generate :mdm_host_mac }
20
+ os_flavor { generate :mdm_host_os_flavor }
21
+ os_lang { generate :mdm_host_os_lang }
22
+ os_name { generate :mdm_host_os_name }
23
+ os_sp { generate :mdm_host_os_sp }
24
+ purpose { generate :mdm_host_purpose }
25
+ scope { generate :mdm_host_scope }
26
+ state { generate :mdm_host_state }
27
+ virtual_host { generate :mdm_host_virtual_host }
28
+ end
13
29
  end
14
30
 
15
31
  sequence :mdm_host_name do |n|
16
32
  "mdm_host_#{n}"
17
33
  end
34
+
35
+ sequence :mdm_host_arch, Mdm::Host::ARCHITECTURES.cycle
36
+
37
+ sequence :mdm_host_comm do |n|
38
+ "Mdm::Host#comm #{n}"
39
+ end
40
+
41
+ sequence :mdm_host_comments do |n|
42
+ "Mdm::Host#comments #{n}"
43
+ end
44
+
45
+ sequence :mdm_host_info do |n|
46
+ "Mdm::Host#info #{n}"
47
+ end
48
+
49
+ sequence :mdm_host_mac do |n|
50
+ without_separators = "%012X" % n
51
+ octet_strings = without_separators.scan(/.{2}/)
52
+ formatted = octet_strings.join(':')
53
+
54
+ formatted
55
+ end
56
+
57
+ sequence :mdm_host_os_flavor do |n|
58
+ "Mdm::Host#os_flavor #{n}"
59
+ end
60
+
61
+ sequence :mdm_host_os_lang do |n|
62
+ "Mdm::Host#os_lang #{n}"
63
+ end
64
+
65
+ sequence :mdm_host_os_name, Mdm::Host::OPERATING_SYSTEM_NAMES.cycle
66
+
67
+ sequence :mdm_host_os_sp do |n|
68
+ "Mdm::Host#os_sp #{n}"
69
+ end
70
+
71
+ sequence :mdm_host_purpose do |n|
72
+ "Mdm::Host#purpose #{n}"
73
+ end
74
+
75
+ sequence :mdm_host_scope do |n|
76
+ n.to_s
77
+ end
78
+
79
+ sequence :mdm_host_state, Mdm::Host::STATES.cycle
80
+
81
+ virtual_hosts = ['VMWare', 'QEMU', 'XEN']
82
+ sequence :mdm_host_virtual_host, virtual_hosts.cycle
18
83
  end