metasploit_data_models 0.17.0 → 0.17.1

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 (42) hide show
  1. checksums.yaml +15 -0
  2. data/.yardopts +1 -1
  3. data/Gemfile +6 -1
  4. data/app/models/mdm/client.rb +3 -1
  5. data/app/models/mdm/cred.rb +7 -2
  6. data/app/models/mdm/event.rb +7 -2
  7. data/app/models/mdm/exploit_attempt.rb +43 -2
  8. data/app/models/mdm/exploited_host.rb +7 -2
  9. data/app/models/mdm/host.rb +85 -49
  10. data/app/models/mdm/host_detail.rb +4 -1
  11. data/app/models/mdm/host_tag.rb +41 -3
  12. data/app/models/mdm/listener.rb +7 -2
  13. data/app/models/mdm/loot.rb +25 -3
  14. data/app/models/mdm/nexpose_console.rb +13 -0
  15. data/app/models/mdm/note.rb +10 -3
  16. data/app/models/mdm/ref.rb +4 -2
  17. data/app/models/mdm/route.rb +7 -1
  18. data/app/models/mdm/service.rb +71 -28
  19. data/app/models/mdm/session.rb +28 -3
  20. data/app/models/mdm/session_event.rb +3 -1
  21. data/app/models/mdm/tag.rb +29 -10
  22. data/app/models/mdm/task.rb +56 -17
  23. data/app/models/mdm/task_cred.rb +7 -3
  24. data/app/models/mdm/task_host.rb +7 -3
  25. data/app/models/mdm/task_service.rb +7 -3
  26. data/app/models/mdm/task_session.rb +7 -2
  27. data/app/models/mdm/user.rb +9 -2
  28. data/app/models/mdm/vuln.rb +27 -7
  29. data/app/models/mdm/vuln_attempt.rb +37 -2
  30. data/app/models/mdm/vuln_detail.rb +9 -1
  31. data/app/models/mdm/vuln_ref.rb +7 -2
  32. data/app/models/mdm/web_form.rb +3 -1
  33. data/app/models/mdm/web_page.rb +3 -1
  34. data/app/models/mdm/web_site.rb +19 -4
  35. data/app/models/mdm/web_vuln.rb +3 -1
  36. data/lib/metasploit_data_models/version.rb +1 -1
  37. data/lib/tasks/yard.rake +7 -0
  38. data/metasploit_data_models.gemspec +3 -1
  39. data/spec/app/models/mdm/host_spec.rb +0 -67
  40. data/spec/app/models/mdm/host_tag_spec.rb +38 -7
  41. data/spec/app/models/mdm/tag_spec.rb +5 -23
  42. metadata +11 -27
@@ -16,23 +16,45 @@ class Mdm::Loot < ActiveRecord::Base
16
16
  # Associations
17
17
  #
18
18
 
19
+ # @!attribute exploit_attempt
20
+ # Exploit attempt where this loot was gathered.
21
+ #
22
+ # @return [Mdm::ExploitAttempt]
23
+ has_one :exploit_attempt,
24
+ class_name: 'Mdm::ExploitAttempt',
25
+ inverse_of: :loot
26
+
19
27
  # @!attribute [rw] host
20
28
  # The host from which the loot was gathered.
21
29
  #
22
30
  # @return [Mdm::Host]
23
- belongs_to :host, :class_name => 'Mdm::Host'
31
+ belongs_to :host,
32
+ class_name: 'Mdm::Host',
33
+ inverse_of: :loots
24
34
 
25
35
  # @!attribute [rw] service
26
36
  # The service running on the {#host} from which the loot was gathered.
27
37
  #
28
38
  # @return [Mdm::Service]
29
- belongs_to :service, :class_name => 'Mdm::Service'
39
+ belongs_to :service,
40
+ class_name: 'Mdm::Service',
41
+ inverse_of: :loots
42
+
43
+ # @!attribute vuln_attempt
44
+ # Vuln attempt that gathered this loot.
45
+ #
46
+ # @return [Mdm::VulnAttempt]
47
+ has_one :vuln_attempt,
48
+ class_name: 'Mdm::VulnAttempt',
49
+ inverse_of: :loot
30
50
 
31
51
  # @!attribute [rw] workspace
32
52
  # The workspace in which the loot is stored and the {#host} exists.
33
53
  #
34
54
  # @return [Mdm::Workspace]
