metasploit_data_models 0.14.4 → 0.15.0

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.
@@ -14,8 +14,25 @@ class Mdm::Cred < ActiveRecord::Base
14
14
  #
15
15
  # Relations
16
16
  #
17
+
18
+ # @!attribute [rw] servce
19
+ # The service this cred is for
20
+ #
21
+ # @return [Mdm::Service]
17
22
  belongs_to :service, :class_name => "Mdm::Service"
18
23
 
24
+ # @!attribute [rw] task_creds
25
+ # Details about what Tasks touched this cred
26
+ #
27
+ # @return [Array<Mdm::TaskCred>]
28
+ has_many :task_creds, :dependent => :destroy, :class_name => "Mdm::TaskCred"
29
+
30
+ # @!attribute [rw] tasks
31
+ # Tasks that touched this service
32
+ #
33
+ # @return [Array<Mdm::Task>]
34
+ has_many :tasks, :through => :task_creds
35
+
19
36
  after_create :increment_host_counter_cache
20
37
  after_destroy :decrement_host_counter_cache
21
38
 
@@ -53,6 +53,18 @@ class Mdm::Host < ActiveRecord::Base
53
53
  # Associations
54
54
  #
55
55
 
56
+ # @!attribute [rw] task_hosts
57
+ # Details about what Tasks touched this host
58
+ #
59
+ # @return [Array<Mdm::TaskHost>]
60
+ has_many :task_hosts, :dependent => :destroy, :class_name => 'Mdm::TaskHost'
61
+
62
+ # @!attribute [rw] tasks
63
+ # Tasks that touched this service
64
+ #
65
+ # @return [Array<Mdm::Task>]
66
+ has_many :tasks, :through => :task_hosts, :class_name => 'Mdm::Task'
67
+
56
68
  # @!attribute [rw] exploit_attempts
57
69
  # Attempts to run exploits against this host.
58
70
  #
@@ -11,6 +11,18 @@ class Mdm::Service < ActiveRecord::Base
11
11
  # Associations
12
12
  #
13
13
 
14
+ # @!attribute [rw] task_services
15
+ # Details about what Tasks touched this service
16
+ #
17
+ # @return [Array<Mdm::TaskService>]
18
+ has_many :task_services, :dependent => :destroy, :class_name => 'Mdm::TaskService'
19
+
20
+ # @!attribute [rw] tasks
21
+ # Tasks that touched this service
22
+ #
23
+ # @return [Array<Mdm::Task>]
24
+ has_many :tasks, :through => :task_services, :class_name => 'Mdm::Task'
25
+
14
26
  # @!attribute [rw] creds
15
27
  # Credentials gathered from this service.
16
28
  #
@@ -9,7 +9,47 @@ class Mdm::Task < ActiveRecord::Base
9
9
  # Relations
10
10
  #
11
11
 
12
- belongs_to :workspace, :class_name => "Mdm::Workspace"
12
+ # @!attribute [rw] workspace
13
+ # The Workspace the Task belongs to
14
+ #
15
+ # @return [Mdm::Workspace]
16
+ belongs_to :workspace, :class_name => "Mdm::Workspace"
17
+
18
+ # @!attribute [rw] task_creds
19
+ # Details about creds this task touched
20
+ #
21
+ # @return [Array<Mdm::TaskCred>]
22
+ has_many :task_creds, :dependent => :destroy, :class_name => 'Mdm::TaskCred'
23
+
24
+ # @!attribute [rw] creds
25
+ # Creds this task touched
26
+ #
27
+ # @return [Array<Mdm::TaskCred>]
28
+ has_many :creds, :through => :task_creds, :class_name => 'Mdm::Cred'
29
+
30
+ # @!attribute [rw] task_hosts
31
+ # Details about hosts this task touched
32
+ #
33
+ # @return [Array<Mdm::TaskHost>]
34
+ has_many :task_hosts, :dependent => :destroy, :class_name => 'Mdm::TaskHost'
35
+
36
+ # @!attribute [rw] hosts
37
+ # Hosts this task touched
38
+ #
39
+ # @return [Array<Mdm::TaskHost>
40
+ has_many :hosts, :through => :task_hosts, :class_name => 'Mdm::Host'
41
+
42
+ # @!attribute [rw] task_services
43
+ # Details about services this task touched
44
+ #
45
+ # @return [Array<Mdm::TaskService>]
46
+ has_many :task_services, :dependent => :destroy, :class_name => 'Mdm::TaskService'
47
+
48
+ # @!attribute [rw] services
49
+ # Services this task touched
50
+ #
51
+ # @return [Array<Mdm::TaskHost>
52
+ has_many :services, :through => :task_services, :class_name => 'Mdm::Service'
13
53
 
