metasploit_data_models 1.0.0.pre.rails.pre.4.0b → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -2
- data/.travis.yml +6 -3
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +10 -52
- data/Gemfile +4 -6
- data/RELEASING.md +88 -0
- data/Rakefile +23 -0
- data/UPGRADING.md +1 -0
- data/app/models/mdm/api_key.rb +41 -1
- data/app/models/mdm/client.rb +41 -1
- data/app/models/mdm/cred.rb +116 -28
- data/app/models/mdm/event.rb +47 -0
- data/app/models/mdm/exploit_attempt.rb +65 -16
- data/app/models/mdm/exploited_host.rb +27 -0
- data/app/models/mdm/host_detail.rb +44 -0
- data/app/models/mdm/host_tag.rb +6 -8
- data/app/models/mdm/listener.rb +52 -0
- data/app/models/mdm/macro.rb +42 -0
- data/app/models/mdm/mod_ref.rb +21 -1
- data/app/models/mdm/module/action.rb +15 -0
- data/app/models/mdm/module/arch.rb +10 -0
- data/app/models/mdm/module/author.rb +17 -1
- data/app/models/mdm/module/mixin.rb +13 -0
- data/app/models/mdm/module/platform.rb +11 -0
- data/app/models/mdm/module/target.rb +18 -0
- data/app/models/mdm/nexpose_console.rb +82 -4
- data/app/models/mdm/profile.rb +36 -0
- data/app/models/mdm/route.rb +16 -4
- data/app/models/mdm/session_event.rb +32 -0
- data/app/models/mdm/tag.rb +48 -9
- data/app/models/mdm/task.rb +85 -46
- data/app/models/mdm/task_cred.rb +29 -0
- data/app/models/mdm/task_host.rb +25 -0
- data/app/models/mdm/task_service.rb +25 -0
- data/app/models/mdm/task_session.rb +25 -0
- data/app/models/mdm/user.rb +192 -6
- data/app/models/mdm/vuln_attempt.rb +37 -12
- data/app/models/mdm/vuln_detail.rb +138 -5
- data/app/models/mdm/vuln_ref.rb +3 -0
- data/app/models/mdm/web_form.rb +34 -0
- data/app/models/mdm/web_page.rb +69 -0
- data/app/models/mdm/web_site.rb +50 -0
- data/app/models/mdm/wmap_request.rb +85 -0
- data/app/models/mdm/wmap_target.rb +40 -0
- data/app/models/mdm/workspace.rb +160 -17
- data/app/models/metasploit_data_models/automatic_exploitation/match.rb +13 -23
- data/app/models/metasploit_data_models/automatic_exploitation/match_result.rb +25 -4
- data/app/models/metasploit_data_models/automatic_exploitation/match_set.rb +15 -4
- data/app/models/metasploit_data_models/automatic_exploitation/run.rb +7 -3
- data/app/models/metasploit_data_models/ip_address/v4/segmented.rb +1 -1
- data/app/models/metasploit_data_models/module_run.rb +1 -1
- data/app/models/metasploit_data_models/search/visitor/where.rb +1 -1
- data/app/validators/ip_format_validator.rb +4 -0
- data/app/validators/parameters_validator.rb +12 -0
- data/app/validators/password_is_strong_validator.rb +10 -1
- data/lib/mdm/host/operating_system_normalization.rb +7 -10
- data/lib/metasploit_data_models.rb +4 -0
- data/lib/metasploit_data_models/automatic_exploitation.rb +25 -0
- data/lib/metasploit_data_models/engine.rb +2 -0
- data/lib/metasploit_data_models/serialized_prefs.rb +6 -0
- data/lib/metasploit_data_models/version.rb +30 -7
- data/metasploit_data_models.gemspec +9 -2
- data/spec/app/models/mdm/api_key_spec.rb +1 -3
- data/spec/app/models/mdm/client_spec.rb +9 -11
- data/spec/app/models/mdm/cred_spec.rb +42 -54
- data/spec/app/models/mdm/event_spec.rb +22 -24
- data/spec/app/models/mdm/exploit_attempt_spec.rb +19 -21
- data/spec/app/models/mdm/exploited_host_spec.rb +11 -13
- data/spec/app/models/mdm/host_detail_spec.rb +15 -17
- data/spec/app/models/mdm/host_spec.rb +262 -260
- data/spec/app/models/mdm/host_tag_spec.rb +6 -8
- data/spec/app/models/mdm/listener_spec.rb +30 -32
- data/spec/app/models/mdm/loot_spec.rb +21 -23
- data/spec/app/models/mdm/macro_spec.rb +1 -3
- data/spec/app/models/mdm/mod_ref_spec.rb +1 -3
- data/spec/app/models/mdm/module/action_spec.rb +8 -10
- data/spec/app/models/mdm/module/arch_spec.rb +8 -10
- data/spec/app/models/mdm/module/author_spec.rb +19 -14
- data/spec/app/models/mdm/module/detail_spec.rb +184 -75
- data/spec/app/models/mdm/module/mixin_spec.rb +8 -10
- data/spec/app/models/mdm/module/platform_spec.rb +8 -10
- data/spec/app/models/mdm/module/ref_spec.rb +8 -10
- data/spec/app/models/mdm/module/target_spec.rb +10 -12
- data/spec/app/models/mdm/nexpose_console_spec.rb +35 -37
- data/spec/app/models/mdm/note_spec.rb +23 -25
- data/spec/app/models/mdm/profile_spec.rb +1 -3
- data/spec/app/models/mdm/ref_spec.rb +9 -12
- data/spec/app/models/mdm/route_spec.rb +6 -8
- data/spec/app/models/mdm/service_spec.rb +38 -40
- data/spec/app/models/mdm/session_event_spec.rb +10 -12
- data/spec/app/models/mdm/session_spec.rb +13 -15
- data/spec/app/models/mdm/tag_spec.rb +29 -30
- data/spec/app/models/mdm/task_cred_spec.rb +9 -11
- data/spec/app/models/mdm/task_host_spec.rb +9 -11
- data/spec/app/models/mdm/task_service_spec.rb +9 -11
- data/spec/app/models/mdm/task_session_spec.rb +7 -9
- data/spec/app/models/mdm/task_spec.rb +27 -29
- data/spec/app/models/mdm/user_spec.rb +17 -19
- data/spec/app/models/mdm/vuln_attempt_spec.rb +14 -16
- data/spec/app/models/mdm/vuln_detail_spec.rb +26 -28
- data/spec/app/models/mdm/vuln_ref_spec.rb +8 -10
- data/spec/app/models/mdm/vuln_spec.rb +24 -26
- data/spec/app/models/mdm/web_form_spec.rb +11 -13
- data/spec/app/models/mdm/web_page_spec.rb +19 -21
- data/spec/app/models/mdm/web_site_spec.rb +21 -23
- data/spec/app/models/mdm/web_vuln_spec.rb +63 -65
- data/spec/app/models/mdm/wmap_request_spec.rb +1 -3
- data/spec/app/models/mdm/wmap_target_spec.rb +1 -3
- data/spec/app/models/mdm/workspace_spec.rb +97 -100
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_result_spec.rb +3 -5
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_set_spec.rb +13 -15
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_spec.rb +1 -3
- data/spec/app/models/metasploit_data_models/automatic_exploitation/run_spec.rb +1 -3
- data/spec/app/models/metasploit_data_models/ip_address/v4/cidr_spec.rb +10 -12
- data/spec/app/models/metasploit_data_models/ip_address/v4/nmap_spec.rb +4 -6
- data/spec/app/models/metasploit_data_models/ip_address/v4/range_spec.rb +21 -23
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/list_spec.rb +9 -11
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/range_spec.rb +21 -23
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/segmented_spec.rb +4 -6
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/single_spec.rb +22 -15
- data/spec/app/models/metasploit_data_models/ip_address/v4/single_spec.rb +4 -6
- data/spec/app/models/metasploit_data_models/module_run_spec.rb +1 -3
- data/spec/app/models/metasploit_data_models/search/operation/ip_address_spec.rb +18 -20
- data/spec/app/models/metasploit_data_models/search/operation/port/number_spec.rb +6 -8
- data/spec/app/models/metasploit_data_models/search/operation/port/range_spec.rb +8 -10
- data/spec/app/models/metasploit_data_models/search/operation/range_spec.rb +8 -10
- data/spec/app/models/metasploit_data_models/search/operator/ip_address_spec.rb +2 -4
- data/spec/app/models/metasploit_data_models/search/operator/multitext_spec.rb +8 -10
- data/spec/app/models/metasploit_data_models/search/operator/port/list_spec.rb +6 -8
- data/spec/app/models/metasploit_data_models/search/visitor/attribute_spec.rb +9 -11
- data/spec/app/models/metasploit_data_models/search/visitor/includes_spec.rb +5 -7
- data/spec/app/models/metasploit_data_models/search/visitor/joins_spec.rb +17 -19
- data/spec/app/models/metasploit_data_models/search/visitor/method_spec.rb +5 -7
- data/spec/app/models/metasploit_data_models/search/visitor/relation_spec.rb +61 -23
- data/spec/app/models/metasploit_data_models/search/visitor/where_spec.rb +8 -10
- data/spec/app/validators/parameters_validator_spec.rb +29 -29
- data/spec/app/validators/password_is_strong_validator_spec.rb +54 -46
- data/spec/lib/base64_serializer_spec.rb +19 -21
- data/spec/lib/ipaddr_spec.rb +1 -3
- data/spec/lib/metasploit_data_models/ip_address/cidr_spec.rb +18 -12
- data/spec/lib/metasploit_data_models/ip_address/range_spec.rb +4 -6
- data/spec/lib/metasploit_data_models/match/child_spec.rb +2 -4
- data/spec/lib/metasploit_data_models/match/parent_spec.rb +4 -6
- data/spec/lib/metasploit_data_models/version_spec.rb +3 -139
- data/spec/lib/metasploit_data_models_spec.rb +4 -0
- data/spec/spec_helper.rb +86 -12
- data/spec/support/shared/examples/mdm/module/detail/does_not_support_stance_with_mtype.rb +2 -2
- data/spec/support/shared/examples/mdm/module/detail/supports_stance_with_mtype.rb +4 -4
- data/spec/support/shared/examples/metasploit_data_models/search/operation/ipaddress/match.rb +2 -2
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_children.rb +5 -5
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_metasploit_model_search_operation_base.rb +5 -5
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_equality.rb +3 -3
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_metasploit_model_search_group_base.rb +7 -6
- metadata +74 -14
- data/app/models/metasploit_data_models/automatic_exploitation.rb +0 -16
- data/lib/tasks/yard.rake +0 -33
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe Mdm::Host do
|
1
|
+
RSpec.describe Mdm::Host, type: :model do
|
4
2
|
subject(:host) do
|
5
3
|
FactoryGirl.build(:mdm_host)
|
6
4
|
end
|
@@ -41,15 +39,18 @@ describe Mdm::Host do
|
|
41
39
|
it_should_behave_like 'Metasploit::Concern.run'
|
42
40
|
|
43
41
|
context 'factory' do
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
context 'mdm_host' do
|
43
|
+
subject(:mdm_host) {
|
44
|
+
FactoryGirl.build(:mdm_host)
|
45
|
+
}
|
46
|
+
|
47
|
+
it { is_expected.to be_valid }
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
51
|
context 'Constants' do
|
51
52
|
subject(:max_nmap_certainty) { described_class::MAX_NMAP_CERTAINTY }
|
52
|
-
it {
|
53
|
+
it { is_expected.to eq(0.84) }
|
53
54
|
end
|
54
55
|
|
55
56
|
context '#destroy' do
|
@@ -103,19 +104,19 @@ describe Mdm::Host do
|
|
103
104
|
end
|
104
105
|
|
105
106
|
context 'associations' do
|
106
|
-
it {
|
107
|
-
it {
|
108
|
-
it {
|
109
|
-
it {
|
110
|
-
it {
|
111
|
-
it {
|
112
|
-
it {
|
113
|
-
it {
|
114
|
-
it {
|
115
|
-
it {
|
107
|
+
it { is_expected.to have_many(:creds).class_name('Mdm::Cred').through(:services) }
|
108
|
+
it { is_expected.to have_many(:clients).class_name('Mdm::Client').dependent(:destroy) }
|
109
|
+
it { is_expected.to have_many(:exploit_attempts).class_name('Mdm::ExploitAttempt').dependent(:destroy) }
|
110
|
+
it { is_expected.to have_many(:exploited_hosts).class_name('Mdm::ExploitedHost').dependent(:destroy) }
|
111
|
+
it { is_expected.to have_many(:host_details).class_name('Mdm::HostDetail').dependent(:destroy) }
|
112
|
+
it { is_expected.to have_many(:hosts_tags).class_name('Mdm::HostTag') }
|
113
|
+
it { is_expected.to have_many(:loots).class_name('Mdm::Loot').dependent(:destroy).order('loots.created_at DESC') }
|
114
|
+
it { is_expected.to have_many(:module_runs).class_name('MetasploitDataModels::ModuleRun') }
|
115
|
+
it { is_expected.to have_many(:task_hosts).class_name('Mdm::TaskHost').dependent(:destroy) }
|
116
|
+
it { is_expected.to have_many(:tasks).class_name('Mdm::Task').through(:task_hosts) }
|
116
117
|
|
117
118
|
context 'module_details' do
|
118
|
-
it {
|
119
|
+
it { is_expected.to have_many(:module_details).class_name('Mdm::Module::Detail').through(:module_refs) }
|
119
120
|
|
120
121
|
context 'with Mdm::Vulns' do
|
121
122
|
let!(:vulns) do
|
@@ -188,8 +189,8 @@ describe Mdm::Host do
|
|
188
189
|
module_details << module_ref.detail
|
189
190
|
end
|
190
191
|
|
191
|
-
|
192
|
-
module_details.uniq.count.
|
192
|
+
expect(architectures).to include('mips')
|
193
|
+
expect(module_details.uniq.count).to eq(host.module_details.count)
|
193
194
|
end
|
194
195
|
end
|
195
196
|
end
|
@@ -198,17 +199,17 @@ describe Mdm::Host do
|
|
198
199
|
end
|
199
200
|
end
|
200
201
|
|
201
|
-
it {
|
202
|
-
it {
|
203
|
-
it {
|
204
|
-
it {
|
205
|
-
it {
|
206
|
-
it {
|
207
|
-
it {
|
208
|
-
it {
|
209
|
-
it {
|
210
|
-
it {
|
211
|
-
it {
|
202
|
+
it { is_expected.to have_many(:module_refs).class_name('Mdm::Module::Ref').through(:refs) }
|
203
|
+
it { is_expected.to have_many(:notes).class_name('Mdm::Note').dependent(:delete_all).order('notes.created_at') }
|
204
|
+
it { is_expected.to have_many(:refs).class_name('Mdm::Ref').through(:vuln_refs) }
|
205
|
+
it { is_expected.to have_many(:services).class_name('Mdm::Service').dependent(:destroy).order('services.port, services.proto') }
|
206
|
+
it { is_expected.to have_many(:service_notes).through(:services) }
|
207
|
+
it { is_expected.to have_many(:sessions).class_name('Mdm::Session').dependent(:destroy).order('sessions.opened_at') }
|
208
|
+
it { is_expected.to have_many(:tags).class_name('Mdm::Tag').through(:hosts_tags) }
|
209
|
+
it { is_expected.to have_many(:vulns).class_name('Mdm::Vuln').dependent(:delete_all) }
|
210
|
+
it { is_expected.to have_many(:vuln_refs).class_name('Mdm::VulnRef') }
|
211
|
+
it { is_expected.to have_many(:web_sites).class_name('Mdm::WebSite').through(:services) }
|
212
|
+
it { is_expected.to belong_to(:workspace).class_name('Mdm::Workspace') }
|
212
213
|
end
|
213
214
|
|
214
215
|
context 'CONSTANTS' do
|
@@ -218,70 +219,70 @@ describe Mdm::Host do
|
|
218
219
|
end
|
219
220
|
|
220
221
|
it 'should be an Array<String>' do
|
221
|
-
architectures.
|
222
|
+
expect(architectures).to include('mips')
|
222
223
|
|
223
224
|
architectures.each do |architecture|
|
224
|
-
|
225
|
+
expect(architectures).to include('mips')
|
225
226
|
end
|
226
227
|
end
|
227
228
|
|
228
229
|
it 'should include both endians of ARM' do
|
229
|
-
architectures.
|
230
|
-
architectures.
|
230
|
+
expect(architectures).to include('mips')
|
231
|
+
expect(architectures).to include('mips')
|
231
232
|
end
|
232
233
|
|
233
234
|
it 'should include 32-bit and 64-bit versions of Cell Broadband Engine Architecture' do
|
234
|
-
architectures.
|
235
|
-
architectures.
|
235
|
+
expect(architectures).to include('mips')
|
236
|
+
expect(architectures).to include('mips')
|
236
237
|
end
|
237
238
|
|
238
239
|
it 'should include cmd for command shell' do
|
239
|
-
architectures.
|
240
|
+
expect(architectures).to include('mips')
|
240
241
|
end
|
241
242
|
|
242
243
|
it 'should include java for Java Virtual Machine' do
|
243
|
-
architectures.
|
244
|
+
expect(architectures).to include('mips')
|
244
245
|
end
|
245
246
|
|
246
247
|
it 'should include plain and endian-ware MIPS' do
|
247
|
-
architectures.
|
248
|
-
architectures.
|
249
|
-
architectures.
|
248
|
+
expect(architectures).to include('mips')
|
249
|
+
expect(architectures).to include('mipsbe')
|
250
|
+
expect(architectures).to include('mipsle')
|
250
251
|
end
|
251
252
|
|
252
253
|
it 'should include php for PHP code' do
|
253
|
-
architectures.
|
254
|
+
expect(architectures).to include('php')
|
254
255
|
end
|
255
256
|
|
256
257
|
it 'should include 32-bit and 64-bit PowerPC' do
|
257
|
-
architectures.
|
258
|
-
architectures.
|
258
|
+
expect(architectures).to include('ppc')
|
259
|
+
expect(architectures).to include('ppc64')
|
259
260
|
end
|
260
261
|
|
261
262
|
it 'should include ruby for Ruby code' do
|
262
|
-
architectures.
|
263
|
+
expect(architectures).to include('ruby')
|
263
264
|
end
|
264
265
|
|
265
266
|
it 'should include sparc for Sparc' do
|
266
|
-
architectures.
|
267
|
+
expect(architectures).to include('sparc')
|
267
268
|
end
|
268
269
|
|
269
270
|
it 'should include tty for Terminals' do
|
270
|
-
architectures.
|
271
|
+
expect(architectures).to include('tty')
|
271
272
|
end
|
272
273
|
|
273
274
|
it 'should include 32-bit and 64-bit x86' do
|
274
|
-
architectures.
|
275
|
-
architectures.
|
276
|
-
architectures.
|
275
|
+
expect(architectures).to include('x64')
|
276
|
+
expect(architectures).to include('x86')
|
277
|
+
expect(architectures).to include('x86_64')
|
277
278
|
end
|
278
279
|
|
279
280
|
it 'should include blank string to indicate no detection has happened' do
|
280
|
-
architectures.
|
281
|
+
expect(architectures).to include('')
|
281
282
|
end
|
282
283
|
|
283
284
|
it 'should include "Unknown" for failed detection attempts' do
|
284
|
-
architectures.
|
285
|
+
expect(architectures).to include('Unknown')
|
285
286
|
end
|
286
287
|
|
287
288
|
end
|
@@ -292,71 +293,71 @@ describe Mdm::Host do
|
|
292
293
|
end
|
293
294
|
|
294
295
|
it 'should be an Array<String>' do
|
295
|
-
search_fields.
|
296
|
+
expect(search_fields).to be_an Array
|
296
297
|
|
297
298
|
search_fields.each { |search_field|
|
298
|
-
search_field.
|
299
|
+
expect(search_field).to be_a String
|
299
300
|
}
|
300
301
|
end
|
301
302
|
|
302
303
|
it 'should cast address to text' do
|
303
|
-
search_fields.
|
304
|
+
expect(search_fields).to include('address::text')
|
304
305
|
end
|
305
306
|
|
306
|
-
it {
|
307
|
-
it {
|
308
|
-
it {
|
309
|
-
it {
|
310
|
-
it {
|
311
|
-
it {
|
312
|
-
it {
|
307
|
+
it { is_expected.to include('comments') }
|
308
|
+
it { is_expected.to include('mac') }
|
309
|
+
it { is_expected.to include('name') }
|
310
|
+
it { is_expected.to include('os_flavor') }
|
311
|
+
it { is_expected.to include('os_name') }
|
312
|
+
it { is_expected.to include('os_sp') }
|
313
|
+
it { is_expected.to include('purpose') }
|
313
314
|
end
|
314
315
|
|
315
316
|
it 'should define STATES in any order' do
|
316
|
-
described_class::STATES.
|
317
|
+
expect(described_class::STATES).to match_array(states)
|
317
318
|
end
|
318
319
|
end
|
319
320
|
|
320
321
|
context 'database' do
|
321
322
|
context 'columns' do
|
322
|
-
it {
|
323
|
-
it {
|
324
|
-
it {
|
325
|
-
it {
|
326
|
-
it {
|
327
|
-
it {
|
328
|
-
it {
|
329
|
-
it {
|
330
|
-
it {
|
331
|
-
it {
|
332
|
-
it {
|
333
|
-
it {
|
334
|
-
it {
|
335
|
-
it {
|
336
|
-
it {
|
337
|
-
it {
|
323
|
+
it { is_expected.to have_db_column(:address).of_type(:inet).with_options(:null => false) }
|
324
|
+
it { is_expected.to have_db_column(:arch).of_type(:string) }
|
325
|
+
it { is_expected.to have_db_column(:comm).of_type(:string) }
|
326
|
+
it { is_expected.to have_db_column(:comments).of_type(:text) }
|
327
|
+
it { is_expected.to have_db_column(:info).of_type(:string).with_options(:limit => 2 ** 16) }
|
328
|
+
it { is_expected.to have_db_column(:mac).of_type(:string) }
|
329
|
+
it { is_expected.to have_db_column(:name).of_type(:string) }
|
330
|
+
it { is_expected.to have_db_column(:os_flavor).of_type(:string) }
|
331
|
+
it { is_expected.to have_db_column(:os_lang).of_type(:string) }
|
332
|
+
it { is_expected.to have_db_column(:os_name).of_type(:string) }
|
333
|
+
it { is_expected.to have_db_column(:os_sp).of_type(:string) }
|
334
|
+
it { is_expected.to have_db_column(:purpose).of_type(:text) }
|
335
|
+
it { is_expected.to have_db_column(:scope).of_type(:text) }
|
336
|
+
it { is_expected.to have_db_column(:state).of_type(:string) }
|
337
|
+
it { is_expected.to have_db_column(:virtual_host).of_type(:text) }
|
338
|
+
it { is_expected.to have_db_column(:workspace_id).of_type(:integer).with_options(:null => false) }
|
338
339
|
|
339
340
|
context 'counter caches' do
|
340
|
-
it {
|
341
|
-
it {
|
342
|
-
it {
|
343
|
-
it {
|
344
|
-
it {
|
341
|
+
it { is_expected.to have_db_column(:exploit_attempt_count).of_type(:integer).with_options(:default => 0) }
|
342
|
+
it { is_expected.to have_db_column(:host_detail_count).of_type(:integer).with_options(:default => 0) }
|
343
|
+
it { is_expected.to have_db_column(:note_count).of_type(:integer).with_options(:default => 0) }
|
344
|
+
it { is_expected.to have_db_column(:service_count).of_type(:integer).with_options(:default => 0) }
|
345
|
+
it { is_expected.to have_db_column(:vuln_count).of_type(:integer).with_options(:default => 0) }
|
345
346
|
end
|
346
347
|
|
347
348
|
context 'timestamps' do
|
348
|
-
it {
|
349
|
-
it {
|
349
|
+
it { is_expected.to have_db_column(:created_at).of_type(:datetime) }
|
350
|
+
it { is_expected.to have_db_column(:updated_at).of_type(:datetime) }
|
350
351
|
end
|
351
352
|
end
|
352
353
|
|
353
354
|
context 'indices' do
|
354
|
-
it {
|
355
|
-
it {
|
356
|
-
it {
|
357
|
-
it {
|
358
|
-
it {
|
359
|
-
it {
|
355
|
+
it { is_expected.to have_db_index([:workspace_id, :address]).unique(true) }
|
356
|
+
it { is_expected.to have_db_index(:name) }
|
357
|
+
it { is_expected.to have_db_index(:os_flavor) }
|
358
|
+
it { is_expected.to have_db_index(:os_name) }
|
359
|
+
it { is_expected.to have_db_index(:purpose) }
|
360
|
+
it { is_expected.to have_db_index(:state) }
|
360
361
|
end
|
361
362
|
end
|
362
363
|
|
@@ -366,7 +367,7 @@ describe Mdm::Host do
|
|
366
367
|
FactoryGirl.build(:full_mdm_host)
|
367
368
|
end
|
368
369
|
|
369
|
-
it {
|
370
|
+
it { is_expected.to be_valid }
|
370
371
|
end
|
371
372
|
|
372
373
|
context 'mdm_host' do
|
@@ -374,14 +375,14 @@ describe Mdm::Host do
|
|
374
375
|
FactoryGirl.build(:mdm_host)
|
375
376
|
end
|
376
377
|
|
377
|
-
it {
|
378
|
+
it { is_expected.to be_valid }
|
378
379
|
end
|
379
380
|
end
|
380
381
|
|
381
382
|
context 'validations' do
|
382
383
|
context 'address' do
|
383
|
-
it {
|
384
|
-
it {
|
384
|
+
it { is_expected.to validate_exclusion_of(:address).in_array(['127.0.0.1']) }
|
385
|
+
it { is_expected.to validate_presence_of(:address) }
|
385
386
|
|
386
387
|
# can't use validate_uniqueness_of(:address).scoped_to(:workspace_id) because it will attempt to set workspace_id
|
387
388
|
# to `nil`, which will make the `:null => false` constraint on hosts.workspace_id to fail.
|
@@ -393,8 +394,8 @@ describe Mdm::Host do
|
|
393
394
|
|
394
395
|
duplicate_host = FactoryGirl.build(:mdm_host, :address => address, :workspace => workspace)
|
395
396
|
|
396
|
-
duplicate_host.
|
397
|
-
duplicate_host.errors[:address].
|
397
|
+
expect(duplicate_host).not_to be_valid
|
398
|
+
expect(duplicate_host.errors[:address]).to include('has already been taken')
|
398
399
|
end
|
399
400
|
end
|
400
401
|
|
@@ -405,19 +406,20 @@ describe Mdm::Host do
|
|
405
406
|
context 'with an unknown architecture' do
|
406
407
|
let(:arch) { "asdfasdf" }
|
407
408
|
it 'should normalize to Unknown' do
|
408
|
-
host.
|
409
|
-
host.arch.
|
409
|
+
expect(host).to be_valid
|
410
|
+
expect(host.arch).to be described_class::UNKNOWN_ARCHITECTURE
|
410
411
|
end
|
411
412
|
end
|
412
413
|
described_class::ARCHITECTURES.each do |arch|
|
413
414
|
context "with known architecture '#{arch}'" do
|
414
415
|
let(:arch) { arch }
|
415
|
-
it {
|
416
|
+
it { is_expected.to be_valid }
|
416
417
|
end
|
417
418
|
end
|
418
419
|
end
|
419
|
-
|
420
|
-
it {
|
420
|
+
|
421
|
+
it { is_expected.to validate_inclusion_of(:state).in_array(states).allow_nil }
|
422
|
+
it { is_expected.to validate_presence_of(:workspace) }
|
421
423
|
end
|
422
424
|
|
423
425
|
context 'search scope' do
|
@@ -431,13 +433,13 @@ describe Mdm::Host do
|
|
431
433
|
|
432
434
|
context 'searching for an empty string' do
|
433
435
|
it 'should return any hosts in the database' do
|
434
|
-
search_for('').
|
436
|
+
expect(search_for('')).to include(subject)
|
435
437
|
end
|
436
438
|
end
|
437
439
|
|
438
440
|
context 'searching for an existing Host\'s name' do
|
439
441
|
it 'should return the host' do
|
440
|
-
search_for(subject.name).
|
442
|
+
expect(search_for(subject.name)).to include(subject)
|
441
443
|
end
|
442
444
|
end
|
443
445
|
end
|
@@ -446,139 +448,139 @@ describe Mdm::Host do
|
|
446
448
|
context '#get_arch_from_string' do
|
447
449
|
context "should return 'x64'" do
|
448
450
|
it "when the string contains 'x64'" do
|
449
|
-
host.send(:get_arch_from_string, 'blahx64blah').
|
451
|
+
expect(host.send(:get_arch_from_string, 'blahx64blah')).to eq('x64')
|
450
452
|
end
|
451
453
|
|
452
454
|
it "when the string contains 'X64'" do
|
453
|
-
host.send(:get_arch_from_string, 'blahX64blah').
|
455
|
+
expect(host.send(:get_arch_from_string, 'blahX64blah')).to eq('x64')
|
454
456
|
end
|
455
457
|
|
456
458
|
it "when the string contains 'x86_64'" do
|
457
|
-
host.send(:get_arch_from_string, 'blahx86_64blah').
|
459
|
+
expect(host.send(:get_arch_from_string, 'blahx86_64blah')).to eq('x64')
|
458
460
|
end
|
459
461
|
|
460
462
|
it "when the string contains 'X86_64'" do
|
461
|
-
host.send(:get_arch_from_string, 'blahX86_64blah').
|
463
|
+
expect(host.send(:get_arch_from_string, 'blahX86_64blah')).to eq('x64')
|
462
464
|
end
|
463
465
|
|
464
466
|
it "when the string contains 'amd64'" do
|
465
|
-
host.send(:get_arch_from_string, 'blahamd64blah').
|
467
|
+
expect(host.send(:get_arch_from_string, 'blahamd64blah')).to eq('x64')
|
466
468
|
end
|
467
469
|
|
468
470
|
it "when the string contains 'AMD64'" do
|
469
|
-
host.send(:get_arch_from_string, 'blahAMD64blah').
|
471
|
+
expect(host.send(:get_arch_from_string, 'blahAMD64blah')).to eq('x64')
|
470
472
|
end
|
471
473
|
|
472
474
|
it "when the string contains 'aMd64'" do
|
473
|
-
host.send(:get_arch_from_string, 'blahamd64blah').
|
475
|
+
expect(host.send(:get_arch_from_string, 'blahamd64blah')).to eq('x64')
|
474
476
|
end
|
475
477
|
end
|
476
478
|
|
477
479
|
context "should return 'x86'" do
|
478
480
|
it "when the string contains 'x86'" do
|
479
|
-
host.send(:get_arch_from_string, 'blahx86blah').
|
481
|
+
expect(host.send(:get_arch_from_string, 'blahx86blah')).to eq('x86')
|
480
482
|
end
|
481
483
|
|
482
484
|
it "when the string contains 'X86'" do
|
483
|
-
host.send(:get_arch_from_string, 'blahX86blah').
|
485
|
+
expect(host.send(:get_arch_from_string, 'blahX86blah')).to eq('x86')
|
484
486
|
end
|
485
487
|
|
486
488
|
it "when the string contains 'i386'" do
|
487
|
-
host.send(:get_arch_from_string, 'blahi386blah').
|
489
|
+
expect(host.send(:get_arch_from_string, 'blahi386blah')).to eq('x86')
|
488
490
|
end
|
489
491
|
|
490
492
|
it "when the string contains 'I386'" do
|
491
|
-
host.send(:get_arch_from_string, 'blahI386blah').
|
493
|
+
expect(host.send(:get_arch_from_string, 'blahI386blah')).to eq('x86')
|
492
494
|
end
|
493
495
|
|
494
496
|
it "when the string contains 'i486'" do
|
495
|
-
host.send(:get_arch_from_string, 'blahi486blah').
|
497
|
+
expect(host.send(:get_arch_from_string, 'blahi486blah')).to eq('x86')
|
496
498
|
end
|
497
499
|
|
498
500
|
it "when the string contains 'i586'" do
|
499
|
-
host.send(:get_arch_from_string, 'blahi586blah').
|
501
|
+
expect(host.send(:get_arch_from_string, 'blahi586blah')).to eq('x86')
|
500
502
|
end
|
501
503
|
|
502
504
|
it "when the string contains 'i686'" do
|
503
|
-
host.send(:get_arch_from_string, 'blahi386blah').
|
505
|
+
expect(host.send(:get_arch_from_string, 'blahi386blah')).to eq('x86')
|
504
506
|
end
|
505
507
|
end
|
506
508
|
|
507
509
|
context "should return 'ppc'" do
|
508
510
|
it "when the string contains 'PowerPC'" do
|
509
|
-
host.send(:get_arch_from_string, 'blahPowerPCblah').
|
511
|
+
expect(host.send(:get_arch_from_string, 'blahPowerPCblah')).to eq('ppc')
|
510
512
|
end
|
511
513
|
|
512
514
|
it "when the string contains 'PPC'" do
|
513
|
-
host.send(:get_arch_from_string, 'blahPPCblah').
|
515
|
+
expect(host.send(:get_arch_from_string, 'blahPPCblah')).to eq('ppc')
|
514
516
|
end
|
515
517
|
|
516
518
|
it "when the string contains 'POWER'" do
|
517
|
-
host.send(:get_arch_from_string, 'blahPOWERblah').
|
519
|
+
expect(host.send(:get_arch_from_string, 'blahPOWERblah')).to eq('ppc')
|
518
520
|
end
|
519
521
|
|
520
522
|
it "when the string contains 'ppc'" do
|
521
|
-
host.send(:get_arch_from_string, 'blahppcblah').
|
523
|
+
expect(host.send(:get_arch_from_string, 'blahppcblah')).to eq('ppc')
|
522
524
|
end
|
523
525
|
end
|
524
526
|
|
525
527
|
context 'should return nil' do
|
526
528
|
it 'when PowerPC is cased incorrectly' do
|
527
|
-
host.send(:get_arch_from_string, 'powerPC').
|
528
|
-
host.send(:get_arch_from_string, 'Powerpc').
|
529
|
+
expect(host.send(:get_arch_from_string, 'powerPC')).to eq(nil)
|
530
|
+
expect(host.send(:get_arch_from_string, 'Powerpc')).to eq(nil)
|
529
531
|
end
|
530
532
|
|
531
533
|
it 'when no recognized arch string is present' do
|
532
|
-
host.send(:get_arch_from_string, 'blahblah').
|
534
|
+
expect(host.send(:get_arch_from_string, 'blahblah')).to eq(nil)
|
533
535
|
end
|
534
536
|
end
|
535
537
|
|
536
538
|
it "should return 'sparc' if the string contains SPARC, regardless of case" do
|
537
|
-
host.send(:get_arch_from_string, 'blahSPARCblah').
|
538
|
-
host.send(:get_arch_from_string, 'blahSPaRCblah').
|
539
|
-
host.send(:get_arch_from_string, 'blahsparcblah').
|
539
|
+
expect(host.send(:get_arch_from_string, 'blahSPARCblah')).to eq('sparc')
|
540
|
+
expect(host.send(:get_arch_from_string, 'blahSPaRCblah')).to eq('sparc')
|
541
|
+
expect(host.send(:get_arch_from_string, 'blahsparcblah')).to eq('sparc')
|
540
542
|
end
|
541
543
|
|
542
544
|
it "should return 'arm' if the string contains 'ARM', regardless of case" do
|
543
|
-
host.send(:get_arch_from_string, 'blahARMblah').
|
544
|
-
host.send(:get_arch_from_string, 'blahArMblah').
|
545
|
-
host.send(:get_arch_from_string, 'blaharmblah').
|
545
|
+
expect(host.send(:get_arch_from_string, 'blahARMblah')).to eq('arm')
|
546
|
+
expect(host.send(:get_arch_from_string, 'blahArMblah')).to eq('arm')
|
547
|
+
expect(host.send(:get_arch_from_string, 'blaharmblah')).to eq('arm')
|
546
548
|
end
|
547
549
|
|
548
550
|
it "should return 'mips' if the string contains 'MIPS', regardless of case" do
|
549
|
-
host.send(:get_arch_from_string, 'blahMIPSblah').
|
550
|
-
host.send(:get_arch_from_string, 'blahMiPslah').
|
551
|
-
host.send(:get_arch_from_string, 'blahmipsblah').
|
551
|
+
expect(host.send(:get_arch_from_string, 'blahMIPSblah')).to eq('mips')
|
552
|
+
expect(host.send(:get_arch_from_string, 'blahMiPslah')).to eq('mips')
|
553
|
+
expect(host.send(:get_arch_from_string, 'blahmipsblah')).to eq('mips')
|
552
554
|
end
|
553
555
|
end
|
554
556
|
|
555
557
|
context '#parse_windows_os_str' do
|
556
558
|
it 'should always return the os_name as Windows' do
|
557
559
|
result = host.send(:parse_windows_os_str, '')
|
558
|
-
result['os.product'].
|
560
|
+
expect(result['os.product']).to eq('Windows')
|
559
561
|
end
|
560
562
|
|
561
563
|
context 'arch' do
|
562
564
|
it 'should return a value for arch if there is one' do
|
563
565
|
result = host.send(:parse_windows_os_str, 'Windows x64')
|
564
|
-
result['os.arch'].
|
566
|
+
expect(result['os.arch']).to eq('x64')
|
565
567
|
end
|
566
568
|
|
567
569
|
it "should not have an arch key if we don't know the arch" do
|
568
570
|
result = host.send(:parse_windows_os_str, 'Windows')
|
569
|
-
result.has_key?('os.arch').
|
571
|
+
expect(result.has_key?('os.arch')).to eq(false)
|
570
572
|
end
|
571
573
|
end
|
572
574
|
|
573
575
|
context 'Service Pack' do
|
574
576
|
it 'should be returned if we see Service Pack X' do
|
575
577
|
result = host.send(:parse_windows_os_str, 'Windows XP Service Pack 1')
|
576
|
-
result['os.version'].
|
578
|
+
expect(result['os.version']).to eq('SP1')
|
577
579
|
end
|
578
580
|
|
579
581
|
it 'should be returned if we see SPX' do
|
580
582
|
result = host.send(:parse_windows_os_str, 'Windows XP SP3')
|
581
|
-
result['os.version'].
|
583
|
+
expect(result['os.version']).to eq('SP3')
|
582
584
|
end
|
583
585
|
end
|
584
586
|
|
@@ -586,141 +588,137 @@ describe Mdm::Host do
|
|
586
588
|
|
587
589
|
it "should appear as Windows 95 for 'Windows 95" do
|
588
590
|
result = host.send(:parse_windows_os_str, 'Windows 95')
|
589
|
-
result['os.product'].
|
591
|
+
expect(result['os.product']).to eq('Windows 95')
|
590
592
|
end
|
591
593
|
|
592
594
|
it "should appear as Windows NT 3.51 for 'Windows NT 3.51" do
|
593
595
|
result = host.send(:parse_windows_os_str, 'Windows NT 3.51')
|
594
|
-
result['os.product'].
|
596
|
+
expect(result['os.product']).to eq('Windows NT 3.51')
|
595
597
|
end
|
596
598
|
|
597
599
|
it "should appear as Windows NT 4.0 for 'Windows NT 4.0" do
|
598
600
|
result = host.send(:parse_windows_os_str, 'Windows NT 4.0')
|
599
|
-
result['os.product'].
|
601
|
+
expect(result['os.product']).to eq('Windows NT 4.0')
|
600
602
|
end
|
601
603
|
|
602
604
|
it "should appear as Windows 98 for 'Windows 98" do
|
603
605
|
result = host.send(:parse_windows_os_str, 'Windows 98')
|
604
|
-
result['os.product'].
|
606
|
+
expect(result['os.product']).to eq('Windows 98')
|
605
607
|
end
|
606
608
|
|
607
609
|
it "should appear as Windows ME for 'Windows ME" do
|
608
610
|
result = host.send(:parse_windows_os_str, 'Windows ME')
|
609
|
-
result['os.product'].
|
611
|
+
expect(result['os.product']).to eq('Windows ME')
|
610
612
|
end
|
611
613
|
|
612
614
|
it "should appear as Windows 2003 for '.NET Server'" do
|
613
615
|
result = host.send(:parse_windows_os_str, 'Windows .NET Server')
|
614
|
-
result['os.product'].
|
616
|
+
expect(result['os.product']).to eq('Windows Server 2003')
|
615
617
|
end
|
616
618
|
|
617
619
|
it 'should be recognized for Windows XP' do
|
618
620
|
result = host.send(:parse_windows_os_str, 'Windows XP')
|
619
|
-
result['os.product'].
|
621
|
+
expect(result['os.product']).to eq('Windows XP')
|
620
622
|
end
|
621
623
|
|
622
624
|
it 'should be recognized for Windows Server 2000' do
|
623
625
|
result = host.send(:parse_windows_os_str, 'Windows 2000')
|
624
|
-
result['os.product'].
|
626
|
+
expect(result['os.product']).to eq('Windows Server 2000')
|
625
627
|
end
|
626
628
|
|
627
629
|
it 'should be recognized for Windows Server 2003' do
|
628
630
|
result = host.send(:parse_windows_os_str, 'Windows 2003')
|
629
|
-
result['os.product'].
|
631
|
+
expect(result['os.product']).to eq('Windows Server 2003')
|
630
632
|
end
|
631
633
|
|
632
634
|
it 'should be recognized for Windows 2008' do
|
633
635
|
result = host.send(:parse_windows_os_str, 'Windows 2008')
|
634
|
-
result['os.product'].
|
636
|
+
expect(result['os.product']).to eq('Windows Server 2008')
|
635
637
|
end
|
636
638
|
|
637
639
|
it 'should be recognized for Windows 2012' do
|
638
640
|
result = host.send(:parse_windows_os_str, 'Windows 2012')
|
639
|
-
result['os.product'].
|
641
|
+
expect(result['os.product']).to eq('Windows Server 2012')
|
640
642
|
end
|
641
643
|
|
642
644
|
it 'should be recognized for Windows Vista' do
|
643
645
|
result = host.send(:parse_windows_os_str, 'Windows Vista')
|
644
|
-
result['os.product'].
|
646
|
+
expect(result['os.product']).to eq('Windows Vista')
|
645
647
|
end
|
646
648
|
|
647
649
|
it 'should be recognized for Windows Server 2000' do
|
648
650
|
result = host.send(:parse_windows_os_str, 'Windows 2000 Advanced Server')
|
649
|
-
result['os.product'].
|
651
|
+
expect(result['os.product']).to eq('Windows Server 2000')
|
650
652
|
end
|
651
653
|
|
652
654
|
it 'should be recognized for Windows 7' do
|
653
655
|
result = host.send(:parse_windows_os_str, 'Windows 7')
|
654
|
-
result['os.product'].
|
656
|
+
expect(result['os.product']).to eq('Windows 7')
|
655
657
|
end
|
656
658
|
|
657
659
|
it 'should be recognized for Windows 7 Ultimate Edition' do
|
658
660
|
result = host.send(:parse_windows_os_str, 'Windows 7 Ultimate Edition')
|
659
|
-
result['os.product'].
|
660
|
-
result['os.edition'].
|
661
|
+
expect(result['os.product']).to eq('Windows 7')
|
662
|
+
expect(result['os.edition']).to eq('Ultimate')
|
661
663
|
end
|
662
664
|
|
663
665
|
it 'should be recognized for Windows 8' do
|
664
666
|
result = host.send(:parse_windows_os_str, 'Windows 8')
|
665
|
-
result['os.product'].
|
667
|
+
expect(result['os.product']).to eq('Windows 8')
|
666
668
|
end
|
667
669
|
|
668
670
|
it 'should be recognized for Windows 8.1' do
|
669
671
|
result = host.send(:parse_windows_os_str, 'Windows 8.1')
|
670
|
-
result['os.product'].
|
672
|
+
expect(result['os.product']).to eq('Windows 8.1')
|
671
673
|
end
|
672
674
|
|
673
675
|
it 'should be recognized for Windows 8.2' do
|
674
676
|
result = host.send(:parse_windows_os_str, 'Windows 8.2')
|
675
|
-
result['os.product'].
|
677
|
+
expect(result['os.product']).to eq('Windows 8.2')
|
676
678
|
end
|
677
679
|
|
678
680
|
it 'should be recognized as Windows XP, Build 2600, SP3' do
|
679
681
|
result = host.send(:parse_windows_os_str, 'Windows XP (Build 2600, Service Pack 3).')
|
680
|
-
result['os.product'].
|
681
|
-
result['os.build'].
|
682
|
-
result['os.version'].
|
682
|
+
expect(result['os.product']).to eq('Windows XP')
|
683
|
+
expect(result['os.build']).to eq('2600')
|
684
|
+
expect(result['os.version']).to eq('SP3')
|
683
685
|
end
|
684
686
|
|
685
687
|
it 'should be recognized as Windows Server 2003, Build 3790' do
|
686
688
|
result = host.send(:parse_windows_os_str, 'Windows .NET Server (Build 3790).')
|
687
|
-
result['os.product'].
|
688
|
-
result['os.build'].
|
689
|
+
expect(result['os.product']).to eq('Windows Server 2003')
|
690
|
+
expect(result['os.build']).to eq('3790')
|
689
691
|
end
|
690
692
|
|
691
693
|
it 'should be recognized as Windows Server 2008, Build 6001, SP1' do
|
692
694
|
result = host.send(:parse_windows_os_str, 'Windows 2008 (Build 6001, Service Pack 1).')
|
693
|
-
result['os.product'].
|
694
|
-
result['os.build'].
|
695
|
-
result['os.version'].
|
695
|
+
expect(result['os.product']).to eq('Windows Server 2008')
|
696
|
+
expect(result['os.build']).to eq('6001')
|
697
|
+
expect(result['os.version']).to eq('SP1')
|
696
698
|
end
|
697
699
|
|
698
700
|
it 'should default to Windows <name> if all else fails' do
|
699
701
|
result = host.send(:parse_windows_os_str, 'Windows Foobar Service Pack 3')
|
700
|
-
result['os.product'].
|
701
|
-
result['os.version'].
|
702
|
+
expect(result['os.product']).to eq('Windows Foobar')
|
703
|
+
expect(result['os.version']).to eq('SP3')
|
702
704
|
end
|
703
705
|
end
|
704
706
|
end
|
705
707
|
|
706
708
|
context '#validate_fingerprint_data' do
|
707
|
-
before(:each) do
|
708
|
-
host.stub(:dlog)
|
709
|
-
end
|
710
|
-
|
711
709
|
it 'should return false for an empty hash' do
|
712
710
|
fingerprint= FactoryGirl.build(:mdm_note, :data => {})
|
713
|
-
host.validate_fingerprint_data(fingerprint).
|
711
|
+
expect(host.validate_fingerprint_data(fingerprint)).to eq(false)
|
714
712
|
end
|
715
713
|
|
716
714
|
it 'should return false for postgresql fingerprints' do
|
717
715
|
fingerprint= FactoryGirl.build(:mdm_note, :ntype => 'postgresql.fingerprint', :data => {})
|
718
|
-
host.validate_fingerprint_data(fingerprint).
|
716
|
+
expect(host.validate_fingerprint_data(fingerprint)).to eq(false)
|
719
717
|
end
|
720
718
|
|
721
719
|
it 'should return false if the fingerprint does not contain a hash' do
|
722
720
|
fingerprint= FactoryGirl.build(:mdm_note, :data => 'this is not a fingerprint')
|
723
|
-
host.validate_fingerprint_data(fingerprint).
|
721
|
+
expect(host.validate_fingerprint_data(fingerprint)).to eq(false)
|
724
722
|
end
|
725
723
|
end
|
726
724
|
|
@@ -728,91 +726,95 @@ describe Mdm::Host do
|
|
728
726
|
context '#apply_match_to_host' do
|
729
727
|
|
730
728
|
before(:each) do
|
731
|
-
stub_const(
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
729
|
+
stub_const(
|
730
|
+
'Rex::Text',
|
731
|
+
Module.new do
|
732
|
+
def self.ascii_safe_hex(unsanitized)
|
733
|
+
# Pass back the sanitized value for the stub
|
734
|
+
unsanitized.unpack("C*").pack("C*").gsub(/([\x00-\x08\x0b\x0c\x0e-\x1f\x80-\xFF])/n){ |x| "\\x%.2x" % x.unpack("C*")[0]}
|
735
|
+
end
|
736
|
+
end
|
737
|
+
)
|
736
738
|
end
|
737
739
|
|
738
740
|
it 'should set host.mac when host.mac is present' do
|
739
741
|
match = { 'host.mac' => '00:11:22:33:44:55' }
|
740
742
|
host.send(:apply_match_to_host, match)
|
741
|
-
host.mac.
|
743
|
+
expect(host.mac).to eq('00:11:22:33:44:55')
|
742
744
|
end
|
743
745
|
|
744
746
|
it 'should set host.name when host.name is present' do
|
745
747
|
match = { 'host.name' => 'webbyweb' }
|
746
748
|
host.send(:apply_match_to_host, match)
|
747
|
-
host.name.
|
749
|
+
expect(host.name).to eq('webbyweb')
|
748
750
|
end
|
749
751
|
|
750
752
|
it 'should set host.arch when os.arch is present' do
|
751
753
|
match = { 'os.arch' => 'x86' }
|
752
754
|
host.send(:apply_match_to_host, match)
|
753
|
-
host.arch.
|
755
|
+
expect(host.arch).to eq('x86')
|
754
756
|
end
|
755
757
|
|
756
758
|
it 'should set host.name to an escaped hex value when host.name contains high bytes' do
|
757
759
|
match = { 'host.name' => "HighBytes\xff\xf0".force_encoding('binary') }
|
758
760
|
host.send(:apply_match_to_host, match)
|
759
|
-
host.name.
|
761
|
+
expect(host.name).to eq("HighBytes\\xff\\xf0")
|
760
762
|
end
|
761
763
|
|
762
764
|
it 'should set host.purpose to client when os.product is Windows XP' do
|
763
765
|
match = { 'os.product' => 'Windows XP' }
|
764
766
|
host.send(:apply_match_to_host, match)
|
765
|
-
host.os_name.
|
766
|
-
host.purpose.
|
767
|
+
expect(host.os_name).to eq('Windows XP')
|
768
|
+
expect(host.purpose).to eq('client')
|
767
769
|
end
|
768
770
|
|
769
771
|
it 'should set host.purpose to server when os.product is Windows 2012' do
|
770
772
|
match = { 'os.product' => 'Windows 2012' }
|
771
773
|
host.send(:apply_match_to_host, match)
|
772
|
-
host.os_name.
|
773
|
-
host.purpose.
|
774
|
+
expect(host.os_name).to eq('Windows 2012')
|
775
|
+
expect(host.purpose).to eq('server')
|
774
776
|
end
|
775
777
|
|
776
778
|
it 'should set host.purpose to printer when os.device is Print server' do
|
777
779
|
match = { 'os.device' => 'Print server' }
|
778
780
|
host.send(:apply_match_to_host, match)
|
779
|
-
host.purpose.
|
781
|
+
expect(host.purpose).to eq('printer')
|
780
782
|
end
|
781
783
|
|
782
784
|
it 'should set host.os_lang to English when os.language is English' do
|
783
785
|
match = { 'os.language' => 'English' }
|
784
786
|
host.send(:apply_match_to_host, match)
|
785
|
-
host.os_lang.
|
787
|
+
expect(host.os_lang).to eq('English')
|
786
788
|
end
|
787
789
|
|
788
790
|
it 'should set host.os_name to Windows 8.1 when os.product is Windows 8.1' do
|
789
791
|
match = { 'os.product' => 'Windows 8.1' }
|
790
792
|
host.send(:apply_match_to_host, match)
|
791
|
-
host.os_name.
|
793
|
+
expect(host.os_name).to eq('Windows 8.1')
|
792
794
|
end
|
793
795
|
|
794
796
|
it 'should set host.os_name to Windows when os.product is not set and os.family is Windows' do
|
795
797
|
match = { 'os.family' => 'Windows' }
|
796
798
|
host.send(:apply_match_to_host, match)
|
797
|
-
host.os_name.
|
799
|
+
expect(host.os_name).to eq('Windows')
|
798
800
|
end
|
799
801
|
|
800
802
|
it 'should set host.os_flavor to Professional when os.edition is Professional' do
|
801
803
|
match = { 'os.edition' => 'Professional' }
|
802
804
|
host.send(:apply_match_to_host, match)
|
803
|
-
host.os_flavor.
|
805
|
+
expect(host.os_flavor).to eq('Professional')
|
804
806
|
end
|
805
807
|
|
806
808
|
it 'should set host.os_sp to SP2 when os.version is SP2' do
|
807
809
|
match = { 'os.version' => 'SP2' }
|
808
810
|
host.send(:apply_match_to_host, match)
|
809
|
-
host.os_sp.
|
811
|
+
expect(host.os_sp).to eq('SP2')
|
810
812
|
end
|
811
813
|
|
812
814
|
it 'should set host.os_sp to 3.2.11 when os.version is nil and linux.kernel.version is 3.2.11' do
|
813
815
|
match = { 'linux.kernel.version' => '3.2.11' }
|
814
816
|
host.send(:apply_match_to_host, match)
|
815
|
-
host.os_sp.
|
817
|
+
expect(host.os_sp).to eq('3.2.11')
|
816
818
|
end
|
817
819
|
end
|
818
820
|
|
@@ -821,33 +823,33 @@ describe Mdm::Host do
|
|
821
823
|
it 'should convert Service Pack X to SPX' do
|
822
824
|
match = { 'os.version' => 'Service Pack 2' }
|
823
825
|
result = host.send(:normalize_match, match)
|
824
|
-
result['os.version'].
|
826
|
+
expect(result['os.version']).to eq('SP2')
|
825
827
|
end
|
826
828
|
|
827
829
|
it 'should not convert No Service Pack to SP' do
|
828
830
|
match = { 'os.version' => 'No Service Pack' }
|
829
831
|
result = host.send(:normalize_match, match)
|
830
|
-
result['os.version'].
|
832
|
+
expect(result['os.version']).to eq('No Service Pack')
|
831
833
|
end
|
832
834
|
|
833
835
|
it 'should convert Apple Mac OS X to Mac OS X' do
|
834
836
|
match = { 'os.product' => 'Apple Mac OS X' }
|
835
837
|
result = host.send(:normalize_match, match)
|
836
|
-
result['os.product'].
|
837
|
-
result['os.vendor'].
|
838
|
+
expect(result['os.product']).to eq('Mac OS X')
|
839
|
+
expect(result['os.vendor']).to eq('Apple')
|
838
840
|
end
|
839
841
|
|
840
842
|
it 'should convert Microsoft Windows to Windows' do
|
841
843
|
match = { 'os.product' => 'Microsoft Windows 7' }
|
842
844
|
result = host.send(:normalize_match, match)
|
843
|
-
result['os.product'].
|
844
|
-
result['os.vendor'].
|
845
|
+
expect(result['os.product']).to eq('Windows 7')
|
846
|
+
expect(result['os.vendor']).to eq('Microsoft')
|
845
847
|
end
|
846
848
|
|
847
849
|
it 'should convert Windows Server 2012 to Windows 2012' do
|
848
850
|
match = { 'os.product' => 'Windows Server 2012' }
|
849
851
|
result = host.send(:normalize_match, match)
|
850
|
-
result['os.product'].
|
852
|
+
expect(result['os.product']).to eq('Windows 2012')
|
851
853
|
end
|
852
854
|
end
|
853
855
|
|
@@ -856,55 +858,55 @@ describe Mdm::Host do
|
|
856
858
|
it 'should detect Windows XP as a client' do
|
857
859
|
match = { 'os.product' => 'Windows XP' }
|
858
860
|
result = host.send(:guess_purpose_from_match, match)
|
859
|
-
result.
|
861
|
+
expect(result).to eq('client')
|
860
862
|
end
|
861
863
|
|
862
864
|
it 'should detect Windows 8.1 as a client' do
|
863
865
|
match = { 'os.product' => 'Windows 8.1' }
|
864
866
|
result = host.send(:guess_purpose_from_match, match)
|
865
|
-
result.
|
867
|
+
expect(result).to eq('client')
|
866
868
|
end
|
867
869
|
|
868
870
|
it 'should detect Windows 2000 as a server' do
|
869
871
|
match = { 'os.product' => 'Windows 2000' }
|
870
872
|
result = host.send(:guess_purpose_from_match, match)
|
871
|
-
result.
|
873
|
+
expect(result).to eq('server')
|
872
874
|
end
|
873
875
|
|
874
876
|
it 'should detect Windows Server 2012 as a server' do
|
875
877
|
match = { 'os.product' => 'Windows Server 2012' }
|
876
878
|
result = host.send(:guess_purpose_from_match, match)
|
877
|
-
result.
|
879
|
+
expect(result).to eq('server')
|
878
880
|
end
|
879
881
|
|
880
882
|
it 'should detect Linux as a server' do
|
881
883
|
match = { 'os.product' => 'Linux' }
|
882
884
|
result = host.send(:guess_purpose_from_match, match)
|
883
|
-
result.
|
885
|
+
expect(result).to eq('server')
|
884
886
|
end
|
885
887
|
|
886
888
|
it 'should detect JetDirect as a printer' do
|
887
889
|
match = { 'os.product' => 'JetDirect', 'os.device' => 'Print server' }
|
888
890
|
result = host.send(:guess_purpose_from_match, match)
|
889
|
-
result.
|
891
|
+
expect(result).to eq('printer')
|
890
892
|
end
|
891
893
|
|
892
894
|
it 'should detect Unknown Printer as a printer' do
|
893
895
|
match = { 'os.product' => 'Unknown Printer' }
|
894
896
|
result = host.send(:guess_purpose_from_match, match)
|
895
|
-
result.
|
897
|
+
expect(result).to eq('printer')
|
896
898
|
end
|
897
899
|
|
898
900
|
it 'should detect Linksys Router as a router' do
|
899
901
|
match = { 'os.product' => 'Linksys', 'os.device' => 'Router' }
|
900
902
|
result = host.send(:guess_purpose_from_match, match)
|
901
|
-
result.
|
903
|
+
expect(result).to eq('router')
|
902
904
|
end
|
903
905
|
|
904
906
|
it 'should detect CheckPoint Firewall-1 as a firewall' do
|
905
907
|
match = { 'os.vendor' => 'Check Point', 'os.product' => 'Firewall-1' }
|
906
908
|
result = host.send(:guess_purpose_from_match, match)
|
907
|
-
result.
|
909
|
+
expect(result).to eq('firewall')
|
908
910
|
end
|
909
911
|
end
|
910
912
|
|
@@ -913,22 +915,22 @@ describe Mdm::Host do
|
|
913
915
|
it 'should return all the correct data for Windows XP SP3 x86' do
|
914
916
|
fingerprint = FactoryGirl.build(:mdm_session_fingerprint, :host => host)
|
915
917
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
916
|
-
result['os.product'].
|
917
|
-
result['os.version'].
|
918
|
-
result['os.arch'].
|
919
|
-
result['host.name'].
|
920
|
-
result['os.certainty'].to_f.
|
918
|
+
expect(result['os.product']).to eq('Windows XP')
|
919
|
+
expect(result['os.version']).to eq('SP3')
|
920
|
+
expect(result['os.arch']).to eq('x86')
|
921
|
+
expect(result['host.name']).to eq(nil)
|
922
|
+
expect(result['os.certainty'].to_f).to eq(0.8)
|
921
923
|
end
|
922
924
|
|
923
925
|
it 'should return all the correct data for Windows 2008 SP1 x64' do
|
924
926
|
fp_data = { :os => 'Microsoft Windows 2008 SP1', :arch => 'x64'}
|
925
927
|
fingerprint = FactoryGirl.build(:mdm_session_fingerprint, :host => host, :data => fp_data)
|
926
928
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
927
|
-
result['os.product'].
|
928
|
-
result['os.version'].
|
929
|
-
result['os.arch'].
|
930
|
-
result['host.name'].
|
931
|
-
result['os.certainty'].to_f.
|
929
|
+
expect(result['os.product']).to eq('Windows Server 2008')
|
930
|
+
expect(result['os.version']).to eq('SP1')
|
931
|
+
expect(result['os.arch']).to eq('x64')
|
932
|
+
expect(result['host.name']).to eq(nil)
|
933
|
+
expect(result['os.certainty'].to_f).to eq(0.8)
|
932
934
|
end
|
933
935
|
|
934
936
|
it 'should fingerprint Metasploitable correctly' do
|
@@ -936,21 +938,21 @@ describe Mdm::Host do
|
|
936
938
|
fp_data = { :os => 'Linux 2.6.24-16-server (i386)', :name => 'metasploitable'}
|
937
939
|
fingerprint = FactoryGirl.build(:mdm_session_fingerprint, :host => host, :data => fp_data)
|
938
940
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
939
|
-
result['os.product'].
|
940
|
-
result['host.name'].
|
941
|
-
result['os.version'].
|
942
|
-
result['os.arch'].
|
943
|
-
result['os.certainty'].to_f.
|
941
|
+
expect(result['os.product']).to eq('Linux')
|
942
|
+
expect(result['host.name']).to eq('metasploitable')
|
943
|
+
expect(result['os.version']).to eq('2.6.24-16-server')
|
944
|
+
expect(result['os.arch']).to eq('x86')
|
945
|
+
expect(result['os.certainty'].to_f).to eq(0.8)
|
944
946
|
end
|
945
947
|
|
946
948
|
it 'should just populate os_name if it is unsure' do
|
947
949
|
fp_data = { :os => 'Darwin 12.3.0 x86_64 i386'}
|
948
950
|
fingerprint = FactoryGirl.build(:mdm_session_fingerprint, :host => host, :data => fp_data)
|
949
951
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
950
|
-
result['os.product'].
|
951
|
-
result['os.version'].
|
952
|
-
result['os.arch'].
|
953
|
-
result['os.certainty'].
|
952
|
+
expect(result['os.product']).to eq('Darwin 12.3.0 x86_64 i386')
|
953
|
+
expect(result['os.version']).to eq(nil)
|
954
|
+
expect(result['os.arch']).to eq(nil)
|
955
|
+
expect(result['os.certainty']).to eq(0.8)
|
954
956
|
end
|
955
957
|
end
|
956
958
|
|
@@ -958,27 +960,27 @@ describe Mdm::Host do
|
|
958
960
|
it 'should return OS name for a Windows XP fingerprint' do
|
959
961
|
fingerprint = FactoryGirl.build(:mdm_nmap_fingerprint, :host => host)
|
960
962
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
961
|
-
result['os.product'].
|
962
|
-
result['os.certainty'].to_f.
|
963
|
+
expect(result['os.product']).to eq('Windows XP')
|
964
|
+
expect(result['os.certainty'].to_f).to eq(described_class::MAX_NMAP_CERTAINTY)
|
963
965
|
end
|
964
966
|
|
965
967
|
it 'should return OS name for a Metasploitable fingerprint' do
|
966
968
|
fp_data = {:os_vendor=>"Linux", :os_family=>"Linux", :os_version=>"2.6.X", :os_accuracy=>100}
|
967
969
|
fingerprint = FactoryGirl.build(:mdm_nmap_fingerprint, :host => host, :data => fp_data)
|
968
970
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
969
|
-
result['os.product'].
|
970
|
-
result['os.version'].
|
971
|
-
result['os.certainty'].to_f.
|
971
|
+
expect(result['os.product']).to eq('Linux')
|
972
|
+
expect(result['os.version']).to eq('2.6.X')
|
973
|
+
expect(result['os.certainty'].to_f).to eq(described_class::MAX_NMAP_CERTAINTY)
|
972
974
|
end
|
973
975
|
|
974
976
|
it 'should return OS name and flavor fo an OSX fingerprint' do
|
975
977
|
fp_data = {:os_vendor=>"Apple", :os_family=>"Mac OS X", :os_version=>"10.8.X", :os_accuracy=>100}
|
976
978
|
fingerprint = FactoryGirl.build(:mdm_nmap_fingerprint, :host => host, :data => fp_data)
|
977
979
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
978
|
-
result['os.product'].
|
979
|
-
result['os.vendor'].
|
980
|
-
result['os.version'].
|
981
|
-
result['os.certainty'].to_f.
|
980
|
+
expect(result['os.product']).to eq('Mac OS X')
|
981
|
+
expect(result['os.vendor']).to eq('Apple')
|
982
|
+
expect(result['os.version']).to eq('10.8.X')
|
983
|
+
expect(result['os.certainty'].to_f).to eq(described_class::MAX_NMAP_CERTAINTY)
|
982
984
|
end
|
983
985
|
end
|
984
986
|
|
@@ -987,19 +989,19 @@ describe Mdm::Host do
|
|
987
989
|
it 'should return a generic Windows fingerprint with no product info' do
|
988
990
|
fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host)
|
989
991
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
990
|
-
result['os.product'].
|
991
|
-
result['os.arch'].
|
992
|
-
result['os.certainty'].to_f.
|
992
|
+
expect(result['os.product']).to eq('Windows')
|
993
|
+
expect(result['os.arch']).to eq('x86')
|
994
|
+
expect(result['os.certainty'].to_f).to eq(0.67)
|
993
995
|
end
|
994
996
|
|
995
997
|
it 'should recognize a Windows 7 fingerprint' do
|
996
998
|
fp_data = {:family=>"Windows", :certainty=>"0.67", :vendor=>"Microsoft", :arch=>"x86", :product => 'Windows 7', :version => 'SP1'}
|
997
999
|
fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host, :data => fp_data)
|
998
1000
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
999
|
-
result['os.product'].
|
1000
|
-
result['os.version'].
|
1001
|
-
result['os.arch'].
|
1002
|
-
result['os.certainty'].to_f.
|
1001
|
+
expect(result['os.product']).to eq('Windows 7')
|
1002
|
+
expect(result['os.version']).to eq('SP1')
|
1003
|
+
expect(result['os.arch']).to eq('x86')
|
1004
|
+
expect(result['os.certainty'].to_f).to eq(0.67)
|
1003
1005
|
end
|
1004
1006
|
end
|
1005
1007
|
|
@@ -1007,30 +1009,30 @@ describe Mdm::Host do
|
|
1007
1009
|
fp_data = {:family=>"Mac OS X", :certainty=>"0.80", :vendor=>"Apple"}
|
1008
1010
|
fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host, :data => fp_data)
|
1009
1011
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
1010
|
-
result['os.product'].
|
1011
|
-
result['os.vendor'].
|
1012
|
+
expect(result['os.product']).to eq('Mac OS X')
|
1013
|
+
expect(result['os.vendor']).to eq("Apple")
|
1012
1014
|
end
|
1013
1015
|
|
1014
1016
|
it 'should recognize a Cisco fingerprint' do
|
1015
1017
|
fp_data = {:family=>"IOS", :certainty=>"1.00", :vendor=>"Cisco", :version=>"11.2(8)SA2"}
|
1016
1018
|
fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host, :data => fp_data)
|
1017
1019
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
1018
|
-
result['os.product'].
|
1019
|
-
result['os.vendor'].
|
1020
|
+
expect(result['os.product']).to eq('IOS')
|
1021
|
+
expect(result['os.vendor']).to eq('Cisco')
|
1020
1022
|
end
|
1021
1023
|
|
1022
1024
|
it 'should recognize an embedded fingerprint' do
|
1023
1025
|
fp_data = {:family=>"embedded", :certainty=>"1.00", :vendor=>"Footek"}
|
1024
1026
|
fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host, :data => fp_data)
|
1025
1027
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
1026
|
-
result['os.product'].
|
1028
|
+
expect(result['os.product']).to eq('Footek')
|
1027
1029
|
end
|
1028
1030
|
|
1029
1031
|
it 'should handle an unknown fingerprint' do
|
1030
1032
|
fp_data = {:certainty=>"1.00", :vendor=>"Footek"}
|
1031
1033
|
fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host, :data => fp_data)
|
1032
1034
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
1033
|
-
result['os.product'].
|
1035
|
+
expect(result['os.product']).to eq('Footek')
|
1034
1036
|
end
|
1035
1037
|
|
1036
1038
|
|
@@ -1040,18 +1042,18 @@ describe Mdm::Host do
|
|
1040
1042
|
it 'should recognize a Windows fingerprint' do
|
1041
1043
|
fingerprint = FactoryGirl.build(:mdm_retina_fingerprint, :host => host)
|
1042
1044
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
1043
|
-
result['os.product'].
|
1044
|
-
result['os.arch'].
|
1045
|
-
result['os.version'].
|
1046
|
-
result['os.certainty'].to_f.
|
1045
|
+
expect(result['os.product']).to eq( 'Windows Server 2003')
|
1046
|
+
expect(result['os.arch']).to eq('x64')
|
1047
|
+
expect(result['os.version']).to eq('SP2')
|
1048
|
+
expect(result['os.certainty'].to_f).to eq(0.8)
|
1047
1049
|
end
|
1048
1050
|
|
1049
1051
|
it 'should otherwise jsut copy the fingerprint to os_name' do
|
1050
1052
|
fp_data = { :os => 'Linux 2.6.X (i386)'}
|
1051
1053
|
fingerprint = FactoryGirl.build(:mdm_retina_fingerprint, :host => host, :data => fp_data)
|
1052
1054
|
result = host.send(:normalize_scanner_fp, fingerprint).first
|
1053
|
-
result['os.product'].
|
1054
|
-
result['os.certainty'].to_f.
|
1055
|
+
expect(result['os.product']).to eq( 'Linux 2.6.X (i386)')
|
1056
|
+
expect(result['os.certainty'].to_f).to eq(0.8)
|
1055
1057
|
end
|
1056
1058
|
end
|
1057
1059
|
end
|