metasploit_data_models 0.24.5 → 1.0.0.pre.rails.pre.4.0a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/.simplecov +1 -1
  4. data/Gemfile +8 -5
  5. data/app/models/mdm/api_key.rb +1 -0
  6. data/app/models/mdm/client.rb +2 -2
  7. data/app/models/mdm/cred.rb +13 -13
  8. data/app/models/mdm/event.rb +5 -4
  9. data/app/models/mdm/exploit_attempt.rb +1 -0
  10. data/app/models/mdm/exploited_host.rb +1 -1
  11. data/app/models/mdm/host.rb +37 -20
  12. data/app/models/mdm/host_detail.rb +2 -2
  13. data/app/models/mdm/host_tag.rb +1 -1
  14. data/app/models/mdm/listener.rb +2 -1
  15. data/app/models/mdm/loot.rb +1 -0
  16. data/app/models/mdm/macro.rb +1 -1
  17. data/app/models/mdm/mod_ref.rb +1 -0
  18. data/app/models/mdm/module/action.rb +1 -7
  19. data/app/models/mdm/module/arch.rb +0 -6
  20. data/app/models/mdm/module/author.rb +1 -8
  21. data/app/models/mdm/module/detail.rb +1 -1
  22. data/app/models/mdm/module/mixin.rb +0 -6
  23. data/app/models/mdm/module/platform.rb +0 -6
  24. data/app/models/mdm/module/ref.rb +0 -6
  25. data/app/models/mdm/module/target.rb +0 -7
  26. data/app/models/mdm/nexpose_console.rb +1 -0
  27. data/app/models/mdm/note.rb +3 -3
  28. data/app/models/mdm/ref.rb +0 -6
  29. data/app/models/mdm/route.rb +2 -1
  30. data/app/models/mdm/service.rb +1 -1
  31. data/app/models/mdm/session.rb +8 -7
  32. data/app/models/mdm/session_event.rb +2 -1
  33. data/app/models/mdm/tag.rb +2 -2
  34. data/app/models/mdm/task.rb +1 -3
  35. data/app/models/mdm/user.rb +4 -5
  36. data/app/models/mdm/vuln.rb +8 -7
  37. data/app/models/mdm/vuln_attempt.rb +1 -0
  38. data/app/models/mdm/vuln_detail.rb +3 -2
  39. data/app/models/mdm/vuln_ref.rb +1 -1
  40. data/app/models/mdm/web_form.rb +2 -1
  41. data/app/models/mdm/web_page.rb +3 -2
  42. data/app/models/mdm/web_site.rb +3 -2
  43. data/app/models/mdm/web_vuln.rb +1 -0
  44. data/app/models/mdm/wmap_request.rb +12 -0
  45. data/app/models/mdm/wmap_target.rb +12 -0
  46. data/app/models/mdm/workspace.rb +4 -3
  47. data/app/models/metasploit_data_models/automatic_exploitation/match.rb +0 -3
  48. data/app/models/metasploit_data_models/automatic_exploitation/match_result.rb +0 -12
  49. data/app/models/metasploit_data_models/automatic_exploitation/match_set.rb +0 -1
  50. data/app/models/metasploit_data_models/automatic_exploitation/run.rb +0 -2
  51. data/app/validators/ip_format_validator.rb +6 -1
  52. data/config/initializers/ipaddr.rb +35 -0
  53. data/db/migrate/002_add_workspaces.rb +2 -2
  54. data/db/migrate/007_add_loots.rb +1 -1
  55. data/db/migrate/008_create_users.rb +1 -1
  56. data/db/migrate/011_add_reports.rb +1 -1
  57. data/db/migrate/012_add_tasks.rb +1 -1
  58. data/db/migrate/026_add_creds_table.rb +2 -2
  59. data/db/migrate/20100824151500_add_exploited_table.rb +1 -1
  60. data/db/migrate/20100911122000_add_report_templates.rb +1 -1
  61. data/db/migrate/20100916175000_add_campaigns_and_templates.rb +1 -1
  62. data/db/migrate/20101001000000_add_web_tables.rb +13 -13
  63. data/db/migrate/20110204112800_add_host_tags.rb +1 -1
  64. data/db/migrate/20110527000001_add_api_keys_table.rb +1 -1
  65. data/db/migrate/20110606000001_add_macros_table.rb +2 -2
  66. data/db/migrate/20110624000001_add_listeners_table.rb +1 -1
  67. data/db/migrate/20110630000001_add_nexpose_consoles_table.rb +1 -1
  68. data/db/migrate/20110717000001_add_profiles_table.rb +1 -1
  69. data/db/migrate/20130522001343_create_task_creds.rb +1 -1
  70. data/db/migrate/20130522032517_create_task_hosts.rb +1 -1
  71. data/db/migrate/20130522041110_create_task_services.rb +1 -1
  72. data/db/migrate/20130604145732_create_task_sessions.rb +1 -1
  73. data/db/migrate/20131002004641_create_automatic_exploitation_matches.rb +1 -1
  74. data/db/migrate/20131002164449_create_automatic_exploitation_match_sets.rb +1 -1
  75. data/db/migrate/20131008213344_create_automatic_exploitation_runs.rb +1 -1
  76. data/db/migrate/20131017150735_create_automatic_exploitation_match_results.rb +1 -1
  77. data/db/migrate/20150219173821_create_module_runs.rb +1 -1
  78. data/db/migrate/20150317145455_rename_module_indices.rb +29 -0
  79. data/db/migrate/20150421211719_rename_automatic_exploitation_index.rb +16 -0
  80. data/lib/mdm/host/operating_system_normalization.rb +1 -1
  81. data/lib/metasploit_data_models.rb +1 -0
  82. data/lib/metasploit_data_models/engine.rb +1 -1
  83. data/lib/metasploit_data_models/version.rb +5 -3
  84. data/metasploit_data_models.gemspec +11 -8
  85. data/spec/app/models/mdm/event_spec.rb +17 -11
  86. data/spec/app/models/mdm/host_spec.rb +2 -2
  87. data/spec/app/models/mdm/module/action_spec.rb +0 -5
  88. data/spec/app/models/mdm/module/arch_spec.rb +0 -5
  89. data/spec/app/models/mdm/module/author_spec.rb +0 -6
  90. data/spec/app/models/mdm/module/detail_spec.rb +3 -3
  91. data/spec/app/models/mdm/module/mixin_spec.rb +0 -5
  92. data/spec/app/models/mdm/module/platform_spec.rb +0 -5
  93. data/spec/app/models/mdm/module/ref_spec.rb +0 -5
  94. data/spec/app/models/mdm/module/target_spec.rb +0 -6
  95. data/spec/app/models/mdm/ref_spec.rb +0 -3
  96. data/spec/app/models/mdm/service_spec.rb +1 -1
  97. data/spec/app/models/mdm/web_vuln_spec.rb +3 -3
  98. data/spec/app/models/mdm/wmap_request_spec.rb +2 -0
  99. data/spec/app/models/mdm/wmap_target_spec.rb +2 -0
  100. data/spec/app/models/mdm/workspace_spec.rb +2 -2
  101. data/spec/app/models/metasploit_data_models/search/operation/port/number_spec.rb +1 -1
  102. data/spec/dummy/config/application.rb +1 -7
  103. data/spec/dummy/config/environments/development.rb +2 -13
  104. data/spec/dummy/config/environments/production.rb +2 -0
  105. data/spec/dummy/config/environments/test.rb +2 -6
  106. data/spec/dummy/db/structure.sql +24 -19
  107. data/spec/dummy/db/structure.sql.from_rails_3 +3403 -0
  108. data/spec/factories/mdm/module/details.rb +1 -1
  109. data/spec/lib/ipaddr_spec.rb +31 -0
  110. data/spec/lib/metasploit_data_models/version_spec.rb +1 -3
  111. data/spec/support/shared/examples/coerces_inet_column_type_to_string.rb +15 -0
  112. metadata +63 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1295b513f0e595f45f1315528cec3ad0f4cf2de