14
54
  #
15
55
  # Scopes
@@ -0,0 +1,10 @@
1
+ class Mdm::TaskCred < ActiveRecord::Base
2
+ # attr_accessible :title, :body
3
+ belongs_to :cred, :class_name => Mdm::Cred
4
+ belongs_to :task, :class_name => Mdm::Task
5
+
6
+ validates :cred_id,
7
+ :uniqueness => {
8
+ :scope => :task_id
9
+ }
10
+ end
@@ -0,0 +1,10 @@
1
+ class Mdm::TaskHost < ActiveRecord::Base
2
+ # attr_accessible :title, :body
3
+ belongs_to :host, :class_name => Mdm::Host
4
+ belongs_to :task, :class_name => Mdm::Task
5
+
6
+ validates :host_id,
7
+ :uniqueness => {
8
+ :scope => :task_id
9
+ }
10
+ end
@@ -0,0 +1,10 @@
1
+ class Mdm::TaskService < ActiveRecord::Base
2
+ # attr_accessible :title, :body
3
+ belongs_to :service, :class_name => Mdm::Service
4
+ belongs_to :task, :class_name => Mdm::Task
5
+
6
+ validates :service_id,
7
+ :uniqueness => {
8
+ :scope => :task_id
9
+ }
10
+ end
@@ -0,0 +1,9 @@
1
+ class CreateTaskCreds < ActiveRecord::Migration
2
+ def change
3
+ create_table :task_creds do |t|
4
+ t.references :task, :null => false
5
+ t.references :cred, :null => false
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateTaskHosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :task_hosts do |t|
4
+ t.references :task, :null => false
5
+ t.references :host, :null => false
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateTaskServices < ActiveRecord::Migration
2
+ def change
3
+ create_table :task_services do |t|
4
+ t.references :task, :null => false
5
+ t.references :service, :null => false
6
+ t.timestamps
7
+ end
8
+ end
9
+ 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.4'
7
+ VERSION = '0.15.0'
8
8
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::Cred do
4
+
5
+ context "Associations" do
6
+ it { should have_many(:task_creds).class_name('Mdm::TaskCred').dependent(:destroy) }
7
+ it { should have_many(:tasks).class_name('Mdm::Task').through(:task_creds) }
8
+ it { should belong_to(:service).class_name('Mdm::Service') }
9
+ end
10
+
11
+
12
+
13
+ end
@@ -44,6 +44,8 @@ describe Mdm::Host do
44
44
  it { should have_many(:host_details).class_name('Mdm::HostDetail').dependent(:destroy) }
45
45
  it { should have_many(:hosts_tags).class_name('Mdm::HostTag') }
46
46
  it { should have_many(:loots).class_name('Mdm::Loot').dependent(:destroy).order('loots.created_at DESC') }
47
+ it { should have_many(:task_hosts).class_name('Mdm::TaskHost').dependent(:destroy) }
48
+ it { should have_many(:tasks).class_name('Mdm::Task').through(:task_hosts) }
47
49
 
48
50
  context 'module_details' do
