metasploit_data_models 1.2.7 → 1.2.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a832e9ced35288ddac2edbb5e3cd4d4eb19cbb5c
4
- data.tar.gz: a9f00670c0d01fe19f0991471f7344c6c3370915
3
+ metadata.gz: ac2e230d58545f2f98b7d4c884fe72f3a5019613
4
+ data.tar.gz: cf13ef55f75497f7433dac9fdc2cf38f6c20df12
5
5
  SHA512:
6
- metadata.gz: 255b6a0e805116a6c992657c38d1f25ba81a863cec6dde9f79c5263016c693043c80c99c812329bc4186aab2bc7bccafebde2e9967102afffb2fb50520c58aa1
7
- data.tar.gz: a0c035e7112895aee64de5fb2af85824dade5095b9d0da642d612c6d59d75d08a1a8216ac83cd95578fe68228561c0ba78ab8504c10d0971621b76eb62b54aef
6
+ metadata.gz: 4bb6f24caafd89021295f7042f1bf15db115d635c7a7a12696fa81bab8c612ca8ff6855b2a155187eceb58bfd1cbc08e72cae60bae9706e68ab04d0460aea45e
7
+ data.tar.gz: 38324d7b45f7fcb28a46d9d273a4da9d7120334f23df94e3288ac0005ad60ea36966b70013e1639d82d8a7c19a8b66b894f6b703ed1b72f56bd58ee2eb765d2b
data/Gemfile CHANGED
@@ -32,7 +32,7 @@ group :test do
32
32
  # In a full rails project, factory_girl_rails would be in both the :development, and :test group, but since we only
33
33
  # want rails in :test, factory_girl_rails must also only be in :test.
34
34
  # add matchers from shoulda, such as validates_presence_of, which are useful for testing validations
35
- gem 'shoulda-matchers'
35
+ gem 'shoulda-matchers', '~> 3.0'
36
36
  # code coverage of tests
37
37
  gem 'simplecov', :require => false
38
38
  # need rspec-rails >= 2.12.0 as 2.12.0 adds support for redefining named subject in nested context that uses the
@@ -122,16 +122,15 @@ class Mdm::Loot < ActiveRecord::Base
122
122
  #
123
123
 
124
124
  scope :search, lambda { |*args|
125
- # @todo replace with AREL
126
- terms = RELATIVE_SEARCH_FIELDS.collect { |relative_field|
127
- "loots.#{relative_field} ILIKE ?"
128
- }
129
- disjunction = terms.join(' OR ')
130
- formatted_parameter = "%#{args[0]}%"
131
- parameters = [formatted_parameter] * RELATIVE_SEARCH_FIELDS.length
132
- conditions = [disjunction] + parameters
133
-
134
- where(conditions)
125
+ joins(:host).
126
+ where(
127
+ 'loots.ltype ILIKE ? ' +
128
+ 'OR loots.name ILIKE ? ' +
129
+ 'OR loots.info ILIKE ? ' +
130
+ 'OR loots.data ILIKE ? ' +
131
+ 'OR COALESCE(hosts.name, CAST(hosts.address AS TEXT)) ILIKE ?',
132
+ "%#{args[0]}%", "%#{args[0]}%", "%#{args[0]}%", "%#{args[0]}%", "%#{args[0]}%"
133
+ )
135
134
  }
136
135
 
137
136
  #
@@ -90,11 +90,14 @@ class Mdm::Note < ActiveRecord::Base
90
90
  scope :visible, -> { where(Mdm::Note[:ntype].not_in(['web.form', 'web.url', 'web.vuln'])) }
91
91
 