4
- data.tar.gz: 9e7bb0f98fc9b16e90fd65c502e715fc31f5a34a
3
+ metadata.gz: 5190db99abdc62da0a77b62b517412b481be8957
4
+ data.tar.gz: a67d53030938408032e52f22a92c1f330195f4e0
5
5
  SHA512:
6
- metadata.gz: 29da581587c411a58073e15611381797eaa99d526e9f18bb4c41c7abf0d21cdce16050bdab6300431e0e65baca48b845dac7bbc9e30b6b5b7d226c1bd6cbffe9
7
- data.tar.gz: 7645723fa0cb86dd2b484f8a4e51fdaee78be760a41bb25f6ca60df9c6f174d702cc584e26e4e810819e04af8bd3473b7b88510753961529a3eed04cd361968e
6
+ metadata.gz: 1231e579d907eeedee180ab9ee77472cefbb0a72cfcbf8f78162fa9bd51366174875e4e9706d1e0ce1ded6233a7342557ab5a8d272677409a388bf1bed5816bd
7
+ data.tar.gz: 6eb74b74f6451727d9d739a307779283dd69a9a9003403d7cdf0e75aafa8f957fb93884c3d37e6bbd81cdc14e5ba5d04888f685e319e41907ef03ee4afd79052
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format nested
1
+ --format documentation
2
2
  --colour