49
51
  it { should have_many(:module_details).class_name('Mdm::Module::Detail').through(:module_refs) }
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::Service do
4
+
5
+ context "Associations" do
6
+
7
+ it { should have_many(:task_services).class_name('Mdm::TaskService').dependent(:destroy) }
8
+ it { should have_many(:tasks).class_name('Mdm::Task').through(:task_services) }
9
+ it { should have_many(:creds).class_name('Mdm::Cred').dependent(:destroy) }
10
+ it { should have_many(:exploited_hosts).class_name('Mdm::ExploitedHost').dependent(:destroy) }
11
+ it { should have_many(:notes).class_name('Mdm::Note').dependent(:destroy) }
12
+ it { should have_many(:vulns).class_name('Mdm::Vuln').dependent(:destroy) }
13
+ it { should have_many(:web_sites).class_name('Mdm::WebSite').dependent(:destroy) }
14
+ it { should have_many(:web_pages).class_name('Mdm::WebPage').through(:web_sites) }
15
+ it { should have_many(:web_forms).class_name('Mdm::WebForm').through(:web_sites) }
16
+ it { should have_many(:web_vulns).class_name('Mdm::WebVuln').through(:web_sites) }
17
+ it { should belong_to(:host).class_name('Mdm::Host') }
18
+ end
19
+
20
+ context "inactive" do
21
+ it "should exclude open services" do
22
+ open_service = FactoryGirl.create(:mdm_service, :state => 'open')
23
+ Mdm::Service.inactive.should_not include(open_service)
24
+ end
25
+ end
26
+
27
+ context "with_state open" do
28
+ it "should exclude closed services" do
29
+ closed_service = FactoryGirl.create(:mdm_service, :state => 'closed')
30
+ Mdm::Service.with_state('open').should_not include(closed_service)
31
+ end
32
+ end
33
+
34
+ context "search for 'snmp'" do
35
+ it "should find only services that match" do
36
+ snmp_service = FactoryGirl.create(:mdm_service)
37
+ ftp_service = FactoryGirl.create(:mdm_service, :proto => 'ftp')
38
+ search_results = Mdm::Service.search('snmp')
39
+ search_results.should include(snmp_service)
40
+ search_results.should_not include(ftp_service)
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::TaskCred do
4
+
5
+ context "Associations" do
6
+ it { should belong_to(:task).class_name('Mdm::Task') }
7
+ it { should belong_to(:cred).class_name('Mdm::Cred') }
8
+ end
9
+
10
+ context "validations" do
11
+ it "should not allow duplicate associations" do
12
+ task = FactoryGirl.build(:mdm_task)
13
+ cred = FactoryGirl.build(:mdm_cred)
14
+ FactoryGirl.create(:mdm_task_cred, :task => task, :cred => cred)
15
+ task_cred2 = FactoryGirl.build(:mdm_task_cred, :task => task, :cred => cred)
16
+ task_cred2.should_not be_valid
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::TaskHost do
4
+ context "Associations" do
5
+ it { should belong_to(:task).class_name('Mdm::Task') }
6
+ it { should belong_to(:host).class_name('Mdm::Host') }
7
+ end
8
+
9
+ context "validations" do
10
+ it "should not allow duplicate associations" do
11
+ task = FactoryGirl.build(:mdm_task)
12
+ host = FactoryGirl.build(:mdm_host)
13
+ FactoryGirl.create(:mdm_task_host, :task => task, :host => host)
14
+ task_host2 = FactoryGirl.build(:mdm_task_host, :task => task, :host => host)
15
+ task_host2.should_not be_valid
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::TaskService do
4
+ context "Associations" do
5
+ it { should belong_to(:task).class_name('Mdm::Task') }
6
+ it { should belong_to(:service).class_name('Mdm::Service') }
7
+ end
8
+
9
+ context "validations" do
10
+ it "should not allow duplicate associations" do
11
+ task = FactoryGirl.build(:mdm_task)
12
+ service = FactoryGirl.build(:mdm_service)
13
+ FactoryGirl.create(:mdm_task_service, :task => task, :service => service)
14
+ task_service2 = FactoryGirl.build(:mdm_task_service, :task => task, :service => service)
15
+ task_service2.should_not be_valid
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mdm::Task do
4
+
5
+ context "Associations" do
6
+
7
+ it { should have_many(:task_creds).class_name('Mdm::TaskCred').dependent(:destroy) }
8
+ it { should have_many(:creds).class_name('Mdm::Cred').through(:task_creds) }
9
+ it { should have_many(:task_hosts).class_name('Mdm::TaskHost').dependent(:destroy) }
10
+ it { should have_many(:hosts).class_name('Mdm::Host').through(:task_hosts) }
11
+ it { should have_many(:task_services).class_name('Mdm::TaskService').dependent(:destroy) }
12
+ it { should have_many(:services).class_name('Mdm::Service').through(:task_services) }
13
+ it { should belong_to(:workspace).class_name('Mdm::Workspace') }
14
+ end
15
+
16
+ context "running" do
17
+ it "should exclude completed tasks" do
18
+ task = FactoryGirl.create(:mdm_task, :completed_at => Time.now)
19
+ Mdm::Task.running.should_not include(task)
20
+ end
21
+
22
+ end
23
+
24
+ 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 => 20130516204810) do
14
+ ActiveRecord::Schema.define(:version => 20130522041110) do
15
15
 
16
16
  create_table "api_keys", :force => true do |t|
17
17
  t.text "token"
@@ -427,6 +427,27 @@ ActiveRecord::Schema.define(:version => 20130516204810) do
427
427
  t.datetime "updated_at", :null => false