92
92
  scope :search, lambda { |*args|
93
- where(["(data NOT ILIKE 'BAh7%' AND data LIKE ?)" +
94
- "OR (data ILIKE 'BAh7%' AND decode(data, 'base64') LIKE ?)" +
95
- "OR ntype ILIKE ?",
96
- "%#{args[0]}%", "%#{args[0]}%", "%#{args[0]}%"
97
- ])
93
+ joins(:host).
94
+ where(
95
+ "(notes.data NOT ILIKE 'BAh7%' AND notes.data LIKE ?) " +
96
+ "OR (notes.data ILIKE 'BAh7%' AND decode(notes.data, 'base64') LIKE ?) " +
97
+ 'OR notes.ntype ILIKE ? ' +
98
+ 'OR COALESCE(hosts.name, CAST(hosts.address AS TEXT)) ILIKE ?',
99
+ "%#{args[0]}%", "%#{args[0]}%", "%#{args[0]}%", "%#{args[0]}%"
100
+ )
98
101
  }
99
102
 
100
103
  #
@@ -170,13 +170,15 @@ class Mdm::Service < ActiveRecord::Base
170
170
  scope :inactive, -> { where("services.state != 'open'") }
171
171
  scope :with_state, lambda { |a_state| where("services.state = ?", a_state)}
172
172
  scope :search, lambda { |*args|
173
- where([
174
- "services.name ILIKE ? OR " +
175
- "services.info ILIKE ? OR " +
176
- "services.proto ILIKE ? OR " +
177
- "services.port = ? ",
178
- "%#{args[0]}%", "%#{args[0]}%", "%#{args[0]}%", (args[0].to_i > 0) ? args[0].to_i : 99999
179
- ])
173
+ joins(:host).
174
+ where(
175
+ 'services.name ILIKE ? OR ' +
176
+ 'services.info ILIKE ? OR ' +
177
+ 'services.proto ILIKE ? OR ' +
178
+ 'services.port = ? OR ' +
179
+ 'COALESCE(hosts.name, CAST(hosts.address AS TEXT)) ILIKE ?',
180
+ "%#{args[0]}%", "%#{args[0]}%", "%#{args[0]}%", (args[0].to_i > 0) ? args[0].to_i : 99999, "%#{args[0]}%"
181
+ )
180
182
  }
181
183
 
182
184
  #
@@ -1,6 +1,6 @@
1
1
  # A vulnerability found on a {#host} or {#service}.
2
2
  class Mdm::Vuln < ActiveRecord::Base
3
-
3
+
4
4
  #
5
5
  # Associations
6
6
  #
@@ -169,15 +169,16 @@ class Mdm::Vuln < ActiveRecord::Base
169
169
 
170
170
  scope :search, lambda { |query|
171
171
  formatted_query = "%#{query}%"
172
-
173
172
  where(
174
- arel_table[:name].matches(formatted_query).or(
175
- arel_table[:info].matches(formatted_query)
176
- ).or(
177
- Mdm::Ref.arel_table[:name].matches(formatted_query)
178
- )
173
+ arel_table[:name].matches(formatted_query).or(
174
+ arel_table[:info].matches(formatted_query)
175
+ ).or(
176
+ Mdm::Ref.arel_table[:name].matches(formatted_query)
177
+ ).or(
178
+ Arel::Nodes::NamedFunction.new('CAST', [Mdm::Host.arel_table[:address].as('TEXT')]).matches(formatted_query)
179
+ )
179
180
  ).includes(
180
- :refs
181
+ :refs, :host
181
182
  )
182
183
  }
183
184
 
@@ -10,8 +10,7 @@ module MetasploitDataModels
10
10
  # The minor version number, scoped to the {MAJOR} version number.
11
11
  MINOR = 2
12
12
  # The patch version number, scoped to the {MAJOR} and {MINOR} version numbers.
13
- PATCH = 7
14
-
13
+ PATCH = 8
15
14
 
16
15
  #
17
16
  # Module Methods
@@ -63,6 +63,12 @@ RSpec.describe Mdm::Loot, type: :model do
63
63
  myloot = FactoryGirl.create(:mdm_loot, :info => 'Find This')
64
64
  expect(Mdm::Loot.search('Find This')).to include(myloot)
65
65
  end
66
+
67
+ it 'should match on hostname' do
68
+ myloot = FactoryGirl.create(:mdm_loot, :info => 'Find This')
69
+ host_name = myloot.host.name
70
+ expect(Mdm::Loot.search(host_name)).to include(myloot)
71
+ end
66
72
  end
