metasploit_data_models 0.17.0-java → 0.17.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  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 +9 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f4621672c11b8b3879c2e357d8cb6d58bbed881
4
- data.tar.gz: 98cfa49f629de2306a3fcb0ff56418f20cbf0905
3
+ metadata.gz: c3ac2acc96e06b312007386119fbcb18dd3b4eed
4
+ data.tar.gz: 5750da9112e3e3a3e503b6aea84332bc00d307ea
5
5
  SHA512:
6
- metadata.gz: bc546d304ea93aca26a4bcd8a4d4f66d4c4089f5ed5699e32a39988a4e90e29c186e46774d3cea29f1f5ab3470fe4a935fa1797f2347b5c3ed9f191122bd0d5c
7
- data.tar.gz: ac654d836d39728947e6a4fb02fe6914e8f404a58b9070db06eeb55369ddcfb9436ab9d9e9942df43b7744a9556a6e434b31ce8186b5ff22ca9b6939d89f86f8
6
+ metadata.gz: a3e48421538862eb92a3b8fcd2665690699bbbbdb260fdf676b0eab113582e6504d50167fd3d513901c5d81d1b8ac36e6366266856311e37e7e62af9eeb1fc9e
7
+ data.tar.gz: 1085e221c71d39dea601afa46470158f6d6bb270840df5056524d19ecfa741496ffe7844901a840bc395eecc4d510797c83ba50ebe14cd6e780e7e3faed79b9e
data/.yardopts CHANGED
@@ -1,4 +1,4 @@
1
1
  --markup markdown
2
+ --plugin yard-metasploit-erd
2
3
  --protected
3
4
  {app,lib}/**/*.rb