35
- belongs_to :workspace, :class_name => 'Mdm::Workspace'
55
+ belongs_to :workspace,
56
+ class_name: 'Mdm::Workspace',
57
+ inverse_of: :loots
36
58
 
37
59
  #
38
60
  # Attributes
@@ -1,4 +1,17 @@
1
1
  class Mdm::NexposeConsole < ActiveRecord::Base
2
+ #
3
+ # Associations
4
+ #
5
+
6
+ # @!attribute vuln_details
7
+ # Details for vulnerabilities supplied by this Nexpose console.
8
+ #
9
+ # @return [ActiveRecord::Relation<Mdm::VulnDetail>]
10
+ has_many :vuln_details,
11
+ class_name: 'Mdm::VulnDetail',
12
+ foreign_key: :nx_console_id,
13
+ inverse_of: :nexpose_console
14
+
2
15
  #
3
16
  # Serializations
4
17
  #
@@ -9,20 +9,27 @@ class Mdm::Note < ActiveRecord::Base
9
9
  #
10
10
  # @return [Mdm::Host] if note is attached to an {Mdm::Host}.
11
11
  # @return [nil] if note is attached to an {Mdm::Service}.
12
- belongs_to :host, :class_name => 'Mdm::Host', :counter_cache => :note_count
12
+ belongs_to :host,
13
+ class_name: 'Mdm::Host',
14
+ counter_cache: :note_count,
15
+ inverse_of: :notes
13
16
 
14
17
  # @!attribute [rw] service
15
18
  # The service to which this note is attached.
16
19
  #
17
20
  # @return [Mdm::Service] if note is attached to an {Mdm::Service}.
18
21
  # @return [nil] if not is attached to an {Mdm::Host}.
19
- belongs_to :service, :class_name => 'Mdm::Service'
22
+ belongs_to :service,
23
+ class_name: 'Mdm::Service',
24
+ inverse_of: :notes
20
25
 
21
26
  # @!attribute [rw] workspace
22
27
  # The workspace in which the {#host} or {#service} exists.
23
28
  #
24
29
  # @return [Mdm::Workspace]
25
- belongs_to :workspace, :class_name => 'Mdm::Workspace'
30
+ belongs_to :workspace,
31
+ class_name: 'Mdm::Workspace',
32
+ inverse_of: :notes
26
33
 
27
34
  #
28
35
  # Attributes
@@ -18,9 +18,11 @@ class Mdm::Ref < ActiveRecord::Base
18
18
  # @!attribute [rw] vulns_refs
19
19
  # Join model to {Mdm::Vuln Mdm::Vulns}. Use {#vulns} to get the actual {Mdm::Vuln Mdm::Vulns}.
20
20
  #
21
- # @todo https://www.pivotaltracker.com/story/show/48915453
21
+ # @todo MSP-3066
22
22
  # @return [Array<Mdm::VulnRef>]
23
- has_many :vulns_refs, :class_name => 'Mdm::VulnRef'
23
+ has_many :vulns_refs,
24
+ :class_name => 'Mdm::VulnRef',
25
+ inverse_of: :ref
24
26
 
25
27
  #
26
28
  # Through :vuln_refs
@@ -3,7 +3,13 @@ class Mdm::Route < ActiveRecord::Base
3
3
  # Relations
4
4
  #
5
5
 
6
- belongs_to :session, :class_name => 'Mdm::Session'
6
+ # @!attribute [rw] session
7
+ # The session over which this route traverses.
8
+ #
9
+ # @return [Mdm::Session]
10
+ belongs_to :session,
11
+ class_name: 'Mdm::Session',
12
+ inverse_of: :routes
7
13
 
8
14
  ActiveSupport.run_load_hooks(:mdm_route, self)
9
15
  end
@@ -11,52 +11,95 @@ 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
14
+ # @!attribute creds
15
+ # Credentials gathered from this service.
22
16
  #
23
- # @return [Array<Mdm::Task>]
24
- has_many :tasks, :through => :task_services, :class_name => 'Mdm::Task'
17
+ # @return [ActiveRecord::Relation<Mdm::Cred>]
18
+ has_many :creds,
19
+ class_name: 'Mdm::Cred',
20
+ dependent: :destroy,
21
+ inverse_of: :service
25
22
 
26
- # @!attribute [rw] creds
27
- # Credentials gathered from this service.
23
+ # @!attribute exploit_attempts
24
+ # Exploit attempts against this service.
28
25
  #
