CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/msf/debug_spec.rb
Views: 11655
1
require 'spec_helper'
2
3
RSpec.describe Msf::Ui::Debug do
4
let(:file_fixtures_path) { File.join(Msf::Config.install_root, 'spec', 'file_fixtures') }
5
let(:features) do
6
[
7
{
8
name: 'filtered_options',
9
description: 'Add option filtering functionality to Metasploit',
10
enabled: false
11
},
12
{
13
name: 'new_search_capabilities',
14
description: 'Add new search capabilities to Metasploit',
15
enabled: true
16
}
17
]
18
end
19
20
it 'error parsing correctly parses framework.log and msf-ws.log' do
21
allow(::Msf::Config).to receive(:log_directory).and_return(Pathname.new(file_fixtures_path).join('debug', 'error_logs', 'basic'))
22
23
error_log_output = <<~LOG
24
## %grnFramework Errors%clr
25
26
The following framework errors occurred before the issue occurred:
27
<details>
28
<summary>Collapse</summary>
29
30
```
31
[00/00/0000 00:00:00] [e(0)] core: [-] Error 1
32
33
[11/11/1111 11:11:11] [e(0)] core: [-] Error 2
34
Call stack:
35
Stack_Trace
36
stack trace
37
STACK-TRACE
38
39
[22/22/2222 22:22:22] [e(0)] core: [-] Error 3
40
```
41
42
</details>
43
44
45
## %grnWeb Service Errors%clr
46
47
The following web service errors occurred before the issue occurred:
48
<details>
49
<summary>Collapse</summary>
50
51
```
52
[-] Error 1
53
54
[-] Error 2
55
[-] Error 3
56
```
57
58
</details>
59
60
61
LOG
62
63
expect(subject.errors).to eql(error_log_output)
64
end
65
66
it 'error parsing correctly parses log files larger than the log line total' do
67
allow(::Msf::Config).to receive(:log_directory).and_return(File.join(file_fixtures_path, 'debug', 'error_logs', 'long'))
68
69
logs = ''
70
digits = 11..20
71
72
digits.each do |d|
73
logs += "[00/00/0000 00:00:00] [e(0)] core: [-] Error #{d}\n\n"
74
end
75
76
error_log_output = <<~LOG
77
## %grnFramework Errors%clr
78
79
The following framework errors occurred before the issue occurred:
80
<details>
81
<summary>Collapse</summary>
82
83
```
84
[00/00/0000 00:00:00] [e(0)] core: [-] Error 11
85
86
[00/00/0000 00:00:00] [e(0)] core: [-] Error 12
87
88
[00/00/0000 00:00:00] [e(0)] core: [-] Error 13
89
90
[00/00/0000 00:00:00] [e(0)] core: [-] Error 14
91
92
[00/00/0000 00:00:00] [e(0)] core: [-] Error 15
93
94
[00/00/0000 00:00:00] [e(0)] core: [-] Error 16
95
96
[00/00/0000 00:00:00] [e(0)] core: [-] Error 17
97
98
[00/00/0000 00:00:00] [e(0)] core: [-] Error 18
99
100
[00/00/0000 00:00:00] [e(0)] core: [-] Error 19
101
102
[00/00/0000 00:00:00] [e(0)] core: [-] Error 20
103
```
104
105
</details>
106
107
108
## %grnWeb Service Errors%clr
109
110
The following web service errors occurred before the issue occurred:
111
<details>
112
<summary>Collapse</summary>
113
114
```
115
[-] Error 11
116
117
[-] Error 12
118
119
[-] Error 13
120
121
[-] Error 14
122
123
[-] Error 15
124
125
[-] Error 16
126
127
[-] Error 17
128
129
[-] Error 18
130
131
[-] Error 19
132
133
[-] Error 20
134
```
135
136
</details>
137
138
139
LOG
140
141
expect(subject.errors).to eql(error_log_output)
142
end
143
144
it 'error parsing correctly parses empty log files' do
145
allow(::Msf::Config).to receive(:log_directory).and_return(File.join(file_fixtures_path, 'debug', 'error_logs', 'empty'))
146
147
error_log_output = <<~EMPTY
148
## %grnFramework Errors%clr
149
150
The following framework errors occurred before the issue occurred:
151
<details>
152
<summary>Collapse</summary>
153
154
```
155
No matching patterns were found in framework.log.
156
```
157
158
</details>
159
160
161
## %grnWeb Service Errors%clr
162
163
The following web service errors occurred before the issue occurred:
164
<details>
165
<summary>Collapse</summary>
166
167
```
168
No matching patterns were found in msf-ws.log.
169
```
170
171
</details>
172
173
174
EMPTY
175
176
expect(subject.errors).to eql(error_log_output)
177
end
178
179
it 'error parsing correctly returns a missing log file message' do
180
allow(::Msf::Config).to receive(:log_directory).and_return('FAKE_PATH')
181
182
error_log_output = <<~EMPTY
183
## %grnFramework Errors%clr
184
185
The following framework errors occurred before the issue occurred:
186
<details>
187
<summary>Collapse</summary>
188
189
```
190
framework.log does not exist.
191
```
192
193
</details>
194
195
196
## %grnWeb Service Errors%clr
197
198
The following web service errors occurred before the issue occurred:
199
<details>
200
<summary>Collapse</summary>
201
202
```
203
msf-ws.log does not exist.
204
```
205
206
</details>
207
208
209
EMPTY
210
211
expect(subject.errors).to eql(error_log_output)
212
end
213
214
it 'correctly retrieves and parses a command history shorter than the command total' do
215
stub_const('Readline::HISTORY', Array.new(4) { |i| "Command #{i + 1}" })
216
217
driver = instance_double(
218
Msf::Ui::Console::Driver,
219
hist_last_saved: 0
220
)
221
222
stub_const('Msf::Ui::Debug::COMMAND_HISTORY_TOTAL', 10)
223
224
history_output = <<~E_LOG
225
## %grnHistory%clr
226
227
The following commands were ran during the session and before this issue occurred:
228
<details>
229
<summary>Collapse</summary>
230
231
```
232
0 Command 1
233
1 Command 2
234
2 Command 3
235
3 Command 4
236
```
237
238
</details>
239
240
241
E_LOG
242
243
expect(subject.history(driver)).to eql(history_output)
244
end
245
246
it 'correctly retrieves and parses a command history equal in length to the command total' do
247
driver = instance_double(
248
::Msf::Ui::Console::Driver,
249
hist_last_saved: 0
250
)
251
252
stub_const('Msf::Ui::Debug::COMMAND_HISTORY_TOTAL', 10)
253
254
stub_const('Readline::HISTORY', Array.new(10) { |i| "Command #{i + 1}" })
255
256
history_output = <<~E_LOG
257
## %grnHistory%clr
258
259
The following commands were ran during the session and before this issue occurred:
260
<details>
261
<summary>Collapse</summary>
262
263
```
264
0 Command 1
265
1 Command 2
266
2 Command 3
267
3 Command 4
268
4 Command 5
269
5 Command 6
270
6 Command 7
271
7 Command 8
272
8 Command 9
273
9 Command 10
274
```
275
276
</details>
277
278
279
E_LOG
280
281
expect(subject.history(driver)).to eql(history_output)
282
end
283
284
it 'correctly retrieves and parses a command history larger than the command total' do
285
driver = instance_double(
286
::Msf::Ui::Console::Driver,
287
hist_last_saved: 0
288
)
289
290
stub_const('Msf::Ui::Debug::COMMAND_HISTORY_TOTAL', 10)
291
stub_const('Readline::HISTORY', Array.new(15) { |i| "Command #{i + 1}" })
292
293
history_output = <<~E_LOG
294
## %grnHistory%clr
295
296
The following commands were ran during the session and before this issue occurred:
297
<details>
298
<summary>Collapse</summary>
299
300
```
301
5 Command 6
302
6 Command 7
303
7 Command 8
304
8 Command 9
305
9 Command 10
306
10 Command 11
307
11 Command 12
308
12 Command 13
309
13 Command 14
310
14 Command 15
311
```
312
313
</details>
314
315
316
E_LOG
317
318
expect(subject.history(driver)).to eql(history_output)
319
end
320
321
it 'correctly retrieves and parses a command history larger than the command total and a session command count smaller than the command total' do
322
driver = instance_double(
323
::Msf::Ui::Console::Driver,
324
hist_last_saved: 10
325
)
326
327
stub_const('Msf::Ui::Debug::COMMAND_HISTORY_TOTAL', 10)
328
stub_const('Readline::HISTORY', Array.new(15) { |i| "Command #{i + 1}" })
329
330
history_output = <<~E_LOG
331
## %grnHistory%clr
332
333
The following commands were ran during the session and before this issue occurred:
334
<details>
335
<summary>Collapse</summary>
336
337
```
338
10 Command 11
339
11 Command 12
340
12 Command 13
341
13 Command 14
342
14 Command 15
343
```
344
345
</details>
346
347
348
E_LOG
349
350
expect(subject.history(driver)).to eql(history_output)
351
end
352
353
it 'correctly retrieves and parses an empty config file and datastore' do
354
allow(::Msf::Config).to receive(:config_file).and_return(File.join(file_fixtures_path, 'config_files', 'empty.ini'))
355
356
framework = instance_double(
357
::Msf::Framework,
358
datastore: Msf::DataStore.new
359
)
360
361
driver = instance_double(
362
::Msf::Ui::Console::Driver,
363
get_config_core: 'config_core',
364
get_config: {},
365
get_config_group: 'config_group',
366
active_module: nil
367
)
368
369
expected_output = <<~OUTPUT
370
## %grnModule/Datastore%clr
371
372
The following global/module datastore, and database setup was configured before the issue occurred:
373
<details>
374
<summary>Collapse</summary>
375
376
```
377
The local config file is empty, no global variables are set, and there is no active module.
378
```
379
380
</details>
381
382
383
OUTPUT
384
385
expect(subject.datastore(framework, driver)).to eql(expected_output)
386
end
387
388
it 'correctly retrieves and parses a populated global datastore' do
389
allow(::Msf::Config).to receive(:config_file).and_return(File.join(file_fixtures_path, 'config_files', 'empty.ini'))
390
391
framework_datastore = Msf::DataStore.new
392
framework_datastore.merge!(
393
{
394
'key1' => 'val1',
395
'key2' => 'val2',
396
'key3' => 'val3'
397
}
398
)
399
framework = instance_double(
400
::Msf::Framework,
401
datastore: framework_datastore
402
)
403
404
driver = instance_double(
405
::Msf::Ui::Console::Driver,
406
get_config_core: 'group/name/1',
407
get_config: {},
408
get_config_group: 'config_group',
409
active_module: nil
410
)
411
412
expected_output = <<~OUTPUT
413
## %grnModule/Datastore%clr
414
415
The following global/module datastore, and database setup was configured before the issue occurred:
416
<details>
417
<summary>Collapse</summary>
418
419
```
420
[group/name/1]
421
key1=val1
422
key2=val2
423
key3=val3
424
```
425
426
</details>
427
428
429
OUTPUT
430
431
expect(subject.datastore(framework, driver)).to eql(expected_output)
432
end
433
434
it 'correctly retrieves and parses a populated global datastore and current module' do
435
allow(::Msf::Config).to receive(:config_file).and_return(File.join(file_fixtures_path, 'config_files', 'empty.ini'))
436
437
datastore = Msf::DataStore.new
438
datastore.merge!(
439
{
440
'key1' => 'val1',
441
'key2' => 'val2',
442
'key3' => 'val3'
443
}
444
)
445
framework = instance_double(
446
::Msf::Framework,
447
datastore: datastore
448
)
449
450
driver = instance_double(
451
::Msf::Ui::Console::Driver,
452
get_config_core: 'group/name/1',
453
get_config: {
454
'key4' => 'val4',
455
'key5' => 'val5',
456
'key6' => 'val6'
457
},
458
get_config_group: 'group/name/2',
459
active_module: nil
460
)
461
462
expected_output = <<~OUTPUT
463
## %grnModule/Datastore%clr
464
465
The following global/module datastore, and database setup was configured before the issue occurred:
466
<details>
467
<summary>Collapse</summary>
468
469
```
470
[group/name/1]
471
key1=val1
472
key2=val2
473
key3=val3
474
475
[group/name/2]
476
key4=val4
477
key5=val5
478
key6=val6
479
```
480
481
</details>
482
483
484
OUTPUT
485
486
expect(subject.datastore(framework, driver)).to eql(expected_output)
487
end
488
489
it 'correctly retrieves and parses active module variables' do
490
allow(::Msf::Config).to receive(:config_file).and_return(File.join(file_fixtures_path, 'config_files', 'empty.ini'))
491
492
framework_datastore = Msf::DataStore.new
493
framework = instance_double(
494
::Msf::Framework,
495
datastore: framework_datastore
496
)
497
498
module_datastore = Msf::ModuleDataStore.new(framework_datastore)
499
module_datastore.merge!(
500
{
501
'key7' => 'val7',
502
'key8' => 'default_val8',
503
'key9' => 'val9'
504
}
505
)
506
active_module = instance_double(
507
Msf::Module,
508
datastore: module_datastore,
509
refname: 'active/module/variables'
510
)
511
512
driver = instance_double(
513
::Msf::Ui::Console::Driver,
514
get_config_core: 'group/name/1',
515
get_config: {},
516
get_config_group: 'config_group',
517
active_module: active_module
518
)
519
520
expected_output = <<~OUTPUT
521
## %grnModule/Datastore%clr
522
523
The following global/module datastore, and database setup was configured before the issue occurred:
524
<details>
525
<summary>Collapse</summary>
526
527
```
528
[active/module/variables]
529
key7=val7
530
key8=default_val8
531
key9=val9
532
```
533
534
</details>
535
536
537
OUTPUT
538
539
expect(subject.datastore(framework, driver)).to eql(expected_output)
540
end
541
542
it 'preferences the framework datastore values over config stored values' do
543
allow(::Msf::Config).to receive(:config_file).and_return(File.join(file_fixtures_path, 'config_files', 'module.ini'))
544
545
framework_datastore = Msf::DataStore.new
546
framework_datastore.merge!(
547
{
548
'key1' => 'val1',
549
'key2' => 'val2',
550
'key3' => 'val3'
551
}
552
)
553
framework = instance_double(
554
::Msf::Framework,
555
datastore: framework_datastore
556
)
557
558
driver = instance_double(
559
::Msf::Ui::Console::Driver,
560
get_config_core: 'group/name/1',
561
get_config: {
562
'key4' => 'val4',
563
'key5' => 'val5',
564
'key6' => 'val6'
565
},
566
get_config_group: 'group/name/2',
567
active_module: nil
568
)
569
570
expected_output = <<~OUTPUT
571
## %grnModule/Datastore%clr
572
573
The following global/module datastore, and database setup was configured before the issue occurred:
574
<details>
575
<summary>Collapse</summary>
576
577
```
578
[group/name/1]
579
key1=val1
580
key2=val2
581
key3=val3
582
583
[group/name/2]
584
key4=val4
585
key5=val5
586
key6=val6
587
```
588
589
</details>
590
591
592
OUTPUT
593
594
expect(subject.datastore(framework, driver)).to eql(expected_output)
595
end
596
597
it 'correctly retrieves and parses Database information' do
598
allow(::Msf::Config).to receive(:config_file).and_return(File.join(file_fixtures_path, 'config_files', 'db.ini'))
599
600
framework_datastore = Msf::DataStore.new
601
framework = instance_double(
602
::Msf::Framework,
603
datastore: framework_datastore
604
)
605
606
driver = instance_double(
607
::Msf::Ui::Console::Driver,
608
get_config_core: 'group/name/1',
609
get_config: {},
610
get_config_group: 'group/name/2',
611
active_module: nil
612
)
613
614
expected_output = <<~OUTPUT
615
## %grnModule/Datastore%clr
616
617
The following global/module datastore, and database setup was configured before the issue occurred:
618
<details>
619
<summary>Collapse</summary>
620
621
```
622
[framework/database/1]
623
key10=[Filtered]
624
key11=[Filtered]
625
626
[framework/database/2]
627
key12=[Filtered]
628
key13=[Filtered]
629
```
630
631
</details>
632
633
634
OUTPUT
635
636
expect(subject.datastore(framework, driver)).to eql(expected_output)
637
end
638
639
it 'log parsing correctly retrieves and parses logs shorter than the log line total' do
640
range = 1..30
641
logs = ''
642
range.each do |i|
643
logs += "[00/00/0000 00:00:00] [e(0)] core: Log Line #{i}\n"
644
end
645
646
allow(::Msf::Config).to receive(:log_directory).and_return(File.join(file_fixtures_path, 'debug', 'framework_logs', 'short'))
647
648
error_log_output = <<~E_LOG
649
## %grnFramework Logs%clr
650
651
The following framework logs were recorded before the issue occurred:
652
<details>
653
<summary>Collapse</summary>
654
655
```
656
[00/00/0000 00:00:00] [e(0)] core: Log Line 1
657
[00/00/0000 00:00:00] [e(0)] core: Log Line 2
658
[00/00/0000 00:00:00] [e(0)] core: Log Line 3
659
[00/00/0000 00:00:00] [e(0)] core: Log Line 4
660
[00/00/0000 00:00:00] [e(0)] core: Log Line 5
661
[00/00/0000 00:00:00] [e(0)] core: Log Line 6
662
[00/00/0000 00:00:00] [e(0)] core: Log Line 7
663
[00/00/0000 00:00:00] [e(0)] core: Log Line 8
664
[00/00/0000 00:00:00] [e(0)] core: Log Line 9
665
[00/00/0000 00:00:00] [e(0)] core: Log Line 10
666
[00/00/0000 00:00:00] [e(0)] core: Log Line 11
667
[00/00/0000 00:00:00] [e(0)] core: Log Line 12
668
[00/00/0000 00:00:00] [e(0)] core: Log Line 13
669
[00/00/0000 00:00:00] [e(0)] core: Log Line 14
670
[00/00/0000 00:00:00] [e(0)] core: Log Line 15
671
[00/00/0000 00:00:00] [e(0)] core: Log Line 16
672
[00/00/0000 00:00:00] [e(0)] core: Log Line 17
673
[00/00/0000 00:00:00] [e(0)] core: Log Line 18
674
[00/00/0000 00:00:00] [e(0)] core: Log Line 19
675
[00/00/0000 00:00:00] [e(0)] core: Log Line 20
676
[00/00/0000 00:00:00] [e(0)] core: Log Line 21
677
[00/00/0000 00:00:00] [e(0)] core: Log Line 22
678
[00/00/0000 00:00:00] [e(0)] core: Log Line 23
679
[00/00/0000 00:00:00] [e(0)] core: Log Line 24
680
[00/00/0000 00:00:00] [e(0)] core: Log Line 25
681
[00/00/0000 00:00:00] [e(0)] core: Log Line 26
682
[00/00/0000 00:00:00] [e(0)] core: Log Line 27
683
[00/00/0000 00:00:00] [e(0)] core: Log Line 28
684
[00/00/0000 00:00:00] [e(0)] core: Log Line 29
685
[00/00/0000 00:00:00] [e(0)] core: Log Line 30
686
```
687
688
</details>
689
690
691
## %grnWeb Service Logs%clr
692
693
The following web service logs were recorded before the issue occurred:
694
<details>
695
<summary>Collapse</summary>
696
697
```
698
[-] core: Log Line 1
699
[-] core: Log Line 2
700
[-] core: Log Line 3
701
[-] core: Log Line 4
702
[-] core: Log Line 5
703
[-] core: Log Line 6
704
[-] core: Log Line 7
705
[-] core: Log Line 8
706
[-] core: Log Line 9
707
[-] core: Log Line 10
708
[-] core: Log Line 11
709
[-] core: Log Line 12
710
[-] core: Log Line 13
711
[-] core: Log Line 14
712
[-] core: Log Line 15
713
[-] core: Log Line 16
714
[-] core: Log Line 17
715
[-] core: Log Line 18
716
[-] core: Log Line 19
717
[-] core: Log Line 20
718
[-] core: Log Line 21
719
[-] core: Log Line 22
720
[-] core: Log Line 23
721
[-] core: Log Line 24
722
[-] core: Log Line 25
723
[-] core: Log Line 26
724
[-] core: Log Line 27
725
[-] core: Log Line 28
726
[-] core: Log Line 29
727
[-] core: Log Line 30
728
```
729
730
</details>
731
732
733
E_LOG
734
735
expect(subject.logs).to eql(error_log_output)
736
end
737
738
it 'log parsing correctly retrieves and parses logs equal to the log line total' do
739
range = 1..50
740
logs = ''
741
range.each do |i|
742
logs += "[00/00/0000 00:00:00] [e(0)] core: Log Line #{i}\n"
743
end
744
745
allow(::Msf::Config).to receive(:log_directory).and_return(File.join(file_fixtures_path, 'debug', 'framework_logs', 'equal'))
746
747
error_log_output = <<~E_LOG
748
## %grnFramework Logs%clr
749
750
The following framework logs were recorded before the issue occurred:
751
<details>
752
<summary>Collapse</summary>
753
754
```
755
[00/00/0000 00:00:00] [e(0)] core: Log Line 1
756
[00/00/0000 00:00:00] [e(0)] core: Log Line 2
757
[00/00/0000 00:00:00] [e(0)] core: Log Line 3
758
[00/00/0000 00:00:00] [e(0)] core: Log Line 4
759
[00/00/0000 00:00:00] [e(0)] core: Log Line 5
760
[00/00/0000 00:00:00] [e(0)] core: Log Line 6
761
[00/00/0000 00:00:00] [e(0)] core: Log Line 7
762
[00/00/0000 00:00:00] [e(0)] core: Log Line 8
763
[00/00/0000 00:00:00] [e(0)] core: Log Line 9
764
[00/00/0000 00:00:00] [e(0)] core: Log Line 10
765
[00/00/0000 00:00:00] [e(0)] core: Log Line 11
766
[00/00/0000 00:00:00] [e(0)] core: Log Line 12
767
[00/00/0000 00:00:00] [e(0)] core: Log Line 13
768
[00/00/0000 00:00:00] [e(0)] core: Log Line 14
769
[00/00/0000 00:00:00] [e(0)] core: Log Line 15
770
[00/00/0000 00:00:00] [e(0)] core: Log Line 16
771
[00/00/0000 00:00:00] [e(0)] core: Log Line 17
772
[00/00/0000 00:00:00] [e(0)] core: Log Line 18
773
[00/00/0000 00:00:00] [e(0)] core: Log Line 19
774
[00/00/0000 00:00:00] [e(0)] core: Log Line 20
775
[00/00/0000 00:00:00] [e(0)] core: Log Line 21
776
[00/00/0000 00:00:00] [e(0)] core: Log Line 22
777
[00/00/0000 00:00:00] [e(0)] core: Log Line 23
778
[00/00/0000 00:00:00] [e(0)] core: Log Line 24
779
[00/00/0000 00:00:00] [e(0)] core: Log Line 25
780
[00/00/0000 00:00:00] [e(0)] core: Log Line 26
781
[00/00/0000 00:00:00] [e(0)] core: Log Line 27
782
[00/00/0000 00:00:00] [e(0)] core: Log Line 28
783
[00/00/0000 00:00:00] [e(0)] core: Log Line 29
784
[00/00/0000 00:00:00] [e(0)] core: Log Line 30
785
[00/00/0000 00:00:00] [e(0)] core: Log Line 31
786
[00/00/0000 00:00:00] [e(0)] core: Log Line 32
787
[00/00/0000 00:00:00] [e(0)] core: Log Line 33
788
[00/00/0000 00:00:00] [e(0)] core: Log Line 34
789
[00/00/0000 00:00:00] [e(0)] core: Log Line 35
790
[00/00/0000 00:00:00] [e(0)] core: Log Line 36
791
[00/00/0000 00:00:00] [e(0)] core: Log Line 37
792
[00/00/0000 00:00:00] [e(0)] core: Log Line 38
793
[00/00/0000 00:00:00] [e(0)] core: Log Line 39
794
[00/00/0000 00:00:00] [e(0)] core: Log Line 40
795
[00/00/0000 00:00:00] [e(0)] core: Log Line 41
796
[00/00/0000 00:00:00] [e(0)] core: Log Line 42
797
[00/00/0000 00:00:00] [e(0)] core: Log Line 43
798
[00/00/0000 00:00:00] [e(0)] core: Log Line 44
799
[00/00/0000 00:00:00] [e(0)] core: Log Line 45
800
[00/00/0000 00:00:00] [e(0)] core: Log Line 46
801
[00/00/0000 00:00:00] [e(0)] core: Log Line 47
802
[00/00/0000 00:00:00] [e(0)] core: Log Line 48
803
[00/00/0000 00:00:00] [e(0)] core: Log Line 49
804
[00/00/0000 00:00:00] [e(0)] core: Log Line 50
805
```
806
807
</details>
808
809
810
## %grnWeb Service Logs%clr
811
812
The following web service logs were recorded before the issue occurred:
813
<details>
814
<summary>Collapse</summary>
815
816
```
817
[-] core: Log Line 1
818
[-] core: Log Line 2
819
[-] core: Log Line 3
820
[-] core: Log Line 4
821
[-] core: Log Line 5
822
[-] core: Log Line 6
823
[-] core: Log Line 7
824
[-] core: Log Line 8
825
[-] core: Log Line 9
826
[-] core: Log Line 10
827
[-] core: Log Line 11
828
[-] core: Log Line 12
829
[-] core: Log Line 13
830
[-] core: Log Line 14
831
[-] core: Log Line 15
832
[-] core: Log Line 16
833
[-] core: Log Line 17
834
[-] core: Log Line 18
835
[-] core: Log Line 19
836
[-] core: Log Line 20
837
[-] core: Log Line 21
838
[-] core: Log Line 22
839
[-] core: Log Line 23
840
[-] core: Log Line 24
841
[-] core: Log Line 25
842
[-] core: Log Line 26
843
[-] core: Log Line 27
844
[-] core: Log Line 28
845
[-] core: Log Line 29
846
[-] core: Log Line 30
847
[-] core: Log Line 31
848
[-] core: Log Line 32
849
[-] core: Log Line 33
850
[-] core: Log Line 34
851
[-] core: Log Line 35
852
[-] core: Log Line 36
853
[-] core: Log Line 37
854
[-] core: Log Line 38
855
[-] core: Log Line 39
856
[-] core: Log Line 40
857
[-] core: Log Line 41
858
[-] core: Log Line 42
859
[-] core: Log Line 43
860
[-] core: Log Line 44
861
[-] core: Log Line 45
862
[-] core: Log Line 46
863
[-] core: Log Line 47
864
[-] core: Log Line 48
865
[-] core: Log Line 49
866
[-] core: Log Line 50
867
[-] core: Log Line 51
868
[-] core: Log Line 52
869
[-] core: Log Line 53
870
[-] core: Log Line 54
871
[-] core: Log Line 55
872
[-] core: Log Line 56
873
[-] core: Log Line 57
874
[-] core: Log Line 58
875
[-] core: Log Line 59
876
[-] core: Log Line 60
877
[-] core: Log Line 61
878
[-] core: Log Line 62
879
[-] core: Log Line 63
880
[-] core: Log Line 64
881
[-] core: Log Line 65
882
[-] core: Log Line 66
883
[-] core: Log Line 67
884
[-] core: Log Line 68
885
[-] core: Log Line 69
886
[-] core: Log Line 70
887
[-] core: Log Line 71
888
[-] core: Log Line 72
889
[-] core: Log Line 73
890
[-] core: Log Line 74
891
[-] core: Log Line 75
892
[-] core: Log Line 76
893
[-] core: Log Line 77
894
[-] core: Log Line 78
895
[-] core: Log Line 79
896
[-] core: Log Line 80
897
[-] core: Log Line 81
898
[-] core: Log Line 82
899
[-] core: Log Line 83
900
[-] core: Log Line 84
901
[-] core: Log Line 85
902
[-] core: Log Line 86
903
[-] core: Log Line 87
904
[-] core: Log Line 88
905
[-] core: Log Line 89
906
[-] core: Log Line 90
907
[-] core: Log Line 91
908
[-] core: Log Line 92
909
[-] core: Log Line 93
910
[-] core: Log Line 94
911
[-] core: Log Line 95
912
[-] core: Log Line 96
913
[-] core: Log Line 97
914
[-] core: Log Line 98
915
[-] core: Log Line 99
916
[-] core: Log Line 100
917
[-] core: Log Line 101
918
[-] core: Log Line 102
919
[-] core: Log Line 103
920
[-] core: Log Line 104
921
[-] core: Log Line 105
922
[-] core: Log Line 106
923
[-] core: Log Line 107
924
[-] core: Log Line 108
925
[-] core: Log Line 109
926
[-] core: Log Line 110
927
[-] core: Log Line 111
928
[-] core: Log Line 112
929
[-] core: Log Line 113
930
[-] core: Log Line 114
931
[-] core: Log Line 115
932
[-] core: Log Line 116
933
[-] core: Log Line 117
934
[-] core: Log Line 118
935
[-] core: Log Line 119
936
[-] core: Log Line 120
937
[-] core: Log Line 121
938
[-] core: Log Line 122
939
[-] core: Log Line 123
940
[-] core: Log Line 124
941
[-] core: Log Line 125
942
[-] core: Log Line 126
943
[-] core: Log Line 127
944
[-] core: Log Line 128
945
[-] core: Log Line 129
946
[-] core: Log Line 130
947
[-] core: Log Line 131
948
[-] core: Log Line 132
949
[-] core: Log Line 133
950
[-] core: Log Line 134
951
[-] core: Log Line 135
952
[-] core: Log Line 136
953
[-] core: Log Line 137
954
[-] core: Log Line 138
955
[-] core: Log Line 139
956
[-] core: Log Line 140
957
[-] core: Log Line 141
958
[-] core: Log Line 142
959
[-] core: Log Line 143
960
[-] core: Log Line 144
961
[-] core: Log Line 145
962
[-] core: Log Line 146
963
[-] core: Log Line 147
964
[-] core: Log Line 148
965
[-] core: Log Line 149
966
[-] core: Log Line 150
967
```
968
969
</details>
970
971
972
E_LOG
973
974
expect(subject.logs).to eql(error_log_output)
975
end
976
977
it 'log parsing correctly retrieves and parses logs larger than the log line total' do
978
range = 51..100
979
logs = ''
980
range.each do |i|
981
logs += "[00/00/0000 00:00:00] [e(0)] core: Log Line #{i}\n"
982
end
983
984
allow(::Msf::Config).to receive(:log_directory).and_return(File.join(file_fixtures_path, 'debug', 'framework_logs', 'long'))
985
986
error_log_output = <<~E_LOG
987
## %grnFramework Logs%clr
988
989
The following framework logs were recorded before the issue occurred:
990
<details>
991
<summary>Collapse</summary>
992
993
```
994
[00/00/0000 00:00:00] [e(0)] core: Log Line 51
995
[00/00/0000 00:00:00] [e(0)] core: Log Line 52
996
[00/00/0000 00:00:00] [e(0)] core: Log Line 53
997
[00/00/0000 00:00:00] [e(0)] core: Log Line 54
998
[00/00/0000 00:00:00] [e(0)] core: Log Line 55
999
[00/00/0000 00:00:00] [e(0)] core: Log Line 56
1000
[00/00/0000 00:00:00] [e(0)] core: Log Line 57
1001
[00/00/0000 00:00:00] [e(0)] core: Log Line 58
1002
[00/00/0000 00:00:00] [e(0)] core: Log Line 59
1003
[00/00/0000 00:00:00] [e(0)] core: Log Line 60
1004
[00/00/0000 00:00:00] [e(0)] core: Log Line 61
1005
[00/00/0000 00:00:00] [e(0)] core: Log Line 62
1006
[00/00/0000 00:00:00] [e(0)] core: Log Line 63
1007
[00/00/0000 00:00:00] [e(0)] core: Log Line 64
1008
[00/00/0000 00:00:00] [e(0)] core: Log Line 65
1009
[00/00/0000 00:00:00] [e(0)] core: Log Line 66
1010
[00/00/0000 00:00:00] [e(0)] core: Log Line 67
1011
[00/00/0000 00:00:00] [e(0)] core: Log Line 68
1012
[00/00/0000 00:00:00] [e(0)] core: Log Line 69
1013
[00/00/0000 00:00:00] [e(0)] core: Log Line 70
1014
[00/00/0000 00:00:00] [e(0)] core: Log Line 71
1015
[00/00/0000 00:00:00] [e(0)] core: Log Line 72
1016
[00/00/0000 00:00:00] [e(0)] core: Log Line 73
1017
[00/00/0000 00:00:00] [e(0)] core: Log Line 74
1018
[00/00/0000 00:00:00] [e(0)] core: Log Line 75
1019
[00/00/0000 00:00:00] [e(0)] core: Log Line 76
1020
[00/00/0000 00:00:00] [e(0)] core: Log Line 77
1021
[00/00/0000 00:00:00] [e(0)] core: Log Line 78
1022
[00/00/0000 00:00:00] [e(0)] core: Log Line 79
1023
[00/00/0000 00:00:00] [e(0)] core: Log Line 80
1024
[00/00/0000 00:00:00] [e(0)] core: Log Line 81
1025
[00/00/0000 00:00:00] [e(0)] core: Log Line 82
1026
[00/00/0000 00:00:00] [e(0)] core: Log Line 83
1027
[00/00/0000 00:00:00] [e(0)] core: Log Line 84
1028
[00/00/0000 00:00:00] [e(0)] core: Log Line 85
1029
[00/00/0000 00:00:00] [e(0)] core: Log Line 86
1030
[00/00/0000 00:00:00] [e(0)] core: Log Line 87
1031
[00/00/0000 00:00:00] [e(0)] core: Log Line 88
1032
[00/00/0000 00:00:00] [e(0)] core: Log Line 89
1033
[00/00/0000 00:00:00] [e(0)] core: Log Line 90
1034
[00/00/0000 00:00:00] [e(0)] core: Log Line 91
1035
[00/00/0000 00:00:00] [e(0)] core: Log Line 92
1036
[00/00/0000 00:00:00] [e(0)] core: Log Line 93
1037
[00/00/0000 00:00:00] [e(0)] core: Log Line 94
1038
[00/00/0000 00:00:00] [e(0)] core: Log Line 95
1039
[00/00/0000 00:00:00] [e(0)] core: Log Line 96
1040
[00/00/0000 00:00:00] [e(0)] core: Log Line 97
1041
[00/00/0000 00:00:00] [e(0)] core: Log Line 98
1042
[00/00/0000 00:00:00] [e(0)] core: Log Line 99
1043
[00/00/0000 00:00:00] [e(0)] core: Log Line 100
1044
```
1045
1046
</details>
1047
1048
1049
## %grnWeb Service Logs%clr
1050
1051
The following web service logs were recorded before the issue occurred:
1052
<details>
1053
<summary>Collapse</summary>
1054
1055
```
1056
[-] core: Log Line 151
1057
[-] core: Log Line 152
1058
[-] core: Log Line 153
1059
[-] core: Log Line 154
1060
[-] core: Log Line 155
1061
[-] core: Log Line 156
1062
[-] core: Log Line 157
1063
[-] core: Log Line 158
1064
[-] core: Log Line 159
1065
[-] core: Log Line 160
1066
[-] core: Log Line 161
1067
[-] core: Log Line 162
1068
[-] core: Log Line 163
1069
[-] core: Log Line 164
1070
[-] core: Log Line 165
1071
[-] core: Log Line 166
1072
[-] core: Log Line 167
1073
[-] core: Log Line 168
1074
[-] core: Log Line 169
1075
[-] core: Log Line 170
1076
[-] core: Log Line 171
1077
[-] core: Log Line 172
1078
[-] core: Log Line 173
1079
[-] core: Log Line 174
1080
[-] core: Log Line 175
1081
[-] core: Log Line 176
1082
[-] core: Log Line 177
1083
[-] core: Log Line 178
1084
[-] core: Log Line 179
1085
[-] core: Log Line 180
1086
[-] core: Log Line 181
1087
[-] core: Log Line 182
1088
[-] core: Log Line 183
1089
[-] core: Log Line 184
1090
[-] core: Log Line 185
1091
[-] core: Log Line 186
1092
[-] core: Log Line 187
1093
[-] core: Log Line 188
1094
[-] core: Log Line 189
1095
[-] core: Log Line 190
1096
[-] core: Log Line 191
1097
[-] core: Log Line 192
1098
[-] core: Log Line 193
1099
[-] core: Log Line 194
1100
[-] core: Log Line 195
1101
[-] core: Log Line 196
1102
[-] core: Log Line 197
1103
[-] core: Log Line 198
1104
[-] core: Log Line 199
1105
[-] core: Log Line 200
1106
[-] core: Log Line 201
1107
[-] core: Log Line 202
1108
[-] core: Log Line 203
1109
[-] core: Log Line 204
1110
[-] core: Log Line 205
1111
[-] core: Log Line 206
1112
[-] core: Log Line 207
1113
[-] core: Log Line 208
1114
[-] core: Log Line 209
1115
[-] core: Log Line 210
1116
[-] core: Log Line 211
1117
[-] core: Log Line 212
1118
[-] core: Log Line 213
1119
[-] core: Log Line 214
1120
[-] core: Log Line 215
1121
[-] core: Log Line 216
1122
[-] core: Log Line 217
1123
[-] core: Log Line 218
1124
[-] core: Log Line 219
1125
[-] core: Log Line 220
1126
[-] core: Log Line 221
1127
[-] core: Log Line 222
1128
[-] core: Log Line 223
1129
[-] core: Log Line 224
1130
[-] core: Log Line 225
1131
[-] core: Log Line 226
1132
[-] core: Log Line 227
1133
[-] core: Log Line 228
1134
[-] core: Log Line 229
1135
[-] core: Log Line 230
1136
[-] core: Log Line 231
1137
[-] core: Log Line 232
1138
[-] core: Log Line 233
1139
[-] core: Log Line 234
1140
[-] core: Log Line 235
1141
[-] core: Log Line 236
1142
[-] core: Log Line 237
1143
[-] core: Log Line 238
1144
[-] core: Log Line 239
1145
[-] core: Log Line 240
1146
[-] core: Log Line 241
1147
[-] core: Log Line 242
1148
[-] core: Log Line 243
1149
[-] core: Log Line 244
1150
[-] core: Log Line 245
1151
[-] core: Log Line 246
1152
[-] core: Log Line 247
1153
[-] core: Log Line 248
1154
[-] core: Log Line 249
1155
[-] core: Log Line 250
1156
[-] core: Log Line 251
1157
[-] core: Log Line 252
1158
[-] core: Log Line 253
1159
[-] core: Log Line 254
1160
[-] core: Log Line 255
1161
[-] core: Log Line 256
1162
[-] core: Log Line 257
1163
[-] core: Log Line 258
1164
[-] core: Log Line 259
1165
[-] core: Log Line 260
1166
[-] core: Log Line 261
1167
[-] core: Log Line 262
1168
[-] core: Log Line 263
1169
[-] core: Log Line 264
1170
[-] core: Log Line 265
1171
[-] core: Log Line 266
1172
[-] core: Log Line 267
1173
[-] core: Log Line 268
1174
[-] core: Log Line 269
1175
[-] core: Log Line 270
1176
[-] core: Log Line 271
1177
[-] core: Log Line 272
1178
[-] core: Log Line 273
1179
[-] core: Log Line 274
1180
[-] core: Log Line 275
1181
[-] core: Log Line 276
1182
[-] core: Log Line 277
1183
[-] core: Log Line 278
1184
[-] core: Log Line 279
1185
[-] core: Log Line 280
1186
[-] core: Log Line 281
1187
[-] core: Log Line 282
1188
[-] core: Log Line 283
1189
[-] core: Log Line 284
1190
[-] core: Log Line 285
1191
[-] core: Log Line 286
1192
[-] core: Log Line 287
1193
[-] core: Log Line 288
1194
[-] core: Log Line 289
1195
[-] core: Log Line 290
1196
[-] core: Log Line 291
1197
[-] core: Log Line 292
1198
[-] core: Log Line 293
1199
[-] core: Log Line 294
1200
[-] core: Log Line 295
1201
[-] core: Log Line 296
1202
[-] core: Log Line 297
1203
[-] core: Log Line 298
1204
[-] core: Log Line 299
1205
[-] core: Log Line 300
1206
```
1207
1208
</details>
1209
1210
1211
E_LOG
1212
1213
expect(subject.logs).to eql(error_log_output)
1214
end
1215
1216
it 'log parsing correctly retrieves and parses an empty log file' do
1217
allow(::Msf::Config).to receive(:log_directory).and_return(File.join(file_fixtures_path, 'debug', 'framework_logs', 'empty'))
1218
1219
error_log_output = <<~E_LOG
1220
## %grnFramework Logs%clr
1221
1222
The following framework logs were recorded before the issue occurred:
1223
<details>
1224
<summary>Collapse</summary>
1225
1226
```
1227
1228
```
1229
1230
</details>
1231
1232
1233
## %grnWeb Service Logs%clr
1234
1235
The following web service logs were recorded before the issue occurred:
1236
<details>
1237
<summary>Collapse</summary>
1238
1239
```
1240
1241
```
1242
1243
</details>
1244
1245
1246
E_LOG
1247
1248
expect(subject.logs).to eql(error_log_output)
1249
end
1250
1251
it 'log parsing correctly retrieves and returns a missing log file message' do
1252
allow(::Msf::Config).to receive(:log_directory).and_return('FAKE_PATH')
1253
1254
error_log_output = <<~E_LOG
1255
## %grnFramework Logs%clr
1256
1257
The following framework logs were recorded before the issue occurred:
1258
<details>
1259
<summary>Collapse</summary>
1260
1261
```
1262
framework.log does not exist.
1263
```
1264
1265
</details>
1266
1267
1268
## %grnWeb Service Logs%clr
1269
1270
The following web service logs were recorded before the issue occurred:
1271
<details>
1272
<summary>Collapse</summary>
1273
1274
```
1275
msf-ws.log does not exist.
1276
```
1277
1278
</details>
1279
1280
1281
E_LOG
1282
1283
expect(subject.logs).to eql(error_log_output)
1284
end
1285
1286
it 'correctly retrieves features and outputs them' do
1287
db = instance_double(
1288
Msf::DBManager,
1289
connection_established?: false,
1290
driver: 'driver'
1291
)
1292
1293
framework = instance_double(
1294
::Msf::Framework,
1295
features: instance_double(Msf::FeatureManager, all: features),
1296
db: db
1297
)
1298
1299
expected_output = <<~OUTPUT
1300
## %grnFramework Configuration%clr
1301
1302
The features are configured as follows:
1303
<details>
1304
<summary>Collapse</summary>
1305
1306
| name | enabled |
1307
|-:|-:|
1308
| filtered_options | false |
1309
| new_search_capabilities | true |
1310
1311
</details>
1312
1313
1314
OUTPUT
1315
1316
expect(subject.framework_config(framework)).to eql(expected_output)
1317
end
1318
1319
it 'correctly retrieves version information with no connected DB' do
1320
db = instance_double(
1321
Msf::DBManager,
1322
connection_established?: false,
1323
driver: 'driver'
1324
)
1325
1326
framework = instance_double(
1327
::Msf::Framework,
1328
version: 'VERSION',
1329
db: db
1330
)
1331
1332
allow(::Msf::Config).to receive(:install_root).and_return('bad/path')
1333
1334
expected_output = <<~OUTPUT
1335
## %grnVersion/Install%clr
1336
1337
The versions and install method of your Metasploit setup:
1338
<details>
1339
<summary>Collapse</summary>
1340
1341
```
1342
Framework: VERSION
1343
Ruby: #{RUBY_DESCRIPTION}
1344
OpenSSL: #{OpenSSL::OPENSSL_VERSION}
1345
Install Root: bad/path
1346
Session Type: driver selected, no connection
1347
Install Method: Other - Please specify
1348
```
1349
1350
</details>
1351
1352
1353
OUTPUT
1354
1355
expect(subject.versions(framework)).to eql(expected_output)
1356
end
1357
1358
it 'correctly retrieves version information with DB connected via http' do
1359
db = double(
1360
'Metasploit::Framework::DataService::DataProxy',
1361
name: 'db_name',
1362
driver: 'http',
1363
connection_established?: true
1364
)
1365
1366
framework = instance_double(
1367
::Msf::Framework,
1368
version: 'VERSION',
1369
db: db
1370
)
1371
1372
allow(::Msf::Config).to receive(:install_root).and_return('bad/path')
1373
1374
expected_output = <<~OUTPUT
1375
## %grnVersion/Install%clr
1376
1377
The versions and install method of your Metasploit setup:
1378
<details>
1379
<summary>Collapse</summary>
1380
1381
```
1382
Framework: VERSION
1383
Ruby: #{RUBY_DESCRIPTION}
1384
OpenSSL: #{OpenSSL::OPENSSL_VERSION}
1385
Install Root: bad/path
1386
Session Type: Connected to db_name. Connection type: http.
1387
Install Method: Other - Please specify
1388
```
1389
1390
</details>
1391
1392
1393
OUTPUT
1394
1395
expect(subject.versions(framework)).to eql(expected_output)
1396
end
1397
1398
it 'correctly retrieves version information with DB connected via local connection' do
1399
db = double(
1400
'Metasploit::Framework::DataService::DataProxy',
1401
connection_established?: true,
1402
driver: 'local'
1403
)
1404
1405
framework = instance_double(
1406
::Msf::Framework,
1407
version: 'VERSION',
1408
db: db
1409
)
1410
1411
connection_pool = instance_double(ActiveRecord::ConnectionAdapters::ConnectionPool)
1412
connection = double(
1413
'connection',
1414
current_database: 'current_db_connection',
1415
respond_to?: true
1416
)
1417
allow(connection_pool).to receive(:with_connection).and_yield(connection)
1418
1419
allow(::ApplicationRecord).to receive(:connection_pool).and_return(connection_pool)
1420
allow(::Msf::Config).to receive(:install_root).and_return('bad/path')
1421
1422
expected_output = <<~OUTPUT
1423
## %grnVersion/Install%clr
1424
1425
The versions and install method of your Metasploit setup:
1426
<details>
1427
<summary>Collapse</summary>
1428
1429
```
1430
Framework: VERSION
1431
Ruby: #{RUBY_DESCRIPTION}
1432
OpenSSL: #{OpenSSL::OPENSSL_VERSION}
1433
Install Root: bad/path
1434
Session Type: Connected to current_db_connection. Connection type: local.
1435
Install Method: Other - Please specify
1436
```
1437
1438
</details>
1439
1440
1441
OUTPUT
1442
1443
expect(subject.versions(framework)).to eql(expected_output)
1444
end
1445
1446
it 'correctly retrieves version information with no connected DB and a Kali Install' do
1447
db = instance_double(
1448
Msf::DBManager,
1449
connection_established?: false,
1450
driver: 'driver'
1451
)
1452
1453
framework = instance_double(
1454
::Msf::Framework,
1455
version: 'VERSION',
1456
db: db
1457
)
1458
1459
allow(::Msf::Config).to receive(:install_root).and_return(File.join(File::SEPARATOR, 'usr', 'share', 'metasploit-framework'))
1460
1461
expected_output = <<~OUTPUT
1462
## %grnVersion/Install%clr
1463
1464
The versions and install method of your Metasploit setup:
1465
<details>
1466
<summary>Collapse</summary>
1467
1468
```
1469
Framework: VERSION
1470
Ruby: #{RUBY_DESCRIPTION}
1471
OpenSSL: #{OpenSSL::OPENSSL_VERSION}
1472
Install Root: #{File.join(File::SEPARATOR, 'usr', 'share', 'metasploit-framework')}
1473
Session Type: driver selected, no connection
1474
Install Method: Other - Please specify
1475
```
1476
1477
</details>
1478
1479
1480
OUTPUT
1481
1482
expect(subject.versions(framework)).to eql(expected_output)
1483
end
1484
1485
it 'correctly retrieves version information with no connected DB and an Omnibus Install' do
1486
db = instance_double(
1487
Msf::DBManager,
1488
connection_established?: false,
1489
driver: 'driver'
1490
)
1491
1492
framework = instance_double(
1493
::Msf::Framework,
1494
version: 'VERSION',
1495
db: db
1496
)
1497
1498
allow(::Msf::Config).to receive(:install_root).and_return(File.join(file_fixtures_path, 'debug', 'installs', 'omnibus'))
1499
1500
expected_output = <<~OUTPUT
1501
## %grnVersion/Install%clr
1502
1503
The versions and install method of your Metasploit setup:
1504
<details>
1505
<summary>Collapse</summary>
1506
1507
```
1508
Framework: VERSION
1509
Ruby: #{RUBY_DESCRIPTION}
1510
OpenSSL: #{OpenSSL::OPENSSL_VERSION}
1511
Install Root: #{File.join(file_fixtures_path, 'debug', 'installs', 'omnibus')}
1512
Session Type: driver selected, no connection
1513
Install Method: Omnibus Installer
1514
```
1515
1516
</details>
1517
1518
1519
OUTPUT
1520
1521
expect(subject.versions(framework)).to eql(expected_output)
1522
end
1523
1524
it 'correctly retrieves version information with no connected DB and a Git Clone' do
1525
db = instance_double(
1526
Msf::DBManager,
1527
connection_established?: false,
1528
driver: 'driver'
1529
)
1530
1531
framework = instance_double(
1532
::Msf::Framework,
1533
version: 'VERSION',
1534
db: db
1535
)
1536
1537
allow(::Msf::Config).to receive(:install_root).and_return(File.join(file_fixtures_path, 'debug', 'installs'))
1538
allow(File).to receive(:directory?).with(File.join(Msf::Config.install_root, '.git')).and_return(true)
1539
1540
expected_output = <<~OUTPUT
1541
## %grnVersion/Install%clr
1542
1543
The versions and install method of your Metasploit setup:
1544
<details>
1545
<summary>Collapse</summary>
1546
1547
```
1548
Framework: VERSION
1549
Ruby: #{RUBY_DESCRIPTION}
1550
OpenSSL: #{OpenSSL::OPENSSL_VERSION}
1551
Install Root: #{File.join(file_fixtures_path, 'debug', 'installs')}
1552
Session Type: driver selected, no connection
1553
Install Method: Git Clone
1554
```
1555
1556
</details>
1557
1558
1559
OUTPUT
1560
1561
expect(subject.versions(framework)).to eql(expected_output)
1562
end
1563
1564
it 'correctly retrieves version information with no connected DB and a Arch Pacman install' do
1565
db = instance_double(
1566
Msf::DBManager,
1567
connection_established?: false,
1568
driver: 'driver'
1569
)
1570
1571
framework = instance_double(
1572
::Msf::Framework,
1573
version: 'VERSION',
1574
db: db
1575
)
1576
1577
allow(::Msf::Config).to receive(:install_root).times.and_return(File.join(File::SEPARATOR, 'opt', 'metasploit'))
1578
1579
expected_output = <<~OUTPUT
1580
## %grnVersion/Install%clr
1581
1582
The versions and install method of your Metasploit setup:
1583
<details>
1584
<summary>Collapse</summary>
1585
1586
```
1587
Framework: VERSION
1588
Ruby: #{RUBY_DESCRIPTION}
1589
OpenSSL: #{OpenSSL::OPENSSL_VERSION}
1590
Install Root: #{File.join(File::SEPARATOR, 'opt', 'metasploit')}
1591
Session Type: driver selected, no connection
1592
Install Method: Other - Please specify
1593
```
1594
1595
</details>
1596
1597
1598
OUTPUT
1599
1600
expect(subject.versions(framework)).to eql(expected_output)
1601
end
1602
1603
context 'Database Configuration Debug' do
1604
1605
it 'correctly retrieves the current empty workspace with DB connected' do
1606
workspace = FactoryBot.create(:mdm_workspace)
1607
1608
db = instance_double(
1609
Msf::DBManager,
1610
connection_established?: true,
1611
name: 'msf',
1612
driver: 'postgresql',
1613
active: true,
1614
workspace: workspace,
1615
workspaces: [workspace]
1616
)
1617
1618
framework = instance_double(
1619
::Msf::Framework,
1620
version: 'VERSION',
1621
db: db
1622
)
1623
1624
connection_pool = instance_double(ActiveRecord::ConnectionAdapters::ConnectionPool)
1625
connection = double(
1626
'connection',
1627
current_database: 'msf',
1628
respond_to?: true
1629
)
1630
allow(connection_pool).to receive(:with_connection).and_yield(connection)
1631
allow(::ApplicationRecord).to receive(:connection_pool).and_return(connection_pool)
1632
1633
allow(::Mdm::Workspace).to receive(:count).and_return(1)
1634
allow(::Mdm::Workspace).to receive_message_chain(:order, :take).and_return([workspace])
1635
allow(::Mdm::Host).to receive(:count).and_return(0)
1636
allow(::Mdm::Vuln).to receive(:count).and_return(0)
1637
allow(::Mdm::Note).to receive(:count).and_return(0)
1638
allow(::Mdm::Service).to receive(:count).and_return(0)
1639
1640
expected_output = <<~OUTPUT
1641
## %grnDatabase Configuration%clr
1642
1643
The database contains the following information:
1644
<details>
1645
<summary>Collapse</summary>
1646
1647
```
1648
Session Type: Connected to msf. Connection type: postgresql.
1649
```
1650
1651
| ID | Hosts | Vulnerabilities | Notes | Services |
1652
|-:|-:|-:|-:|-:|
1653
| #{workspace.id.to_fs(:delimited)} **(Current)** | 0 | 0 | 0 | 0 |
1654
| **Total (#{::Mdm::Workspace.count})** | **#{::Mdm::Host.count}** | **#{::Mdm::Vuln.count}** | **#{::Mdm::Note.count}** | **#{::Mdm::Service.count}** |
1655
1656
</details>
1657
1658
1659
OUTPUT
1660
1661
expect(subject.database_configuration(framework)).to eql(expected_output)
1662
end
1663
1664
it 'correctly retrieves the current workspace with contents with DB connected' do
1665
workspace = FactoryBot.create(:mdm_workspace)
1666
host = FactoryBot.create(:mdm_host, workspace: workspace)
1667
vuln = FactoryBot.create(:mdm_vuln, host: host)
1668
service = FactoryBot.create(:mdm_service, host: host)
1669
note = FactoryBot.create(:mdm_note, workspace: workspace, host: host, service: service, vuln: vuln)
1670
1671
db = instance_double(
1672
Msf::DBManager,
1673
connection_established?: true,
1674
name: 'msf',
1675
driver: 'postgresql',
1676
active: true,
1677
workspace: workspace,
1678
workspaces: [workspace]
1679
)
1680
1681
framework = instance_double(
1682
::Msf::Framework,
1683
version: 'VERSION',
1684
db: db
1685
)
1686
1687
connection_pool = instance_double(ActiveRecord::ConnectionAdapters::ConnectionPool)
1688
connection = double(
1689
'connection',
1690
current_database: 'msf',
1691
respond_to?: true
1692
)
1693
allow(connection_pool).to receive(:with_connection).and_yield(connection)
1694
allow(::ApplicationRecord).to receive(:connection_pool).and_return(connection_pool)
1695
1696
allow(::Mdm::Workspace).to receive(:count).and_return(1)
1697
allow(::Mdm::Workspace).to receive_message_chain(:order, :take).and_return([workspace])
1698
allow(::Mdm::Host).to receive(:count).and_return(1)
1699
allow(::Mdm::Vuln).to receive(:count).and_return(1)
1700
allow(::Mdm::Note).to receive(:count).and_return(1)
1701
allow(::Mdm::Service).to receive(:count).and_return(1)
1702
1703
expected_output = <<~OUTPUT
1704
## %grnDatabase Configuration%clr
1705
1706
The database contains the following information:
1707
<details>
1708
<summary>Collapse</summary>
1709
1710
```
1711
Session Type: Connected to msf. Connection type: postgresql.
1712
```
1713
1714
| ID | Hosts | Vulnerabilities | Notes | Services |
1715
|-:|-:|-:|-:|-:|
1716
| #{workspace.id.to_fs(:delimited)} **(Current)** | 1 | 1 | 1 | 1 |
1717
| **Total (#{::Mdm::Workspace.count})** | **#{::Mdm::Host.count}** | **#{::Mdm::Vuln.count}** | **#{::Mdm::Note.count}** | **#{::Mdm::Service.count}** |
1718
1719
</details>
1720
1721
1722
OUTPUT
1723
1724
expect(subject.database_configuration(framework)).to eql(expected_output)
1725
end
1726
1727
it 'correctly retrieves session type with DB not connected' do
1728
db = instance_double(
1729
Msf::DBManager,
1730
connection_established?: false,
1731
driver: 'postgresql',
1732
active: false
1733
)
1734
1735
framework = instance_double(
1736
::Msf::Framework,
1737
db: db
1738
)
1739
1740
expected_output = <<~OUTPUT
1741
## %grnDatabase Configuration%clr
1742
1743
The database contains the following information:
1744
<details>
1745
<summary>Collapse</summary>
1746
1747
```
1748
Session Type: postgresql selected, no connection
1749
```
1750
1751
</details>
1752
1753
1754
OUTPUT
1755
1756
expect(subject.database_configuration(framework)).to eql(expected_output)
1757
end
1758
1759
it 'correctly retrieves multiple empty workspaces with DB connected' do
1760
workspaces = 5.times.map { FactoryBot.create(:mdm_workspace) }
1761
1762
db = instance_double(
1763
Msf::DBManager,
1764
connection_established?: true,
1765
name: 'msf',
1766
driver: 'postgresql',
1767
active: true,
1768
workspace: workspaces.last,
1769
workspaces: workspaces
1770
)
1771
1772
framework = instance_double(
1773
::Msf::Framework,
1774
version: 'VERSION',
1775
db: db
1776
)
1777
1778
connection_pool = instance_double(ActiveRecord::ConnectionAdapters::ConnectionPool)
1779
connection = double(
1780
'connection',
1781
current_database: 'msf',
1782
respond_to?: true
1783
)
1784
allow(connection_pool).to receive(:with_connection).and_yield(connection)
1785
allow(::ApplicationRecord).to receive(:connection_pool).and_return(connection_pool)
1786
1787
allow(::Mdm::Workspace).to receive(:count).and_return(5)
1788
allow(::Mdm::Workspace).to receive_message_chain(:order, :take).and_return(workspaces)
1789
allow(::Mdm::Host).to receive(:count).and_return(0)
1790
allow(::Mdm::Vuln).to receive(:count).and_return(0)
1791
allow(::Mdm::Note).to receive(:count).and_return(0)
1792
allow(::Mdm::Service).to receive(:count).and_return(0)
1793
1794
expected_output = <<~OUTPUT
1795
## %grnDatabase Configuration%clr
1796
1797
The database contains the following information:
1798
<details>
1799
<summary>Collapse</summary>
1800
1801
```
1802
Session Type: Connected to msf. Connection type: postgresql.
1803
```
1804
1805
| ID | Hosts | Vulnerabilities | Notes | Services |
1806
|-:|-:|-:|-:|-:|
1807
| #{workspaces[0].id.to_fs(:delimited)} | 0 | 0 | 0 | 0 |
1808
| #{workspaces[1].id.to_fs(:delimited)} | 0 | 0 | 0 | 0 |
1809
| #{workspaces[2].id.to_fs(:delimited)} | 0 | 0 | 0 | 0 |
1810
| #{workspaces[3].id.to_fs(:delimited)} | 0 | 0 | 0 | 0 |
1811
| #{workspaces[4].id.to_fs(:delimited)} **(Current)** | 0 | 0 | 0 | 0 |
1812
| **Total (#{::Mdm::Workspace.count})** | **#{::Mdm::Host.count}** | **#{::Mdm::Vuln.count}** | **#{::Mdm::Note.count}** | **#{::Mdm::Service.count}** |
1813
1814
</details>
1815
1816
1817
OUTPUT
1818
1819
expect(subject.database_configuration(framework)).to eql(expected_output)
1820
end
1821
1822
it 'correctly retrieves multiple workspaces with content with DB connected' do
1823
workspaces = 5.times.map do |index|
1824
workspace = FactoryBot.create(:mdm_workspace)
1825
# Only some of the workspaces should have values to make the output not be the same for every workspace.
1826
if index.even?
1827
host = FactoryBot.create(:mdm_host, workspace: workspace)
1828
vuln = FactoryBot.create(:mdm_vuln, host: host)
1829
service = FactoryBot.create(:mdm_service, host: host)
1830
note = FactoryBot.create(:mdm_note, workspace: workspace, host: host, service: service, vuln: vuln)
1831
end
1832
workspace
1833
end
1834
1835
db = instance_double(
1836
Msf::DBManager,
1837
connection_established?: true,
1838
name: 'msf',
1839
driver: 'postgresql',
1840
active: true,
1841
workspace: workspaces.last,
1842
workspaces: workspaces
1843
)
1844
1845
framework = instance_double(
1846
::Msf::Framework,
1847
version: 'VERSION',
1848
db: db
1849
)
1850
1851
connection_pool = instance_double(ActiveRecord::ConnectionAdapters::ConnectionPool)
1852
connection = double(
1853
'connection',
1854
current_database: 'msf',
1855
respond_to?: true
1856
)
1857
allow(connection_pool).to receive(:with_connection).and_yield(connection)
1858
allow(::ApplicationRecord).to receive(:connection_pool).and_return(connection_pool)
1859
1860
allow(::Mdm::Workspace).to receive(:count).and_return(5)
1861
allow(::Mdm::Workspace).to receive_message_chain(:order, :take).and_return(workspaces)
1862
allow(::Mdm::Host).to receive(:count).and_return(2)
1863
allow(::Mdm::Vuln).to receive(:count).and_return(2)
1864
allow(::Mdm::Note).to receive(:count).and_return(2)
1865
allow(::Mdm::Service).to receive(:count).and_return(2)
1866
1867
expected_output = <<~OUTPUT
1868
## %grnDatabase Configuration%clr
1869
1870
The database contains the following information:
1871
<details>
1872
<summary>Collapse</summary>
1873
1874
```
1875
Session Type: Connected to msf. Connection type: postgresql.
1876
```
1877
1878
| ID | Hosts | Vulnerabilities | Notes | Services |
1879
|-:|-:|-:|-:|-:|
1880
| #{workspaces[0].id.to_fs(:delimited)} | 1 | 1 | 1 | 1 |
1881
| #{workspaces[1].id.to_fs(:delimited)} | 0 | 0 | 0 | 0 |
1882
| #{workspaces[2].id.to_fs(:delimited)} | 1 | 1 | 1 | 1 |
1883
| #{workspaces[3].id.to_fs(:delimited)} | 0 | 0 | 0 | 0 |
1884
| #{workspaces[4].id.to_fs(:delimited)} **(Current)** | 1 | 1 | 1 | 1 |
1885
| **Total (#{::Mdm::Workspace.count})** | **#{::Mdm::Host.count}** | **#{::Mdm::Vuln.count}** | **#{::Mdm::Note.count}** | **#{::Mdm::Service.count}** |
1886
1887
</details>
1888
1889
1890
OUTPUT
1891
1892
expect(subject.database_configuration(framework)).to eql(expected_output)
1893
end
1894
end
1895
end
1896
1897