67
73
  end
68
74
 
@@ -240,7 +240,10 @@ RSpec.describe Mdm::Module::Detail, type: :model do
240
240
  # validate_inclusion_of(:privileged).in_array([true, false]) will fail on the disallowed values check.
241
241
 
242
242
  context 'rank' do
243
- it { is_expected.to validate_numericality_of(:rank).only_integer }
243
+ it 'validates rank is only an integer', pending: 'https://github.com/thoughtbot/shoulda-matchers/issues/784' do
244
+ is_expected.to validate_numericality_of(:rank).only_integer
245
+ end
246
+
244
247
  it { is_expected.to validate_inclusion_of(:rank).in_array(ranks) }
245
248
  end
246
249
 
@@ -80,6 +80,12 @@ RSpec.describe Mdm::Note, type: :model do
80
80
  flagged_note = FactoryGirl.create(:mdm_note, :ntype => 'flag.me', :critical => true, :seen => false)
81
81
  expect(Mdm::Note.search('flag.me')).to include(flagged_note)
82
82
  end
83
+
84
+ it 'should match on host name' do
85
+ flagged_note = FactoryGirl.create(:mdm_note, :seen => false)
86
+ host_name = flagged_note.host.name
87
+ expect(Mdm::Note.search(host_name)).to include(flagged_note)
88
+ end
83
89
  end
84
90
  end
85
91
  end
@@ -53,14 +53,20 @@ RSpec.describe Mdm::Service, type: :model do
53
53
  end
54
54
  end
55
55
 
56
- context "search for 'tcp'" do
57
- it "should find only services that match" do
56
+ context 'search' do
57
+ it 'should find only services that match for \'tcp\'' do
58
58
  tcp_service = FactoryGirl.create(:mdm_service, proto: 'tcp')
59
59
  udp_service = FactoryGirl.create(:mdm_service, proto: 'udp')
60
60
  search_results = Mdm::Service.search('tcp')
61
61
  expect(search_results).to include(tcp_service)
62
62
  expect(search_results).not_to include(udp_service)
63
63
  end
64
+
65
+ it 'should query host name of services' do
66
+ service = FactoryGirl.create(:mdm_service)
67
+ host_name = service.host.name
68
+ expect(Mdm::Service.search(host_name)).to include(service)
69
+ end
64
70
  end
65
71
  end
66
72
 
@@ -174,7 +180,10 @@ RSpec.describe Mdm::Service, type: :model do
174
180
  FactoryGirl.build(:mdm_service)
175
181
  }
176
182
 
177
- it { is_expected.to validate_numericality_of(:port).only_integer }
183
+ it 'validate port is only an integer', pending: 'https://github.com/thoughtbot/shoulda-matchers/issues/784' do
184
+ is_expected.to validate_numericality_of(:port).only_integer
185
+ end
186
+
178
187
  it { is_expected.to validate_inclusion_of(:proto).in_array(described_class::PROTOS) }
179
188
 
180
189
  context 'when a duplicate service already exists' do
@@ -256,6 +256,17 @@ RSpec.describe Mdm::Vuln, type: :model do
256
256
  end
257
257
  end
258
258
  end
259
+
260
+ context 'with Mdm::Host' do
261
+ context 'with query matching Mdm::Host address' do
262
+ let(:vuln_with_host) { FactoryGirl.create(:mdm_vuln, :host)}
263
+ let(:query) { vuln_with_host.host.address}
264
+
265
+ it 'should match Mdm::Vuln' do
266
+ expect(results).to match_array [vuln_with_host]
267
+ end
268
+ end
269
+ end
259
270
  end
260
271
  end
261
272
  end
@@ -115,10 +115,6 @@ RSpec.describe Mdm::WebVuln, type: :model do
115
115
  it { is_expected.to validate_presence_of :path }
116
116
 
117
117
  context 'params' do
118
- it 'should not validate presence of params because it default to [] and can never be nil' do
119
- expect(web_vuln).not_to validate_presence_of(:params)
120
- end
121
-
122
118
  context 'validates parameters' do