29
- # @return [Array<Mdm::Cred>]
30
- has_many :creds, :dependent => :destroy, :class_name => 'Mdm::Cred'
26
+ # @return [ActiveRecord::Relation<Mdm::ExploitAttempt>]
27
+ has_many :exploit_attempts,
28
+ class_name: 'Mdm::ExploitAttempt',
29
+ dependent: :destroy,
30
+ inverse_of: :service
31
31
 
32
- # @!attribute [rw] exploited_hosts
33
- # @todo https://www.pivotaltracker.com/story/show/48993731
32
+ # @!attribute exploited_hosts
33
+ # @todo MSP-2732
34
34
  # @return [Array<Mdm::ExploitHost>]
35
- has_many :exploited_hosts, :dependent => :destroy, :class_name => 'Mdm::ExploitedHost'
35
+ has_many :exploited_hosts,
36
+ class_name: 'Mdm::ExploitedHost',
37
+ dependent: :destroy,
38
+ inverse_of: :service
36
39
 
37
- # @!attribute [rw] host
40
+ # @!attribute host
38
41
  # The host on which this service runs.
39
42
  #
40
43
  # @return [Mdm::Host]
41
- belongs_to :host, :class_name => 'Mdm::Host', :counter_cache => :service_count
44
+ belongs_to :host,
45
+ class_name: 'Mdm::Host',
46
+ counter_cache: :service_count,
47
+ inverse_of: :services
42
48
 
43
- # @!attribute [rw] notes
49
+ # @!attribute loots
50
+ # Loot gathers from this service.
51
+ #
52
+ # @return [ActiveRecord::Relation<Mdm::Loot>]
53
+ has_many :loots,
54
+ class_name: 'Mdm::Loot',
55
+ dependent: :destroy,
56
+ inverse_of: :service
57
+
58
+ # @!attribute notes
44
59
  # Notes about this service.
45
60
  #
46
- # @return [Array<Mdm::Note>]
47
- has_many :notes, :dependent => :destroy, :class_name => 'Mdm::Note'
61
+ # @return [ActiveRecord::Relation<Mdm::Note>]
62
+ has_many :notes,
63
+ class_name: 'Mdm::Note',
64
+ dependent: :destroy,
65
+ inverse_of: :service
48
66
 
49
- # @!attribute [rw] vulns
67
+ # @!attribute [rw] task_services
68
+ # Details about what Tasks touched this service
69
+ #
70
+ # @return [Array<Mdm::TaskService>]
71
+ has_many :task_services,
72
+ class_name: 'Mdm::TaskService',
73
+ dependent: :destroy,
74
+ inverse_of: :service
75
+
76
+ # @!attribute vulns
50
77
  # Vulnerabilities found in this service.
51
78
  #
52
- # @return [Array<Mdm::Vuln>]
53
- has_many :vulns, :dependent => :destroy, :class_name => 'Mdm::Vuln'
79
+ # @return [ActiveRecord::Relation<Mdm::Vuln>]
80
+ has_many :vulns,
81
+ class_name: 'Mdm::Vuln',
82
+ dependent: :destroy,
83
+ inverse_of: :service
54
84
 
55
- # @!attribute [rw] web_sites
85
+ # @!attribute web_sites
56
86
  # Web sites running on top of this service.
57
87
  #
58
- # @return [Array<Mdm::WebSite>]
59
- has_many :web_sites, :dependent => :destroy, :class_name => 'Mdm::WebSite'
88
+ # @return [ActiveRecord::Relation<Mdm::WebSite>]
89
+ has_many :web_sites,
90
+ class_name: 'Mdm::WebSite',
91
+ dependent: :destroy,
92
+ inverse_of: :service
93
+
94
+ #
95
+ # through: :task_services
96
+ #
97
+
98
+ # @!attribute [rw] tasks
99
+ # Tasks that touched this service
100
+ #
101
+ # @return [Array<Mdm::Task>]
102
+ has_many :tasks, :through => :task_services, :class_name => 'Mdm::Task'
60
103
 
61
104
  #
62
105
  # Through :web_sites
@@ -9,19 +9,44 @@ class Mdm::Session < ActiveRecord::Base
9
9
  # Events that occurred when this session was open.
10
10
  #
11
11
  # @return [Array<Mdm::Event>]