428
428
  end
429
429
 
430
+ create_table "task_creds", :force => true do |t|
431
+ t.integer "task_id", :null => false
432
+ t.integer "cred_id", :null => false
433
+ t.datetime "created_at", :null => false
434
+ t.datetime "updated_at", :null => false
435
+ end
436
+
437
+ create_table "task_hosts", :force => true do |t|
438
+ t.integer "task_id", :null => false
439
+ t.integer "host_id", :null => false
440
+ t.datetime "created_at", :null => false
441
+ t.datetime "updated_at", :null => false
442
+ end
443
+
444
+ create_table "task_services", :force => true do |t|
445
+ t.integer "task_id", :null => false
446
+ t.integer "service_id", :null => false
447
+ t.datetime "created_at", :null => false
448
+ t.datetime "updated_at", :null => false
449
+ end
450
+
430
451
  create_table "tasks", :force => true do |t|
431
452
  t.integer "workspace_id", :default => 1, :null => false
432
453
  t.string "created_by"
@@ -0,0 +1,8 @@
1
+ FactoryGirl.define do
2
+ factory :mdm_cred, :aliases => [:cred], :class => Mdm::Cred do
3
+ #
4
+ # Associations
5
+ #
6
+ association :service, :factory => :mdm_service
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ FactoryGirl.define do
2
+ factory :mdm_task, :aliases => [:task], :class => 'Mdm::Task' do
3
+ #
4
+ # Associations
5
+ #
6
+ association :workspace, :factory => :mdm_workspace
7
+
8
+ #
9
+ # Attributes
10
+ #
11
+ created_at { Time.now }
12
+ updated_at { Time.now }
13
+
14
+
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :mdm_task_cred, :class => 'Mdm::TaskCred' do
5
+
6
+ association :task, :factory => :mdm_task
7
+ association :cred, :factory => :mdm_cred
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :mdm_task_host, :class => 'Mdm::TaskHost' do
5
+
6
+ association :task, :factory => :mdm_task
7
+ association :host, :factory => :mdm_host
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :mdm_task_service, :class => 'Mdm::TaskService' do
5
+ association :task, :factory => :mdm_task
6
+ association :service, :factory => :mdm_service
7
+ end
8
+ 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
4
+ version: 0.15.0
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-21 00:00:00.000000000 Z
15
+ date: 2013-05-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rake
@@ -181,6 +181,9 @@ files:
181
181
  - app/models/mdm/session_event.rb
182
182
  - app/models/mdm/tag.rb
183
183
  - app/models/mdm/task.rb
184
+ - app/models/mdm/task_cred.rb
185
+ - app/models/mdm/task_host.rb
186
+ - app/models/mdm/task_service.rb
184
187
  - app/models/mdm/user.rb
185
188
  - app/models/mdm/vuln.rb
186
189
  - app/models/mdm/vuln_attempt.rb
@@ -296,6 +299,9 @@ files:
296
299
  - db/migrate/20130515164311_change_web_vulns_confidence_to_integer.rb
297
300
  - db/migrate/20130515172727_valid_mdm_web_vuln_params.rb
298
301
  - db/migrate/20130516204810_making_vulns_refs_a_real_ar_model.rb
302
+ - db/migrate/20130522001343_create_task_creds.rb
303
+ - db/migrate/20130522032517_create_task_hosts.rb
304
+ - db/migrate/20130522041110_create_task_services.rb
299
305
  - lib/mdm.rb
300
306
  - lib/mdm/host/operating_system_normalization.rb
301
307
  - lib/mdm/module.rb
@@ -310,6 +316,7 @@ files:
310
316
  - lib/tasks/yard.rake
311
317
  - metasploit_data_models.gemspec
312
318
  - script/rails
319
+ - spec/app/models/mdm/cred_spec.rb
313
320
  - spec/app/models/mdm/host_spec.rb
314
321
  - spec/app/models/mdm/host_tag_spec.rb
315
322
  - spec/app/models/mdm/module/action_spec.rb
@@ -321,7 +328,12 @@ files:
321
328
  - spec/app/models/mdm/module/ref_spec.rb
322
329
  - spec/app/models/mdm/module/target_spec.rb
323
330
  - spec/app/models/mdm/ref_spec.rb
331
+ - spec/app/models/mdm/service_spec.rb
324
332
  - spec/app/models/mdm/tag_spec.rb
