metasploit_data_models 0.14.2 → 0.14.3
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/mdm/module/detail.rb +21 -2
- data/lib/metasploit_data_models/version.rb +1 -1
- data/spec/app/models/mdm/module/detail_spec.rb +80 -29
- data/spec/factories/mdm/module/details.rb +8 -1
- data/spec/support/shared/examples/mdm/module/detail/does_not_support_stance_with_mtype.rb +20 -0
- data/spec/support/shared/examples/mdm/module/detail/supports_stance_with_mtype.rb +36 -0
- metadata +8 -4
@@ -167,9 +167,10 @@ class Mdm::Module::Detail < ActiveRecord::Base
|
|
167
167
|
# @return [String]
|
168
168
|
|
169
169
|
# @!attribute [rw] stance
|
170
|
-
# Whether the module is active or passive.
|
170
|
+
# Whether the module is active or passive. `nil` if the {#mtype module type} does not
|
171
|
+
# {#supports_stance? support stances}.
|
171
172
|
#
|
172
|
-
# @return ['active', 'passive']
|
173
|
+
# @return ['active', 'passive', nil]
|
173
174
|
|
174
175
|
#
|
175
176
|
# Validations
|
@@ -193,6 +194,7 @@ class Mdm::Module::Detail < ActiveRecord::Base
|
|
193
194
|
validates :refname, :presence => true
|
194
195
|
validates :stance,
|
195
196
|
:inclusion => {
|
197
|
+
:if => :supports_stance?,
|
196
198
|
:in => STANCES
|
197
199
|
}
|
198
200
|
|
@@ -276,5 +278,22 @@ class Mdm::Module::Detail < ActiveRecord::Base
|
|
276
278
|
self.targets.build(:index => index, :name => name).save
|
277
279
|
end
|
278
280
|
|
281
|
+
# Returns whether this module supports a {#stance}. Only modules with {#mtype} `'auxiliary'` and `'exploit'` support
|
282
|
+
# a non-nil {#stance}.
|
283
|
+
#
|
284
|
+
# @return [true] if {#mtype} is `'auxiliary'` or `'exploit'`
|
285
|
+
# @return [false] otherwise
|
286
|
+
# @see https://github.com/rapid7/metasploit-framework/blob/a6070f8584ad9e48918b18c7e765d85f549cb7fd/lib/msf/core/db_manager.rb#L423
|
287
|
+
# @see https://github.com/rapid7/metasploit-framework/blob/a6070f8584ad9e48918b18c7e765d85f549cb7fd/lib/msf/core/db_manager.rb#L436
|
288
|
+
def supports_stance?
|
289
|
+
supports_stance = false
|
290
|
+
|
291
|
+
if ['auxiliary', 'exploit'].include? mtype
|
292
|
+
supports_stance = true
|
293
|
+
end
|
294
|
+
|
295
|
+
supports_stance
|
296
|
+
end
|
297
|
+
|
279
298
|
ActiveSupport.run_load_hooks(:mdm_module_detail, self)
|
280
299
|
end
|
@@ -4,5 +4,5 @@ module MetasploitDataModels
|
|
4
4
|
# metasploit-framework/data/sql/migrate to db/migrate in this project, not all models have specs that verify the
|
5
5
|
# migrations (with have_db_column and have_db_index) and certain models may not be shared between metasploit-framework
|
6
6
|
# and pro, so models may be removed in the future. Because of the unstable API the version should remain below 1.0.0
|
7
|
-
VERSION = '0.14.
|
7
|
+
VERSION = '0.14.3'
|
8
8
|
end
|
@@ -1,8 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mdm::Module::Detail do
|
4
|
-
subject(:
|
5
|
-
FactoryGirl.build(
|
4
|
+
subject(:detail) do
|
5
|
+
FactoryGirl.build(
|
6
|
+
:mdm_module_detail,
|
7
|
+
:mtype => mtype,
|
8
|
+
:stance => stance
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:mtype) do
|
13
|
+
FactoryGirl.generate :mdm_module_detail_mtype
|
6
14
|
end
|
7
15
|
|
8
16
|
let(:ranks) do
|
@@ -17,6 +25,10 @@ describe Mdm::Module::Detail do
|
|
17
25
|
]
|
18
26
|
end
|
19
27
|
|
28
|
+
let(:stance) do
|
29
|
+
FactoryGirl.generate :mdm_module_detail_stance
|
30
|
+
end
|
31
|
+
|
20
32
|
let(:stances) do
|
21
33
|
[
|
22
34
|
'aggressive',
|
@@ -109,7 +121,7 @@ describe Mdm::Module::Detail do
|
|
109
121
|
it { should have_db_column(:rank).of_type(:integer) }
|
110
122
|
it { should have_db_column(:ready).of_type(:boolean) }
|
111
123
|
it { should have_db_column(:refname).of_type(:text) }
|
112
|
-
it { should have_db_column(:stance).of_type(:string) }
|
124
|
+
it { should have_db_column(:stance).of_type(:string).with_options(:null => true) }
|
113
125
|
end
|
114
126
|
|
115
127
|
context 'indices' do
|
@@ -127,6 +139,34 @@ describe Mdm::Module::Detail do
|
|
127
139
|
end
|
128
140
|
|
129
141
|
it { should be_valid }
|
142
|
+
|
143
|
+
context 'stance' do
|
144
|
+
subject(:mdm_module_detail) do
|
145
|
+
FactoryGirl.build(:mdm_module_detail, :mtype => mtype)
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'with supports_stance?' do
|
149
|
+
let(:mtype) do
|
150
|
+
'exploit'
|
151
|
+
end
|
152
|
+
|
153
|
+
it { should be_valid }
|
154
|
+
|
155
|
+
its(:stance) { should_not be_nil }
|
156
|
+
its(:supports_stance?) { should be_true }
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'without supports_stance?' do
|
160
|
+
let(:mtype) do
|
161
|
+
'post'
|
162
|
+
end
|
163
|
+
|
164
|
+
it { should be_valid }
|
165
|
+
|
166
|
+
its(:stance) { should be_nil }
|
167
|
+
its(:supports_stance?) { should be_false }
|
168
|
+
end
|
169
|
+
end
|
130
170
|
end
|
131
171
|
end
|
132
172
|
|
@@ -142,17 +182,28 @@ describe Mdm::Module::Detail do
|
|
142
182
|
end
|
143
183
|
|
144
184
|
it { should validate_presence_of(:refname) }
|
145
|
-
|
185
|
+
|
186
|
+
context 'stance' do
|
187
|
+
context 'mtype' do
|
188
|
+
it_should_behave_like 'Mdm::Module::Detail supports stance with mtype', 'auxiliary'
|
189
|
+
it_should_behave_like 'Mdm::Module::Detail supports stance with mtype', 'exploit'
|
190
|
+
|
191
|
+
it_should_behave_like 'Mdm::Module::Detail does not support stance with mtype', 'encoder'
|
192
|
+
it_should_behave_like 'Mdm::Module::Detail does not support stance with mtype', 'nop'
|
193
|
+
it_should_behave_like 'Mdm::Module::Detail does not support stance with mtype', 'payload'
|
194
|
+
it_should_behave_like 'Mdm::Module::Detail does not support stance with mtype', 'post'
|
195
|
+
end
|
196
|
+
end
|
146
197
|
end
|
147
198
|
|
148
199
|
context 'with saved' do
|
149
200
|
before(:each) do
|
150
|
-
|
201
|
+
detail.save!
|
151
202
|
end
|
152
203
|
|
153
204
|
context '#add_action' do
|
154
205
|
def add_action
|
155
|
-
|
206
|
+
detail.add_action(name)
|
156
207
|
end
|
157
208
|
|
158
209
|
let(:name) do
|
@@ -162,14 +213,14 @@ describe Mdm::Module::Detail do
|
|
162
213
|
it 'should add an Mdm::Action under the Mdm::ModuleDetail' do
|
163
214
|
expect {
|
164
215
|
add_action
|
165
|
-
}.to change(
|
216
|
+
}.to change(detail.actions, :length).by(1)
|
166
217
|
end
|
167
218
|
|
168
219
|
context 'new Mdm::Action' do
|
169
220
|
subject(:module_action) do
|
170
221
|
add_action
|
171
222
|
|
172
|
-
|
223
|
+
detail.actions.last
|
173
224
|
end
|
174
225
|
|
175
226
|
it { should be_valid }
|
@@ -180,7 +231,7 @@ describe Mdm::Module::Detail do
|
|
180
231
|
|
181
232
|
context '#add_arch' do
|
182
233
|
def add_arch
|
183
|
-
|
234
|
+
detail.add_arch(name)
|
184
235
|
end
|
185
236
|
|
186
237
|
let(:name) do
|
@@ -190,14 +241,14 @@ describe Mdm::Module::Detail do
|
|
190
241
|
it 'should add an Mdm::ModuleArch under the Mdm::ModuleDetail' do
|
191
242
|
expect {
|
192
243
|
add_arch
|
193
|
-
}.to change(
|
244
|
+
}.to change(detail.archs, :length).by(1)
|
194
245
|
end
|
195
246
|
|
196
247
|
context 'new Mdm::ModuleArch' do
|
197
248
|
subject(:module_arch) do
|
198
249
|
add_arch
|
199
250
|
|
200
|
-
|
251
|
+
detail.archs.last
|
201
252
|
end
|
202
253
|
|
203
254
|
it { should be_valid }
|
@@ -213,7 +264,7 @@ describe Mdm::Module::Detail do
|
|
213
264
|
|
214
265
|
context 'with email' do
|
215
266
|
def add_author
|
216
|
-
|
267
|
+
detail.add_author(name, email)
|
217
268
|
end
|
218
269
|
|
219
270
|
let(:email) do
|
@@ -223,14 +274,14 @@ describe Mdm::Module::Detail do
|
|
223
274
|
it 'should add an Mdm::ModuleAuthor under the Mdm::ModuleDetail' do
|
224
275
|
expect {
|
225
276
|
add_author
|
226
|
-
}.to change(
|
277
|
+
}.to change(detail.authors, :length).by(1)
|
227
278
|
end
|
228
279
|
|
229
280
|
context 'new Mdm::ModuleAuthor' do
|
230
281
|
subject(:module_author) do
|
231
282
|
add_author
|
232
283
|
|
233
|
-
|
284
|
+
detail.authors.last
|
234
285
|
end
|
235
286
|
|
236
287
|
it { should be_valid }
|
@@ -242,20 +293,20 @@ describe Mdm::Module::Detail do
|
|
242
293
|
|
243
294
|
context 'without email' do
|
244
295
|
def add_author
|
245
|
-
|
296
|
+
detail.add_author(name)
|
246
297
|
end
|
247
298
|
|
248
299
|
it 'should add an Mdm::ModuleAuthor under the Mdm::ModuleDetail' do
|
249
300
|
expect {
|
250
301
|
add_author
|
251
|
-
}.to change(
|
302
|
+
}.to change(detail.authors, :length).by(1)
|
252
303
|
end
|
253
304
|
|
254
305
|
context 'new Mdm::ModuleAuthor' do
|
255
306
|
subject(:module_author) do
|
256
307
|
add_author
|
257
308
|
|
258
|
-
|
309
|
+
detail.authors.last
|
259
310
|
end
|
260
311
|
|
261
312
|
it { should be_valid }
|
@@ -268,7 +319,7 @@ describe Mdm::Module::Detail do
|
|
268
319
|
|
269
320
|
context '#add_mixin' do
|
270
321
|
def add_mixin
|
271
|
-
|
322
|
+
detail.add_mixin(name)
|
272
323
|
end
|
273
324
|
|
274
325
|
let(:name) do
|
@@ -278,14 +329,14 @@ describe Mdm::Module::Detail do
|
|
278
329
|
it 'should add an Mdm::ModuleMixin under the Mdm::ModuleDetail' do
|
279
330
|
expect {
|
280
331
|
add_mixin
|
281
|
-
}.to change(
|
332
|
+
}.to change(detail.mixins, :length).by(1)
|
282
333
|
end
|
283
334
|
|
284
335
|
context 'new Mdm::ModuleMixin' do
|
285
336
|
subject do
|
286
337
|
add_mixin
|
287
338
|
|
288
|
-
|
339
|
+
detail.mixins.last
|
289
340
|
end
|
290
341
|
|
291
342
|
it { should be_valid }
|
@@ -295,7 +346,7 @@ describe Mdm::Module::Detail do
|
|
295
346
|
|
296
347
|
context '#add_platform' do
|
297
348
|
def add_platform
|
298
|
-
|
349
|
+
detail.add_platform(name)
|
299
350
|
end
|
300
351
|
|
301
352
|
let(:name) do
|
@@ -305,14 +356,14 @@ describe Mdm::Module::Detail do
|
|
305
356
|
it 'should add an Mdm::ModulePlatform under the Mdm::ModuleDetail' do
|
306
357
|
expect {
|
307
358
|
add_platform
|
308
|
-
}.to change(
|
359
|
+
}.to change(detail.platforms, :length).by(1)
|
309
360
|
end
|
310
361
|
|
311
362
|
context 'new Mdm::ModulePlatform' do
|
312
363
|
subject(:module_platform) do
|
313
364
|
add_platform
|
314
365
|
|
315
|
-
|
366
|
+
detail.platforms.last
|
316
367
|
end
|
317
368
|
|
318
369
|
it { should be_valid }
|
@@ -322,7 +373,7 @@ describe Mdm::Module::Detail do
|
|
322
373
|
|
323
374
|
context '#add_ref' do
|
324
375
|
def add_ref
|
325
|
-
|
376
|
+
detail.add_ref(name)
|
326
377
|
end
|
327
378
|
|
328
379
|
let(:name) do
|
@@ -332,14 +383,14 @@ describe Mdm::Module::Detail do
|
|
332
383
|
it 'should add an Mdm::ModuleRef under the Mdm::ModuleDetail' do
|
333
384
|
expect {
|
334
385
|
add_ref
|
335
|
-
}.to change(
|
386
|
+
}.to change(detail.refs, :length).by(1)
|
336
387
|
end
|
337
388
|
|
338
389
|
context 'new Mdm::ModuleRef' do
|
339
390
|
subject(:module_ref) do
|
340
391
|
add_ref
|
341
392
|
|
342
|
-
|
393
|
+
detail.refs.last
|
343
394
|
end
|
344
395
|
|
345
396
|
it { should be_valid }
|
@@ -349,7 +400,7 @@ describe Mdm::Module::Detail do
|
|
349
400
|
|
350
401
|
context '#add_target' do
|
351
402
|
def add_target
|
352
|
-
|
403
|
+
detail.add_target(index, name)
|
353
404
|
end
|
354
405
|
|
355
406
|
let(:index) do
|
@@ -363,14 +414,14 @@ describe Mdm::Module::Detail do
|
|
363
414
|
it 'should add an Mdm::ModuleTarget under the Mdm::ModuleDetail' do
|
364
415
|
expect {
|
365
416
|
add_target
|
366
|
-
}.to change(
|
417
|
+
}.to change(detail.targets, :length).by(1)
|
367
418
|
end
|
368
419
|
|
369
420
|
context 'new Mdm::ModuleTarget' do
|
370
421
|
subject(:module_target) do
|
371
422
|
add_target
|
372
423
|
|
373
|
-
|
424
|
+
detail.targets.last
|
374
425
|
end
|
375
426
|
|
376
427
|
it { should be_valid }
|
@@ -17,7 +17,14 @@ FactoryGirl.define do
|
|
17
17
|
rank { generate :mdm_module_detail_rank }
|
18
18
|
refname { generate :mdm_module_detail_refname }
|
19
19
|
fullname { "#{mtype}/#{refname}" }
|
20
|
-
|
20
|
+
|
21
|
+
stance {
|
22
|
+
if supports_stance?
|
23
|
+
generate :mdm_module_detail_stance
|
24
|
+
else
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
}
|
21
28
|
|
22
29
|
file {
|
23
30
|
type_directory = Mdm::Module::Detail::DIRECTORY_BY_TYPE[mtype]
|
@@ -0,0 +1,20 @@
|
|
1
|
+
shared_examples_for 'Mdm::Module::Detail does not support stance with mtype' do |mtype|
|
2
|
+
context "with #{mtype.inspect}" do
|
3
|
+
# define as a let so that lets from outer context can access option to set detail.
|
4
|
+
let(:mtype) do
|
5
|
+
mtype
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should return false for supports_stance?' do
|
9
|
+
detail.supports_stance?.should be_false
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with nil stance' do
|
13
|
+
let(:stance) do
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it { should be_valid }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
shared_examples_for 'Mdm::Module::Detail supports stance with mtype' do |mtype|
|
2
|
+
context "with #{mtype.inspect}" do
|
3
|
+
# define as a let so that lets from outer context can access option to set detail.
|
4
|
+
let(:mtype) do
|
5
|
+
mtype
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should return true for supports_stance?' do
|
9
|
+
detail.supports_stance?.should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with nil stance' do
|
13
|
+
let(:stance) do
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it { should be_invalid }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with 'aggresive' stance" do
|
21
|
+
let(:stance) do
|
22
|
+
'aggressive'
|
23
|
+
end
|
24
|
+
|
25
|
+
it { should be_valid }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with 'passive' stance" do
|
29
|
+
let(:stance) do
|
30
|
+
'passive'
|
31
|
+
end
|
32
|
+
|
33
|
+
it { should be_valid }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metasploit_data_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-05-
|
15
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rake
|
@@ -380,6 +380,8 @@ files:
|
|
380
380
|
- spec/factories/mdm/workspaces.rb
|
381
381
|
- spec/lib/base64_serializer_spec.rb
|
382
382
|
- spec/spec_helper.rb
|
383
|
+
- spec/support/shared/examples/mdm/module/detail/does_not_support_stance_with_mtype.rb
|
384
|
+
- spec/support/shared/examples/mdm/module/detail/supports_stance_with_mtype.rb
|
383
385
|
homepage: ''
|
384
386
|
licenses: []
|
385
387
|
post_install_message:
|
@@ -394,7 +396,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
394
396
|
version: '0'
|
395
397
|
segments:
|
396
398
|
- 0
|
397
|
-
hash: -
|
399
|
+
hash: -614166004821636482
|
398
400
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
399
401
|
none: false
|
400
402
|
requirements:
|
@@ -403,7 +405,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
403
405
|
version: '0'
|
404
406
|
segments:
|
405
407
|
- 0
|
406
|
-
hash: -
|
408
|
+
hash: -614166004821636482
|
407
409
|
requirements: []
|
408
410
|
rubyforge_project:
|
409
411
|
rubygems_version: 1.8.25
|
@@ -481,4 +483,6 @@ test_files:
|
|
481
483
|
- spec/factories/mdm/workspaces.rb
|
482
484
|
- spec/lib/base64_serializer_spec.rb
|
483
485
|
- spec/spec_helper.rb
|
486
|
+
- spec/support/shared/examples/mdm/module/detail/does_not_support_stance_with_mtype.rb
|
487
|
+
- spec/support/shared/examples/mdm/module/detail/supports_stance_with_mtype.rb
|
484
488
|
has_rdoc:
|