12
- has_many :events, :class_name => 'Mdm::SessionEvent', :order => 'created_at', :dependent => :delete_all
12
+ has_many :events,
13
+ class_name: 'Mdm::SessionEvent',
14
+ dependent: :delete_all,
15
+ inverse_of: :session,
16
+ order: 'created_at'
17
+
18
+ # @!attribute exploit_attempt
19
+ # Exploit attempt that created this session.
20
+ #
21
+ # @return [Mdm::ExploitAttempt]
22
+ has_one :exploit_attempt,
23
+ class_name: 'Mdm::ExploitAttempt',
24
+ inverse_of: :session
13
25
 
14
26
  # @!attribute [rw] host
15
27
  # {Mdm::Host Host} on which this session was opened.
16
28
  #
17
29
  # @return [Mdm::Host]
18
- belongs_to :host, :class_name => 'Mdm::Host'
30
+ belongs_to :host,
31
+ class_name: 'Mdm::Host',
32
+ inverse_of: :sessions
19
33
 
20
34
  # @!attribute [rw] routes
21
35
  # Routes tunneled throug this session.
22
36
  #
23
37
  # @return [Array<Mdm::Route>]
24
- has_many :routes, :class_name => 'Mdm::Route', :dependent => :delete_all
38
+ has_many :routes,
39
+ class_name: 'Mdm::Route',
40
+ dependent: :delete_all,
41
+ inverse_of: :session
42
+
43
+ # @!attribute vuln_attempt
44
+ # Vulnerability attempt that created this session.
45
+ #
46
+ # @return [Mdm::VulnAttempt]
47
+ has_one :vuln_attempt,
48
+ class_name: 'Mdm::VulnAttempt',
49
+ inverse_of: :session
25
50
 
26
51
  #
27
52
  # Through :host
@@ -3,7 +3,9 @@ class Mdm::SessionEvent < ActiveRecord::Base
3
3
  # Relations
4
4
  #
5
5
 
6
- belongs_to :session, :class_name => 'Mdm::Session'
6
+ belongs_to :session,
7
+ class_name: 'Mdm::Session',
8
+ inverse_of: :events
7
9
 
8
10
  ActiveSupport.run_load_hooks(:mdm_session_event, self)
9
11
  end
@@ -1,20 +1,29 @@
1
1
  class Mdm::Tag < ActiveRecord::Base
2
2
  #
3
- # Callbacks
3
+ # Relations
4
4
  #
5
5
 
6
- before_destroy :cleanup_hosts
7
-
8
- #
9
- # Relations
6
+ # @!attribute hosts_tags
7
+ # Joins {#hosts} to this tag.
10
8
  #
9
+ # @return [ActiveRecord::Relation<Mdm::HostTag>]
10
+ has_many :hosts_tags,
11
+ class_name: 'Mdm::HostTag',
12
+ dependent: :destroy,
13
+ inverse_of: :tag
11
14
 
12
- has_many :hosts_tags, :class_name => 'Mdm::HostTag'
13
- belongs_to :user, :class_name => 'Mdm::User'
15
+ belongs_to :user,
16
+ class_name: 'Mdm::User',
17
+ inverse_of: :tags
14
18
 
15
19
  #
16
20
  # Through :hosts_tags
17
21
  #
22
+
23
+ # @!attribute [r] hosts
24
+ # Host that are tagged with this tag.
25
+ #
26
+ # @return [ActiveRecord::Relation<Mdm::Host>]
18
27
  has_many :hosts, :through => :hosts_tags, :class_name => 'Mdm::Host'
19
28
 
20
29
 
@@ -33,9 +42,19 @@ class Mdm::Tag < ActiveRecord::Base
33
42
  },
34
43
  :presence => true
35
44
 
36
- def cleanup_hosts
37
- # Clean up association table records
38
- Mdm::HostTag.delete_all("tag_id = #{self.id}")
45
+ #
46
+ # Instance Methods
47
+ #
48
+
49
+ # Destroy this tag if it has no {#hosts_tags}
50
+ #
51
+ # @return [void]
52
+ def destroy_if_orphaned
53
+ self.class.transaction do
54
+ if hosts_tags.empty?
55
+ destroy
56
+ end
57
+ end
39
58
  end
40
59
 
41
60
  def to_s
@@ -9,17 +9,62 @@ class Mdm::Task < ActiveRecord::Base
9
9
  # Relations
10
10
  #
11
11
 