123
119
  let(:type_signature_sentence) do
124
120
  "Valid parameters are an Array<Array(String, String)>."
@@ -138,11 +138,11 @@ RSpec.describe Mdm::Workspace, type: :model do
138
138
  end
139
139
 
140
140
  context 'description' do
141
- it { is_expected.to ensure_length_of(:description).is_at_most(4 * (2 ** 10)) }
141
+ it { is_expected.to validate_length_of(:description).is_at_most(4 * (2 ** 10)) }
142
142
  end
143
143
 
144
144
  context 'name' do
145
- it { is_expected.to ensure_length_of(:name).is_at_most(2**8 - 1) }
145
+ it { is_expected.to validate_length_of(:name).is_at_most(2**8 - 1) }
146
146
  it { is_expected.to validate_presence_of :name }
147
147
  it { is_expected.to validate_uniqueness_of :name }
148
148
  end
@@ -10,7 +10,9 @@ RSpec.describe MetasploitDataModels::IPAddress::V4::Segment::Single, type: :mode
10
10
  }
11
11
 
12
12
  context 'validations' do
13
- it { is_expected.to validate_numericality_of(:value).is_greater_than_or_equal_to(0).is_less_than_or_equal_to(255).only_integer }
13
+ it 'validates value is only an integer between 0 and 255 inclusive', pending: 'https://github.com/thoughtbot/shoulda-matchers/issues/784' do
14
+ is_expected.to validate_numericality_of(:value).is_greater_than_or_equal_to(0).is_less_than_or_equal_to(255).only_integer
15
+ end
14
16
  end
15
17
 
16
18
  it 'can be used in a Range' do
@@ -10,7 +10,7 @@ RSpec.describe MetasploitDataModels::Search::Operator::Multitext, type: :model d
10
10
  }
11
11
 
12
12
  context 'validations' do
13
- it { is_expected.to ensure_length_of(:operator_names).is_at_least(2) }
13
+ it { is_expected.to validate_length_of(:operator_names).is_at_least(2) }
14
14
  it { is_expected.to validate_presence_of :name }
15
15
  end
16
16
 
@@ -1,4 +1,4 @@
1
- RSpec.describe MetasploitDataModels::IPAddress::CIDR do
1
+ RSpec.describe MetasploitDataModels::IPAddress::CIDR, type: :model do
2
2
  subject(:including_class_instance) {
3
3
  including_class.new(
4
4
  value: formatted_value
@@ -138,7 +138,7 @@ RSpec.describe MetasploitDataModels::IPAddress::CIDR do
138
138
  segment_count * segment_bits
139
139
  }
140
140
 
141
- it 'validates it is an integer between 0 and maximum_prefix_length' do
141
+ it 'validates it is an integer between 0 and maximum_prefix_length', pending: 'https://github.com/thoughtbot/shoulda-matchers/issues/784' do
142
142
  expect(including_class_instance).to validate_numericality_of(:prefix_length).only_integer.is_greater_than_or_equal_to(0).is_less_than_or_equal_to(maximum_prefix_length)
143
143
  end
144
144
  end
@@ -128,3 +128,12 @@ RSpec.configure do |config|
128
128
  allow_any_instance_of(Mdm::Workspace).to receive(:valid_ip_or_range?).and_return(true)
129
129
  end
130
130
  end
131
+
132
+ Shoulda::Matchers.configure do |config|
133
+ config.integrate do |with|
134
+ with.library :active_record
135
+ with.library :active_model
136
+
137
+ with.test_framework :rspec
138
+ end
139
+ 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: 1.2.7
4
+ version: 1.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Huckins
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-09-29 00:00:00.000000000 Z
14
+ date: 2015-10-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: metasploit-version
@@ -731,7 +731,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
731
731
  version: '0'
732
732
  requirements: []
733
733
  rubyforge_project:
734
- rubygems_version: 2.4.3
734
+ rubygems_version: 2.4.8
735
735
  signing_key:
736
736
  specification_version: 4
737
737
  summary: Database code for MSF and Metasploit Pro