3
3
  --drb
data/.simplecov CHANGED
@@ -7,7 +7,7 @@ unless ENV['RM_INFO']
7
7
  end
8
8
 
9
9
  SimpleCov.configure do
10
- load_adapter('rails')
10
+ load_profile('rails')
11
11
 
12
12
  # ignore this file
13
13
  add_filter '.simplecov'
data/Gemfile CHANGED
@@ -4,8 +4,9 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  group :development do
7
+ gem 'metasploit-erd', '1.0.0.pre.rails.pre.4.0'
7
8
  # embed ERDs on index, namespace Module and Class<ActiveRecord::Base> pages
8
- gem 'yard-metasploit-erd', '~> 0.0.2'
9
+ gem 'yard-metasploit-erd', '1.0.0.pre.rails.pre.4.0'
9
10
  end
10
11
 
11
12
  # used by dummy application
@@ -17,10 +18,12 @@ group :development, :test do
17
18
  gem 'factory_girl', '>= 4.1.0'
18
19
  # auto-load factories from spec/factories
19
20
  gem 'factory_girl_rails'
20
- # rails is only used for the dummy application in spec/dummy
21
- # restrict from rails 4.0 as it requires protected_attributes gem and other changes for compatibility
22
- # @see MSP-2971
23
- gem 'rails', '>= 3.2', '< 4.0.0'
21
+
22
+ rails_version_constraint = [
23
+ '>= 4.0.9',
24
+ '< 4.1.0'
25
+ ]
26
+ gem 'rails', *rails_version_constraint
24
27
  # Used to create fake data
25
28
  gem "faker"
26
29
  end
@@ -1,4 +1,5 @@
1
1
  class Mdm::ApiKey < ActiveRecord::Base
2
+
2
3
  #
3
4
  # Validators
4
5
  #
@@ -1,10 +1,10 @@
1
1
  class Mdm::Client < ActiveRecord::Base
2
2
  #
3
- # Relations
3
+ # Associations
4
4
  #
5
5
  belongs_to :host,
6
6
  class_name: 'Mdm::Host',
7
7
  inverse_of: :clients
8
-
8
+
9
9
  Metasploit::Concern.run(self)
10
10
  end
@@ -1,18 +1,6 @@
1
1
  class Mdm::Cred < ActiveRecord::Base
2
2
  #
3
- # CONSTANTS
4
- #
5
- KEY_ID_REGEX = /([0-9a-fA-F:]{47})/
6
- PTYPES = {
7
- 'read/write password' => 'password_rw',
8
- 'read-only password' => 'password_ro',
9
- 'SMB hash' => 'smb_hash',
10
- 'SSH private key' => 'ssh_key',
11
- 'SSH public key' => 'ssh_pubkey'
12
- }
13
-
14
- #
15
- # Relations
3
+ # Associations
16
4
  #