12
+ # @!attribute listeners
13
+ # Listeners spawned by this task
14
+ #
15
+ # @return [ActiveRecord::Relation<Mdm::Listener>]
16
+ has_many :listeners,
17
+ class_name: 'Mdm::Listener',
18
+ dependent: :destroy,
19
+ inverse_of: :task
20
+
21
+ # @!attribute [rw] task_creds
22
+ # Joins this to {#creds}.
23
+ #
24
+ # @return [ActiveRecord::Relation<Mdm::TaskCred>]
25
+ has_many :task_creds,
26
+ class_name: 'Mdm::TaskCred',
27
+ dependent: :destroy,
28
+ inverse_of: :task
29
+
30
+ # @!attribute task_hosts
31
+ # Joins this to {#hosts}.
32
+ #
33
+ # @return [ActiveRecord::Relation<Mdm::TaskHost>]
34
+ has_many :task_hosts,
35
+ class_name: 'Mdm::TaskHost',
36
+ dependent: :destroy,
37
+ inverse_of: :task
38
+
39
+ # @!attribute task_services
40
+ # Joins this to {#services}.
41
+ #
42
+ # @return [ActiveRecord::Relation<Mdm::TaskService>]
43
+ has_many :task_services,
44
+ class_name: 'Mdm::TaskService',
45
+ dependent: :destroy,
46
+ inverse_of: :task
47
+
48
+ # @!attribute task_sessions
49
+ # Joins this to {#sessions}.
50
+ #
51
+ # @return [ActiveRecord::Relation<Mdm::TaskSession>]
52
+ has_many :task_sessions,
53
+ class_name: 'Mdm::TaskSession',
54
+ dependent: :destroy,
55
+ inverse_of: :task
56
+
12
57
  # @!attribute [rw] workspace
13
58
  # The Workspace the Task belongs to
14
59
  #
15
60
  # @return [Mdm::Workspace]
16
- belongs_to :workspace, :class_name => "Mdm::Workspace"
61
+ belongs_to :workspace,
62
+ class_name: 'Mdm::Workspace',
63
+ inverse_of: :tasks
17
64
 
18
- # @!attribute [rw] task_creds
19
- # Details about creds this task touched
20
65
  #
21
- # @return [Array<Mdm::TaskCred>]
22
- has_many :task_creds, :dependent => :destroy, :class_name => 'Mdm::TaskCred'
66
+ # through: :task_creds
67
+ #
23
68
 
24
69
  # @!attribute [rw] creds
25
70
  # Creds this task touched
@@ -27,11 +72,9 @@ class Mdm::Task < ActiveRecord::Base
27
72
  # @return [Array<Mdm::Cred>]
28
73
  has_many :creds, :through => :task_creds, :class_name => 'Mdm::Cred'
29
74
 
30
- # @!attribute [rw] task_hosts
31
- # Details about hosts this task touched
32
75
  #
33
- # @return [Array<Mdm::TaskHost>]
34
- has_many :task_hosts, :dependent => :destroy, :class_name => 'Mdm::TaskHost'
76
+ # through: :task_hosts
77
+ #
35
78
 
36
79
  # @!attribute [rw] hosts
37
80
  # Hosts this task touched
@@ -39,11 +82,9 @@ class Mdm::Task < ActiveRecord::Base
39
82
  # @return [Array<Mdm::Host>
40
83
  has_many :hosts, :through => :task_hosts, :class_name => 'Mdm::Host'
41
84
 
42
- # @!attribute [rw] task_services
43
- # Details about services this task touched
44
85
  #
45
- # @return [Array<Mdm::TaskService>]
46
- has_many :task_services, :dependent => :destroy, :class_name => 'Mdm::TaskService'
86
+ # through: :task_services
87
+ #
47
88
 
48
89
  # @!attribute [rw] services
49
90
  # Services this task touched
@@ -51,11 +92,9 @@ class Mdm::Task < ActiveRecord::Base
51
92
  # @return [Array<Mdm::Service>
52
93
  has_many :services, :through => :task_services, :class_name => 'Mdm::Service'
53
94
 
54
- # @!attribute [rw] task_sessions
55
- # Details about sessions this task touched
56
95
  #
57
- # @return [Array<Mdm::TaskSession>]
58
- has_many :task_sessions, :dependent => :destroy, :class_name => 'Mdm::TaskSession'
96
+ # through: :task_sessions
97
+ #
59
98
 
60
99
  # @!attribute [rw] sessions
61
100
  # Session this task touched