333
+ - spec/app/models/mdm/task_creds_spec.rb
334
+ - spec/app/models/mdm/task_host_spec.rb
335
+ - spec/app/models/mdm/task_service_spec.rb
336
+ - spec/app/models/mdm/task_spec.rb
325
337
  - spec/app/models/mdm/vuln_ref_spec.rb
326
338
  - spec/app/models/mdm/vuln_spec.rb
327
339
  - spec/app/models/mdm/web_vuln_spec.rb
@@ -359,6 +371,7 @@ files:
359
371
  - spec/dummy/public/favicon.ico
360
372
  - spec/dummy/script/rails
361
373
  - spec/factories/mdm/addresses.rb
374
+ - spec/factories/mdm/creds.rb
362
375
  - spec/factories/mdm/host_tags.rb
363
376
  - spec/factories/mdm/hosts.rb
364
377
  - spec/factories/mdm/module/actions.rb
@@ -372,6 +385,10 @@ files:
372
385
  - spec/factories/mdm/refs.rb
373
386
  - spec/factories/mdm/services.rb
374
387
  - spec/factories/mdm/tags.rb
388
+ - spec/factories/mdm/task.rb
389
+ - spec/factories/mdm/task_creds.rb
390
+ - spec/factories/mdm/task_hosts.rb
391
+ - spec/factories/mdm/task_services.rb
375
392
  - spec/factories/mdm/users.rb
376
393
  - spec/factories/mdm/vuln_refs.rb
377
394
  - spec/factories/mdm/vulns.rb
@@ -396,7 +413,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
396
413
  version: '0'
397
414
  segments:
398
415
  - 0
399
- hash: -1794950276637032896
416
+ hash: 2038451068979534245
400
417
  required_rubygems_version: !ruby/object:Gem::Requirement
401
418
  none: false
402
419
  requirements:
@@ -405,7 +422,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
405
422
  version: '0'
406
423
  segments:
407
424
  - 0
408
- hash: -1794950276637032896
425
+ hash: 2038451068979534245
409
426
  requirements: []
410
427
  rubyforge_project:
411
428
  rubygems_version: 1.8.25
@@ -413,6 +430,7 @@ signing_key:
413
430
  specification_version: 3
414
431
  summary: Database code for MSF and Metasploit Pro
415
432
  test_files:
433
+ - spec/app/models/mdm/cred_spec.rb
416
434
  - spec/app/models/mdm/host_spec.rb
417
435
  - spec/app/models/mdm/host_tag_spec.rb
418
436
  - spec/app/models/mdm/module/action_spec.rb
@@ -424,7 +442,12 @@ test_files:
424
442
  - spec/app/models/mdm/module/ref_spec.rb
425
443
  - spec/app/models/mdm/module/target_spec.rb
426
444
  - spec/app/models/mdm/ref_spec.rb
445
+ - spec/app/models/mdm/service_spec.rb
427
446
  - spec/app/models/mdm/tag_spec.rb
447
+ - spec/app/models/mdm/task_creds_spec.rb
448
+ - spec/app/models/mdm/task_host_spec.rb
449
+ - spec/app/models/mdm/task_service_spec.rb
450
+ - spec/app/models/mdm/task_spec.rb
428
451
  - spec/app/models/mdm/vuln_ref_spec.rb
429
452
  - spec/app/models/mdm/vuln_spec.rb
430
453
  - spec/app/models/mdm/web_vuln_spec.rb
@@ -462,6 +485,7 @@ test_files:
462
485
  - spec/dummy/public/favicon.ico
463
486
  - spec/dummy/script/rails
464
487
  - spec/factories/mdm/addresses.rb
488
+ - spec/factories/mdm/creds.rb
465
489
  - spec/factories/mdm/host_tags.rb
466
490
  - spec/factories/mdm/hosts.rb
467
491
  - spec/factories/mdm/module/actions.rb
@@ -475,6 +499,10 @@ test_files:
475
499
  - spec/factories/mdm/refs.rb
476
500
  - spec/factories/mdm/services.rb
477
501
  - spec/factories/mdm/tags.rb
502
+ - spec/factories/mdm/task.rb
503
+ - spec/factories/mdm/task_creds.rb
504
+ - spec/factories/mdm/task_hosts.rb
505
+ - spec/factories/mdm/task_services.rb
478
506
  - spec/factories/mdm/users.rb
479
507
  - spec/factories/mdm/vuln_refs.rb
480
508
  - spec/factories/mdm/vulns.rb