17
5
 
18
6
  # @!attribute [rw] servce
@@ -37,6 +25,18 @@ class Mdm::Cred < ActiveRecord::Base
37
25
  #
38
26
  # @return [Array<Mdm::Task>]
39
27
  has_many :tasks, :through => :task_creds
28
+
29
+ #
30
+ # CONSTANTS
31
+ #
32
+ KEY_ID_REGEX = /([0-9a-fA-F:]{47})/
33
+ PTYPES = {
34
+ 'read/write password' => 'password_rw',
35
+ 'read-only password' => 'password_ro',
36
+ 'SMB hash' => 'smb_hash',
37
+ 'SSH private key' => 'ssh_key',
38
+ 'SSH public key' => 'ssh_pubkey'
39
+ }
40
40
 
41
41
  after_create :increment_host_counter_cache
42
42
  after_destroy :decrement_host_counter_cache
@@ -1,6 +1,7 @@
1
1
  class Mdm::Event < ActiveRecord::Base
2
+
2
3
  #
3
- # Relations
4
+ # Associations
4
5
  #
5
6
 
6
7
  belongs_to :host,
@@ -10,13 +11,13 @@ class Mdm::Event < ActiveRecord::Base
10
11
  belongs_to :workspace,
11
12
  class_name: 'Mdm::Workspace',
12
13
  inverse_of: :events
13
-
14
+
14
15
  #
15
16
  # Scopes
16
17
  #
17
18
 
18
- scope :flagged, where(:critical => true, :seen => false)
19
- scope :module_run, where(:name => 'module_run')
19
+ scope :flagged, -> { where(:critical => true, :seen => false) }
20
+ scope :module_run, -> { where(:name => 'module_run') }
20
21
 
21
22
  #
22
23
  # Serializations
@@ -1,4 +1,5 @@
1
1
  class Mdm::ExploitAttempt < ActiveRecord::Base
2
+
2
3
  #
3
4
  # Associations
4
5
  #
@@ -1,6 +1,6 @@
1
1
  class Mdm::ExploitedHost < ActiveRecord::Base
2
2
  #
3
- # Relations
3
+ # Associations
4
4
  #
5
5
 
6
6
  belongs_to :host,
@@ -61,6 +61,18 @@ class Mdm::Host < ActiveRecord::Base
61
61
  'unknown'
62
62
  ]
63
63
 
64
+ #
65
+ # Aggregations
66
+ #
67
+
68
+ # @!attribute [rw] address
69
+ # The IP address of this host. Necessary to avoid coercion to an `IPAddr` object.
70
+ #
71
+ # @return [String]
72
+ def address
73
+ self[:address].to_s
74
+ end
75
+
64
76
  #
65
77
  # Associations
66
78
  #
@@ -132,20 +144,20 @@ class Mdm::Host < ActiveRecord::Base
132
144
  # @todo MSP-3065
133
145
  # @return [ActiveRecord::Relation<Mdm::Loot>]
134
146
  has_many :loots,
135
- class_name: 'Mdm::Loot',
136
- dependent: :destroy,
137
- inverse_of: :host,
138
- order: 'loots.created_at DESC'
147
+ -> { order('loots.created_at DESC')},
148
+ class_name: 'Mdm::Loot',
149
+ dependent: :destroy,
150
+ inverse_of: :host
139
151
 
140
152
  # @!attribute [rw] notes
141
153
  # Notes about the host entered by a user with {Mdm::Note#created_at oldest notes} first.
142
154
  #
143
155
  # @return [ActiveRecord::Relation<Mdm::Note>]
144
156
  has_many :notes,
145
- class_name: 'Mdm::Note',
146
- inverse_of: :host,
147
- dependent: :delete_all,
148
- order: 'notes.created_at'
157
+ -> { order('notes.created_at') },
158
+ class_name: 'Mdm::Note',
159
+ inverse_of: :host,
160
+ dependent: :delete_all
149
161
 
150
162
  # @!attribute [rw] services
151
163
  # The services running on {Mdm::Service#port ports} on the host with services ordered by {Mdm::Service#port port}