4
- db/migrate/*.rb
data/Gemfile CHANGED
@@ -3,6 +3,11 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in metasploit_data_models.gemspec
4
4
  gemspec
5
5
 
6
+ group :development do
7
+ # embed ERDs on index, namespace Module and Class<ActiveRecord::Base> pages
8
+ gem 'yard-metasploit-erd', '~> 0.0.2'
9
+ end
10
+
6
11
  # used by dummy application
7
12
  group :development, :test do
8
13
  # supplies factories for producing model instance for specs
@@ -12,7 +17,7 @@ group :development, :test do
12
17
  gem 'factory_girl_rails'
13
18
  # rails is only used for the dummy application in spec/dummy
14
19
  # restrict from rails 4.0 as it requires protected_attributes gem and other changes for compatibility
15
- # @see https://www.pivotaltracker.com/story/show/52309083
20
+ # @see MSP-2971
16
21
  gem 'rails', '>= 3.2', '< 4.0.0'
17
22
  # Used to create fake data
18
23
  gem "faker"
@@ -2,7 +2,9 @@ class Mdm::Client < ActiveRecord::Base
2
2
  #
3
3
  # Relations
4
4
  #
5
- belongs_to :host, :class_name => 'Mdm::Host'
5
+ belongs_to :host,
6
+ class_name: 'Mdm::Host',
7
+ inverse_of: :clients
6
8
 
7
9
  ActiveSupport.run_load_hooks(:mdm_client, self)
8
10
  end
@@ -19,13 +19,18 @@ class Mdm::Cred < ActiveRecord::Base
19
19
  # The service this cred is for
20
20
  #
21
21
  # @return [Mdm::Service]
22
- belongs_to :service, :class_name => "Mdm::Service"
22
+ belongs_to :service,
23
+ class_name: 'Mdm::Service',
24
+ inverse_of: :creds
23
25
 
24
26
  # @!attribute [rw] task_creds
25
27
  # Details about what Tasks touched this cred
26
28
  #
27
29
  # @return [Array<Mdm::TaskCred>]
28
- has_many :task_creds, :dependent => :destroy, :class_name => "Mdm::TaskCred"
30
+ has_many :task_creds,
31
+ class_name: 'Mdm::TaskCred',
32
+ dependent: :destroy,
33
+ inverse_of: :cred
29
34
 
30
35
  # @!attribute [rw] tasks
31
36
  # Tasks that touched this service
@@ -3,8 +3,13 @@ class Mdm::Event < ActiveRecord::Base
3
3
  # Relations
4
4
  #
5
5
 
6
- belongs_to :host, :class_name => 'Mdm::Host'
7
- belongs_to :workspace, :class_name => 'Mdm::Workspace'
6
+ belongs_to :host,
7
+ class_name: 'Mdm::Host',
8
+ inverse_of: :events
9
+
10
+ belongs_to :workspace,
11
+ class_name: 'Mdm::Workspace',
12
+ inverse_of: :events
8
13
 
9
14
  #
10
15
  # Scopes
@@ -1,8 +1,49 @@
1
1
  class Mdm::ExploitAttempt < ActiveRecord::Base
2
2
  #
3
- # Relations
3
+ # Associations
4
4
  #
5
- belongs_to :host, :class_name => 'Mdm::Host', :counter_cache => :exploit_attempt_count
5
+
6
+ # @!attribute host
7
+ # Host that was attempted to be exploited.
8
+ #
9
+ # @return [Mdm::Host]
10
+ belongs_to :host,
11
+ class_name: 'Mdm::Host',
12
+ counter_cache: :exploit_attempt_count,
13
+ inverse_of: :exploit_attempts
14
+
15
+ # @!attribute loot
16
+ # Loot gathers from the successful exploit.
17
+ #
18
+ # @return [Mdm::Loot, nil]
19
+ belongs_to :loot,
20
+ class_name: 'Mdm::Loot',
21
+ inverse_of: :exploit_attempt
22
+
23
+ # @!attribute service
24
+ # The service being exploited on {#host}.
25
+ #
26
+ # @return [Mdm::Service, nil]
27
+ belongs_to :service,
28
+ class_name: 'Mdm::Service',
29
+ inverse_of: :exploit_attempts
30
+
31
+ # @!attribute session
32
+ # The session that was established when this attempt was successful.
33
+ #
34
+ # @return [Mdm::Session]
35
+ # @return [nil] if session was not established.
36
+ belongs_to :session,
37
+ class_name: 'Mdm::Session',
38
+ inverse_of: :exploit_attempt
39
+
40
+ # @!attribute vuln
41
+ # The vulnerability that was attempted to be exploited.
42
+ #
43
+ # @return [Mdm::Vuln, nil]
44
+ belongs_to :vuln,
45
+ class_name: 'Mdm::Vuln',
46
+ inverse_of: :exploit_attempts
6
47
 
7
48
  #
8
49
  # Validations
@@ -3,8 +3,13 @@ class Mdm::ExploitedHost < ActiveRecord::Base
3
3
  # Relations
4
4
  #
5
5
 
6
- belongs_to :host, :class_name => 'Mdm::Host'
7
- belongs_to :service, :class_name => 'Mdm::Service'
6
+ belongs_to :host,
7
+ class_name: 'Mdm::Host',
8
+ inverse_of: :exploited_hosts
9
+
10
+ belongs_to :service,
11
+ class_name: 'Mdm::Service',
12
+ inverse_of: :exploited_hosts
8
13
 
9
14
  ActiveSupport.run_load_hooks(:mdm_exploited_host, self)
10
15
  end
@@ -57,83 +57,122 @@ class Mdm::Host < ActiveRecord::Base
57
57
  # Users connected to this host
58
58
  #
59
59
  # @return [Array<Mdm::Client>]
60
- has_many :clients, class_name: 'Mdm::Client', dependent: :destroy
60
+ has_many :clients,
61
+ class_name: 'Mdm::Client',
62
+ dependent: :destroy,
63
+ inverse_of: :host
64
+
65
+ # @!attribute events
66
+ # Events that occurred on this host.
67
+ #
68
+ # @return [ActiveRecord::Relation<Mdm::Event>]
69
+ has_many :events,
70
+ class_name: 'Mdm::Event',
71
+ dependent: :destroy,
72
+ inverse_of: :host
61
73
 
62
74
  # @!attribute [rw] task_hosts
63
75
  # Details about what Tasks touched this host
64
76
  #
65
77
  # @return [Array<Mdm::TaskHost>]
66
- has_many :task_hosts, :dependent => :destroy, :class_name => 'Mdm::TaskHost'
67
-
68
- # @!attribute [rw] tasks
69
- # Tasks that touched this service
70
- #
71
- # @return [Array<Mdm::Task>]
72
- has_many :tasks, :through => :task_hosts, :class_name => 'Mdm::Task'
78
+ has_many :task_hosts,
79
+ class_name: 'Mdm::TaskHost',
80
+ dependent: :destroy,
81
+ inverse_of: :host
73
82
 
74
83
  # @!attribute [rw] exploit_attempts
75
84
  # Attempts to run exploits against this host.
76
85
  #
77
86
  # @return [Array<Mdm::ExploitAttempt]
78
87
  has_many :exploit_attempts,
79
- :class_name => 'Mdm::ExploitAttempt',
80
- :dependent => :destroy
81
-
82
- # @!attribute [rw] exploited_hosts
83
- # @todo https://www.pivotaltracker.com/story/show/48993731
84
- # @return [Array<Mdm::ExploitedHost>]
85
- has_many :exploited_hosts, :class_name => 'Mdm::ExploitedHost', :dependent => :destroy
88
+ class_name: 'Mdm::ExploitAttempt',
89
+ dependent: :destroy,
90
+ inverse_of: :host
91
+
92
+ # @!attribute exploited_hosts
93
+ # @todo MSP-2732
94
+ # @return [ActiveRecord::Relation<Mdm::ExploitedHost>]
95
+ has_many :exploited_hosts,
96
+ class_name: 'Mdm::ExploitedHost',
97
+ dependent: :destroy,
98
+ inverse_of: :host
86
99
 
87
100
  # @!attribute [rw] host_details
88
101
  # @return [Array<Mdm::HostDetail>]
89
- has_many :host_details, :class_name => 'Mdm::HostDetail', :dependent => :destroy
102
+ has_many :host_details,
103
+ class_name: 'Mdm::HostDetail',
104
+ dependent: :destroy,
105
+ inverse_of: :host
90
106
 
91
- # @!attribute [rw] hosts_tags
107
+ # @!attribute hosts_tags
92
108
  # A join model between {Mdm::Tag} and {Mdm::Host}. Use {#tags} to get the actual {Mdm::Tag Mdm::Tags} on this host.
93
- # {#hosts_tags} are cleaned up in a before_destroy: {#cleanup_tags}.
94
109
  #
95
- # @todo https://www.pivotaltracker.com/story/show/48923201
96
- # @return [Array<Mdm::HostTag>]
97
- has_many :hosts_tags, :class_name => 'Mdm::HostTag'
110
+ # @todo MSP-2723
111
+ # @return [ActiveRecord::Relation<Mdm::HostTag>]
112
+ has_many :hosts_tags,
113
+ class_name: 'Mdm::HostTag',
114
+ dependent: :destroy,
115
+ inverse_of: :host
98
116
 
99
- # @!attribute [rw] loots
117
+ # @!attribute loots
100
118
  # Loot gathered from the host with {Mdm::Loot#created_at newest loot} first.
101
119
  #
102
- # @todo https://www.pivotaltracker.com/story/show/48991525
103
- # @return [Array<Mdm::Loot>]
104
- has_many :loots, :class_name => 'Mdm::Loot', :dependent => :destroy, :order => 'loots.created_at DESC'
120
+ # @todo MSP-3065
121
+ # @return [ActiveRecord::Relation<Mdm::Loot>]
122
+ has_many :loots,
123
+ class_name: 'Mdm::Loot',
124
+ dependent: :destroy,
125
+ inverse_of: :host,
126
+ order: 'loots.created_at DESC'
105
127
 
106
128
  # @!attribute [rw] notes
107
129
  # Notes about the host entered by a user with {Mdm::Note#created_at oldest notes} first.
108
130
  #
109
131
  # @return [Array<Mdm::Note>]
110
- has_many :notes, :class_name => 'Mdm::Note', :dependent => :delete_all, :order => 'notes.created_at'
132
+ has_many :notes,
133
+ class_name: 'Mdm::Note',
134
+ inverse_of: :host,
135
+ dependent: :delete_all,
136
+ order: 'notes.created_at'
111
137
 
112
138
  # @!attribute [rw] services
113
139
  # The services running on {Mdm::Service#port ports} on the host with services ordered by {Mdm::Service#port port}
114
140
  # and {Mdm::Service#proto protocol}.
115
141
  #
116
142
  # @return [Array<Mdm::Service>]
117
- has_many :services, :class_name => 'Mdm::Service', :dependent => :destroy, :order => 'services.port, services.proto'
143
+ has_many :services,
144
+ class_name: 'Mdm::Service',
145
+ dependent: :destroy,
146
+ inverse_of: :host,
147
+ order: 'services.port, services.proto'
118
148
 
119
149
  # @!attribute [rw] sessions
120
150
  # Sessions that are open or previously were open on the host ordered by {Mdm::Session#opened_at when the session was
121
151
  # opened}
122
152
  #
123
153
  # @return [Array<Mdm::Session]
124
- has_many :sessions, :class_name => 'Mdm::Session', :dependent => :destroy, :order => 'sessions.opened_at'
154
+ has_many :sessions,
155
+ class_name: 'Mdm::Session',
156
+ dependent: :destroy,
157
+ inverse_of: :host,
158
+ order: 'sessions.opened_at'
125
159
 
126
160
  # @!attribute [rw] vulns
127
161
  # Vulnerabilities found on the host.
128
162
  #
129
163
  # @return [Array<Mdm::Vuln>]
130
- has_many :vulns, :class_name => 'Mdm::Vuln', :dependent => :delete_all
164
+ has_many :vulns,
165
+ class_name: 'Mdm::Vuln',
166
+ dependent: :delete_all,
167
+ inverse_of: :host
131
168
 
132
169
  # @!attribute [rw] workspace
133
170
  # The workspace in which this host was found.
134
171
  #
135
172
  # @return [Mdm::Workspace]
136
- belongs_to :workspace, :class_name => 'Mdm::Workspace'
173
+ belongs_to :workspace,
174
+ class_name: 'Mdm::Workspace',
175
+ inverse_of: :hosts
137
176
 
138
177
  #
139
178
  # Through host_tags
@@ -162,7 +201,10 @@ class Mdm::Host < ActiveRecord::Base
162
201
  #
163
202
  # @return [Array<Mdm::Note>]
164
203
  # @see #services
165
- has_many :service_notes, :class_name => 'Mdm::Note', :through => :services
204
+ has_many :service_notes,
205
+ class_name: 'Mdm::Note',
206
+ source: :notes,
207
+ through: :services
166
208
 
167
209
  # @!attribute [r] web_sites
168
210
  # {Mdm::WebSite Web sites} running on top of {#services} on this host.
@@ -171,6 +213,18 @@ class Mdm::Host < ActiveRecord::Base
171
213
  # @see services
172
214
  has_many :web_sites, :class_name => 'Mdm::WebSite', :through => :services
173
215
 
216
+ #
217
+ # through: :task_hosts
218
+ #
219
+
220
+ # @!attribute tasks
221
+ # Tasks that touched this service
222
+ #
223
+ # @return [ActiveRecord::Relation<Mdm::Task>]
224
+ has_many :tasks,
225
+ class_name: 'Mdm::Task',
226
+ through: :task_hosts
227
+
174
228
  #
175
229
  # Through vulns
176
230
  #
@@ -351,12 +405,6 @@ class Mdm::Host < ActiveRecord::Base
351
405
  #
352
406
  # @return [Integer]
353
407
 
354
- #
355
- # Callbacks
356
- #
357
-
358
- before_destroy :cleanup_tags
359
-
360
408
  #
361
409
  # Nested Attributes
362
410
  # @note Must be declared after relations being referenced.
@@ -423,18 +471,6 @@ class Mdm::Host < ActiveRecord::Base
423
471
  n && n.data[:locked]
424
472
  end
425
473
 
426
- # Destroys any {Mdm::Tag Mdm::Tags} that will have no {Mdm::Tag#hosts} left after this host is deleted.
427
- #
428
- # @return [void]
429
- def cleanup_tags
430
- # No need to keep tags with no hosts
431
- tags.each do |tag|
432
- tag.destroy if tag.hosts == [self]
433
- end
434
- # Clean up association table records
435
- Mdm::HostTag.delete_all("host_id = #{self.id}")
436
- end
437
-
438
474
  # This is replicated by the IpAddressValidator class. Had to put it here as well to avoid
439
475
  # SQL errors when checking address uniqueness.
440
476
  #
@@ -3,7 +3,10 @@ class Mdm::HostDetail < ActiveRecord::Base
3
3
  # Relations
4
4
  #
5
5
 
6
- belongs_to :host, :class_name => 'Mdm::Host', :counter_cache => :host_detail_count
6
+ belongs_to :host,
7
+ class_name: 'Mdm::Host',
8
+ counter_cache: :host_detail_count,
9
+ inverse_of: :host_details
7
10
 
8
11
  #
9
12
  # Validations
@@ -2,11 +2,49 @@ class Mdm::HostTag < ActiveRecord::Base
2
2
  self.table_name = "hosts_tags"
3
3
 
4
4
  #
5
- # Relations
5
+ # Associations
6
6
  #
7
7
 
8
- belongs_to :host, :class_name => 'Mdm::Host'
9
- belongs_to :tag, :class_name => 'Mdm::Tag'
8
+ # @!attribute host
9
+ # Host with {#tag}.
10
+ #
11
+ # @todo MSP-2723
12
+ # @return [Mdm::Host]
13
+ belongs_to :host,
14
+ class_name: 'Mdm::Host',
15
+ inverse_of: :hosts_tags
16
+
17
+ # @!attribute tag
18
+ # Tag on {#host}.
19
+ #
20
+ # @todo MSP-2723
21
+ # @return [Mdm::Tag]
22
+ belongs_to :tag,
23
+ class_name: 'Mdm::Tag',
24
+ inverse_of: :hosts_tags
25
+
26
+ #
27
+ # Callbacks
28
+ #
29
+
30
+ # @see http://stackoverflow.com/a/11694704
31
+ after_destroy :destroy_orphan_tag
32
+
33
+ #
34
+ # Instance Methods
35
+ #
36
+
37
+ private
38
+
39
+ # Destroys {#tag} if it is orphaned
40
+ #
41
+ # @see http://stackoverflow.com/a/11694704
42
+ # @return [void]
43
+ def destroy_orphan_tag
44
+ tag.destroy_if_orphaned
45
+ end
46
+
47
+ public
10
48
 
11
49
  ActiveSupport.run_load_hooks(:mdm_host_tag, self)
12
50
  end
@@ -3,8 +3,13 @@ class Mdm::Listener < ActiveRecord::Base
3
3
  # Relations
4
4
  #
5
5
 
6
- belongs_to :task, :class_name => 'Mdm::Task'
7
- belongs_to :workspace, :class_name => 'Mdm::Workspace'
6
+ belongs_to :task,
7
+ class_name: 'Mdm::Task',
8
+ inverse_of: :listeners
9
+
10
+ belongs_to :workspace,
11
+ class_name: 'Mdm::Workspace',
12
+ inverse_of: :listeners
8
13
 
9
14
  #
10
15
  # Serializations