@@ -153,10 +165,10 @@ class Mdm::Host < ActiveRecord::Base
153
165
  #
154
166
  # @return [ActiveRecord::Relation<Mdm::Service>]
155
167
  has_many :services,
156
- class_name: 'Mdm::Service',
157
- dependent: :destroy,
158
- inverse_of: :host,
159
- order: 'services.port, services.proto'
168
+ -> { order('services.port, services.proto') },
169
+ class_name: 'Mdm::Service',
170
+ dependent: :destroy,
171
+ inverse_of: :host
160
172
 
161
173
  # @!attribute [rw] sessions
162
174
  # Sessions that are open or previously were open on the host ordered by {Mdm::Session#opened_at when the session was
@@ -164,10 +176,10 @@ class Mdm::Host < ActiveRecord::Base
164
176
  #
165
177
  # @return [ActiveRecord::Relation<Mdm::Session]
166
178
  has_many :sessions,
167
- class_name: 'Mdm::Session',
168
- dependent: :destroy,
169
- inverse_of: :host,
170
- order: 'sessions.opened_at'
179
+ -> { order('sessions.opened_at') },
180
+ class_name: 'Mdm::Session',
181
+ dependent: :destroy,
182
+ inverse_of: :host
171
183
 
172
184
  # @!attribute [rw] vulns
173
185
  # Vulnerabilities found on the host.
@@ -452,7 +464,7 @@ class Mdm::Host < ActiveRecord::Base
452
464
 
453
465
  validates :address,
454
466
  :exclusion => {
455
- :in => ['127.0.0.1']
467
+ :in => [IPAddr.new('127.0.0.1')]
456
468
  },
457
469
  :ip_format => true,
458
470
  :presence => true,
@@ -476,8 +488,8 @@ class Mdm::Host < ActiveRecord::Base
476
488
  # Scopes
477
489
  #
478
490
 
479
- scope :alive, where({'hosts.state' => 'alive'})
480
- scope :flagged, where('notes.critical = true AND notes.seen = false').includes(:notes)
491
+ scope :alive, -> { where({'hosts.state' => 'alive'}) }
492
+ scope :flagged, -> { where('notes.critical = true AND notes.seen = false').includes(:notes) }
481
493
  scope :search,
482
494
  lambda { |*args|
483
495
  # @todo replace with AREL
@@ -555,7 +567,12 @@ class Mdm::Host < ActiveRecord::Base
555
567
  # @return [void]
556
568
  def ip_address_invalid?
557
569
  begin
558
- potential_ip = IPAddr.new(address)
570
+ if address.is_a? IPAddr
571
+ potential_ip = address.dup
572
+ else
573
+ potential_ip = IPAddr.new(address)
574
+ end
575
+
559
576
  return true unless potential_ip.ipv4? || potential_ip.ipv6?
560
577
  rescue ArgumentError
561
578
  return true
@@ -1,6 +1,6 @@
1
1
  class Mdm::HostDetail < ActiveRecord::Base
2
2
  #
3
- # Relations
3
+ # Associations
4
4
  #
5
5
 
6
6
  belongs_to :host,
@@ -15,4 +15,4 @@ class Mdm::HostDetail < ActiveRecord::Base
15
15
  validates :host_id, :presence => true
16
16
 
17
17
  Metasploit::Concern.run(self)
18
- end
18
+ end
@@ -29,7 +29,7 @@ class Mdm::HostTag < ActiveRecord::Base
29
29
 
30
30
  # @see http://stackoverflow.com/a/11694704
31
31
  after_destroy :destroy_orphan_tag
32
-
32
+
33
33
  #
34
34
  # Instance Methods
35
35
  #
@@ -1,6 +1,7 @@
1
1
  class Mdm::Listener < ActiveRecord::Base
2
+
2
3
  #
3
- # Relations
4
+ # Associations
4
5
  #
5
6
 
6
7
  belongs_to :task,
@@ -1,6 +1,7 @@
1
1
  # Loot gathered from {#host} or {#service} such as files to prove you were on the system or to crack later to gain
2
2
  # sessions on other machines in the network.
3
3
  class Mdm::Loot < ActiveRecord::Base
4
+
4
5
  #
5
6
  # CONSTANTS
6
7
  #
@@ -13,7 +13,7 @@ class Mdm::Macro < ActiveRecord::Base
13
13
  # Validations
14
14
  #
15
15
 
16
- validates :name, :presence => true, :format => /^[^'|"]+$/
16
+ validates :name, :presence => true, :format => /\A[^'|"]+\z/
17
17
 
18
18
  Metasploit::Concern.run(self)
19
19
  end
@@ -1,3 +1,4 @@
1
1
  class Mdm::ModRef < ActiveRecord::Base
2
+
2
3
  Metasploit::Concern.run(self)
3
4
  end
@@ -1,5 +1,5 @@
1
1
  class Mdm::Module::Action < ActiveRecord::Base
2
- self.table_name = 'module_actions'
2
+ self.table_name = 'module_actions'
3
3
 
4
4
  #
5
5
  # Associations
@@ -7,12 +7,6 @@ class Mdm::Module::Action < ActiveRecord::Base
7
7
 
8
8
  belongs_to :detail, :class_name => 'Mdm::Module::Detail'
9
9
 
10
- #
11
- # Mass Assignment Security
12
- #
13
-
14
- attr_accessible :name
15
-
16
10
  #
17
11
  # Validations
18
12
  #
@@ -7,12 +7,6 @@ class Mdm::Module::Arch < ActiveRecord::Base
7
7
 
8
8
  belongs_to :detail, :class_name => 'Mdm::Module::Detail'
9
9
 
10
- #
11
- # Mass Assignment Security
12
- #
13
-
14
- attr_accessible :name
15
-
16
10
  #
17
11
  # Validations
18
12
  #
@@ -6,14 +6,7 @@ class Mdm::Module::Author < ActiveRecord::Base
6
6
  #
7
7
 
8
8
  belongs_to :detail, :class_name => 'Mdm::Module::Detail'
9
-
10
- #
11
- # Mass Assignment Security
12
- #
13
-
14
- attr_accessible :email
15
- attr_accessible :name
16
-
9
+
17
10
  #
18
11
  # Validations
19
12
  #
@@ -2,7 +2,7 @@
2
2
  # {Mdm::Module} namespace.
3
3
  class Mdm::Module::Detail < ActiveRecord::Base
4
4
  self.table_name = 'module_details'
5
-
5
+
6
6
  #
7
7
  # CONSTANTS
8
8
  #
@@ -7,12 +7,6 @@ class Mdm::Module::Mixin < ActiveRecord::Base
7
7
 
8
8
  belongs_to :detail, :class_name => 'Mdm::Module::Detail'
9
9
 
10
- #
11
- # Mass Assignment Security
12
- #
13
-
14
- attr_accessible :name
15
-
16
10
  #
17
11
  # Validation
18
12
  #
@@ -7,12 +7,6 @@ class Mdm::Module::Platform < ActiveRecord::Base
7
7
 
8
8
  belongs_to :detail, :class_name => 'Mdm::Module::Detail'
9
9
 
10
- #
11
- # Mass Assignment Security
12
- #
13
-
14
- attr_accessible :name
15
-
16
10
  #
17
11
  # Validations
18
12
  #
@@ -31,12 +31,6 @@ class Mdm::Module::Ref < ActiveRecord::Base
31
31
  #
32
32
  # @return [String]
33
33
 
34
- #
35
- # Mass Assignment Security
36
- #
37
-
38
- attr_accessible :name
39
-
40
34
  #
41
35
  # Validations
42
36
  #
@@ -7,13 +7,6 @@ class Mdm::Module::Target < ActiveRecord::Base
7
7
 
8
8
  belongs_to :detail, :class_name => 'Mdm::Module::Detail'
9
9
 
10
- #
11
- # Mass Assignment Security
12
- #
13
-
14
- attr_accessible :index
15
- attr_accessible :name
16
-
17
10
  #
18
11
  # Validators
19
12
  #