-
Notifications
You must be signed in to change notification settings - Fork 1
/
vsat.ps1
4427 lines (3710 loc) · 154 KB
/
vsat.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region Common
function Write-MessageWithLogging {
param (
[Parameter(Mandatory=$true)]
[string]$message,
[Parameter(Mandatory=$false)]
[ValidateSet('Black','DarkBlue','DarkGreen','DarkCyan','DarkRed','DarkMagenta','DarkYellow','Gray','DarkGray','Blue','Green','Cyan','Red','Magenta','Yellow','White')]
[string]$color = 'Black'
)
Write-Host $message -ForegroundColor $color
$message | Out-File -FilePath "$PSScriptRoot\vsat.log" -Append
}
function Test-Case {
param (
[Parameter(Mandatory=$true)]
[string]$case,
[Parameter(Mandatory=$false)]
[ValidateSet('Black','DarkBlue','DarkGreen','DarkCyan','DarkRed','DarkMagenta','DarkYellow','Gray','DarkGray','Blue','Green','Cyan','Red','Magenta','Yellow','White')]
[string]$color = 'Black'
)
# CIS 7.4 (L1) Ensure port groups are not configured to the value of the native VLAN
Write-MessageWithLogging -message $case -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# Get the vSwitches
$vSwitches = Get-VirtualPortGroup -Standard | Select virtualSwitch, Name, VlanID
# Checking for native VLAN ID 1
$defaultNativeVLAN = 1
Write-MessageWithLogging -message "Checking for native VLAN ID 1, if you have a different native VLAN ID, please change the value of the variable nativeVLANID in the script." -color Yellow
# Check the vSwitches for port groups with the same VLAN ID as the native VLAN
foreach ($vSwitch in $vSwitches) {
if ($vSwitch.VlanID -eq $defaultNativeVLAN) {
Write-MessageWithLogging -message "- Check Failed" -color Red
Write-MessageWithLogging -message " $($vSwitch.virtualSwitch) - $($vSwitch.Name) - VLAN $($vSwitch.VlanID)" -color Red
$failed++
}
Else {
Write-MessageWithLogging -message "- Check Passed" -color Green
Write-MessageWithLogging -message " $($vSwitch.virtualSwitch) - $($vSwitch.Name) - VLAN $($vSwitch.VlanID)" -color Green
$passed++
}
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Get-SerialPort {
Param (
[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
$VM
)
Process {
Foreach ($VMachine in $VM) {
Foreach ($Device in $VMachine.ExtensionData.Config.Hardware.Device) {
If ($Device.gettype().Name -eq "VirtualSerialPort"){
$Details = New-Object PsObject
$Details | Add-Member Noteproperty VM -Value $VMachine
$Details | Add-Member Noteproperty Name -Value $Device.DeviceInfo.Label
If ($Device.Backing.FileName) { $Details | Add-Member Noteproperty Filename -Value $Device.Backing.FileName }
If ($Device.Backing.Datastore) { $Details | Add-Member Noteproperty Datastore -Value $Device.Backing.Datastore }
If ($Device.Backing.DeviceName) { $Details | Add-Member Noteproperty DeviceName -Value $Device.Backing.DeviceName }
$Details | Add-Member Noteproperty Connected -Value $Device.Connectable.Connected
$Details | Add-Member Noteproperty StartConnected -Value $Device.Connectable.StartConnected
$Details
}
}
}
}
}
function Get-ParallelPort {
Param (
[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
$VM
)
Process {
Foreach ($VMachine in $VM) {
Foreach ($Device in $VMachine.ExtensionData.Config.Hardware.Device) {
If ($Device.gettype().Name -eq "VirtualParallelPort"){
$Details = New-Object PsObject
$Details | Add-Member Noteproperty VM -Value $VMachine
$Details | Add-Member Noteproperty Name -Value $Device.DeviceInfo.Label
If ($Device.Backing.FileName) { $Details | Add-Member Noteproperty Filename -Value $Device.Backing.FileName }
If ($Device.Backing.Datastore) { $Details | Add-Member Noteproperty Datastore -Value $Device.Backing.Datastore }
If ($Device.Backing.DeviceName) { $Details | Add-Member Noteproperty DeviceName -Value $Device.Backing.DeviceName }
$Details | Add-Member Noteproperty Connected -Value $Device.Connectable.Connected
$Details | Add-Member Noteproperty StartConnected -Value $Device.Connectable.StartConnected
$Details
}
}
}
}
}
#endregion Common
#region AuditModules
#region InstallationAduit
# This module assesses against the following CIS controls:
# 1.1 Ensure ESXi is properly patched
# 1.2 Ensure the Image Profile VIB acceptance level is configured properly
# 1.3 Ensure no unauthorized kernel modules are loaded on the host
# 1.4 Ensure the default value of individual salt per vm is configured
function Ensure-ESXiIsProperlyPatched {
# CIS 1.1 Ensure ESXi is properly patched
Write-MessageWithLogging -message "`n* CIS control 1.1 Ensure ESXi is properly patched" -color Blue
# Read patches from a json file
$patches = Get-Content -Path $PSScriptRoot\vmware\patches.json | ConvertFrom-Json
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# Get ESXi patches from the host and compare them to the patches in the json file
Foreach ($VMHost in Get-VMHost) {
$EsxCli = Get-EsxCli -VMHost $VMHost -V2
# Get the name and version of the patch and store them in a hashtable
$esxPatches = $EsxCli.software.vib.list.invoke() | Select-Object @{Name = 'Name'; Expression = { $_.Name } }, @{Name = 'Version'; Expression = { $_.Version } }
# Compare the patches in the json file to the patches on the host
Foreach ($hostpatch in $esxPatches) {
Foreach ($patch in $patches) {
if ($hostpatch.Name -eq $patch.Name) {
if ($hostpatch.Version -ne $patch.Version) {
Write-MessageWithLogging -message "- $($hostpatch.Name): Fail" -color Red
Write-MessageWithLogging -message " Expected version: $($patch.Version)" -color Red
Write-MessageWithLogging -message " Actual version: $($hostpatch.Version)" -color Red
$failed++
break
}
else {
Write-MessageWithLogging -message "- $($hostpatch.Name): Pass" -color Green
$passed++
break
}
}
else {
if ($patch -eq $patches[-1]) {
Write-MessageWithLogging -message "- $($hostpatch.Name): Unknown" -color Yellow
Write-MessageWithLogging -message " Patch not found in the json file" -color Yellow
$unknown++
}
}
}
}
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-VIBAcceptanceLevelIsConfiguredProperly {
# CIS 1.2 Ensure the Image Profile VIB acceptance level is configured properly
Write-MessageWithLogging -message "`n* CIS control 1.2 Ensure the Image Profile VIB acceptance level is configured properly" -color Blue
$passed = 0
$failed = 0
$unknown = 0
# Get the Image Profile acceptance level for each VIB
Foreach ($VMHost in Get-VMHost) {
$EsxCli = Get-EsxCli -VMHost $VMHost -V2
$vibs = $EsxCli.software.vib.list.invoke() | Select-Object @{Name = 'Name'; Expression = { $_.Name } }, @{Name = 'AcceptanceLevel'; Expression = { $_.AcceptanceLevel } }
# Compare the acceptance level to the expected value
Foreach ($vib in $vibs) {
if ($vib.AcceptanceLevel -ne "CommunitySupported" -and $vib.AcceptanceLevel -ne "PartnerSupported" -and $vib.AcceptanceLevel -ne "VMwareCertified") {
Write-MessageWithLogging -message "- $($vib.Name): Fail" -color Red
Write-MessageWithLogging -message " Expected acceptance level: communitySupported" -color Red
Write-MessageWithLogging -message " Actual acceptance level: $($vib.AcceptanceLevel)" -color Red
$failed++
}
else {
Write-MessageWithLogging -message "- $($vib.Name): Pass" -color Green
Write-MessageWithLogging -message " Acceptance level: $($vib.AcceptanceLevel)" -color Green
$passed++
}
}
}
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-UnauthorizedModulesNotLoaded {
# CIS 1.3 Ensure no unauthorized kernel modules are loaded on the host
Write-MessageWithLogging -message "`n* CIS control 1.3 Ensure no unauthorized kernel modules are loaded on the host" -color Blue
# Get the list of loaded kernel modules and check if they are authorized
$passed = 0
$failed = 0
$unknown = 0
Foreach ($VMHost in Get-VMHost) {
$ESXCli = Get-EsxCli -VMHost $VMHost
$systemModules = $ESXCli.system.module.list() | Foreach {
$ESXCli.system.module.get($_.Name) | Select @{N = "VMHost"; E = { $VMHost } }, Module, License, Modulefile, Version, ContainingVIB, VIBAcceptanceLevel
}
# Check if the module corresponding VIB has an acceptance level is certified, exclude vmkernel module
Foreach ($module in $systemModules) {
if ($module.Module -ne "vmkernel") {
if ($module.VIBAcceptanceLevel -ne "certified") {
Write-MessageWithLogging -message "- $($module.Module): Fail" -color Red
Write-MessageWithLogging -message " Containing VIB: $($module.ContainingVIB)" -color Red
Write-MessageWithLogging -message " VIB acceptance level: $($module.VIBAcceptanceLevel)" -color Red
$failed++
}
else {
Write-MessageWithLogging -message "- $($module.Module): Pass" -color Green
Write-MessageWithLogging -message " Containing VIB: $($module.ContainingVIB)" -color Green
Write-MessageWithLogging -message " VIB acceptance level: $($module.VIBAcceptanceLevel)" -color Green
$passed++
}
}
}
}
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-DefaultSaultIsConfiguredProperly {
# CIS 1.4 Ensure the default value of individual salt per vm is configured
Write-MessageWithLogging -message "`n* CIS control 1.4 Ensure the default value of individual salt per vm is configured" -color Blue
$passed = 0
$failed = 0
$unknown = 0
# Get the default value of individual salt per vm using Get-AdvancedSetting
$expectedSaltValue = 2
$actualSaltValue = Get-VMHost | Get-AdvancedSetting -Name "Mem.ShareForceSalting" | Select-Object -ExpandProperty Value
# Compare the value to the expected value
if ($actualSaltValue -ne $expectedSaltValue) {
Write-MessageWithLogging -message "- Default value of individual salt per vm: Fail" -color Red
Write-MessageWithLogging -message " Expected value: $expectedSaltValue" -color Red
Write-MessageWithLogging -message " Actual value: $actualSaltValue" -color Red
$failed++
}
else {
Write-MessageWithLogging -message "- Default value of individual salt per vm: Pass" -color Green
Write-MessageWithLogging -message " Expected Value: $actualSaltValue" -color Green
Write-MessageWithLogging -message " Actual Value: $actualSaltValue" -color Green
$passed++
}
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
#endregion
#region AccessAudit
# This module assesses against the following CIS controls:
# 4.1 (L1) Ensure a non-root user account exists for local admin access
# 4.2 (L1) Ensure passwords are required to be complex
# 4.3 (L1) Ensure the maximum failed login attempts is set to 5
# 4.4 (L1) Ensure account lockout is set to 15 minutes
# 4.5 (L1) Ensure previous 5 passwords are prohibited
# 4.6 (L1) Ensure Active Directory is used for local user authentication
# 4.7 (L1) Ensure only authorized users and groups belong to the esxAdminsGroup group
# 4.8 (L1) Ensure the Exception Users list is properly configured
function Ensure-NonRootExistsForLocalAdmin {
# CIS 4.1 (L1) Ensure a non-root user account exists for local admin access
Write-MessageWithLogging -message "`n* CIS control 4.1 (L1) Ensure a non-root user account exists for local admin access" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# This control needs to be verified manually
Write-MessageWithLogging -message "- Check Unknown" -color Yellow
Write-MessageWithLogging -message " This control needs to be verified manually, refer to the CIS Benchmark for details" -color Yellow
$unknown = 1
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-PasswordsAreRequiredToBeComplex {
# CIS 4.2 (L1) Ensure passwords are required to be complex
Write-MessageWithLogging -message "`n* CIS control 4.2 (L1) Ensure passwords are required to be complex" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# This control needs to be verified manually
Write-MessageWithLogging -message "- Check Unknown" -color Yellow
Write-MessageWithLogging -message " This control needs to be verified manually, refer to the CIS Benchmark for details" -color Yellow
$unknown = 1
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-LoginAttemptsIsSetTo5 {
# CIS 4.3 (L1) Ensure the maximum failed login attempts is set to 5
Write-MessageWithLogging -message "`n* CIS control 4.3 (L1) Ensure the maximum failed login attempts is set to 5" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# Get the ESXi hosts
$VMHosts = Get-VMHost | Select Name, @{N="MaxFailedLogin";E={$_ | Get-AdvancedSetting -Name Security.AccountLockFailures | Select -ExpandProperty Value}}
Foreach ($VMHost in $VMHosts) {
if ($VMHost.MaxFailedLogin -eq 5) {
Write-MessageWithLogging -message "- $($VMHost.Name): Passed" -color Green
Write-MessageWithLogging -message " The maximum failed login attempts is set to 5. " -color Green
$passed++
}
else {
Write-MessageWithLogging -message "- $($VMHost.Name): Failed" -color Red
Write-MessageWithLogging -message " The maximum failed login attempts is not set to 5. " -color Red
$failed++
}
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-AccountLockoutIsSetTo15Minutes {
# CIS 4.4 (L1) Ensure account lockout is set to 15 minutes
Write-MessageWithLogging -message "`n* CIS control 4.4 (L1) Ensure account lockout is set to 15 minutes" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# Get the ESXi hosts
$VMHosts = Get-VMHost | Select Name, @{N="AccountLockoutDuration";E={$_ | Get-AdvancedSetting -Name Security.AccountUnlockTime | Select -ExpandProperty Value}}
Foreach ($VMHost in $VMHosts) {
if ($VMHost.AccountLockoutDuration -eq 900) {
Write-MessageWithLogging -message "- $($VMHost.Name): Passed" -color Green
Write-MessageWithLogging -message " The account lockout is set to 15 minutes. " -color Green
$passed++
}
else {
Write-MessageWithLogging -message "- $($VMHost.Name): Failed" -color Red
Write-MessageWithLogging -message " The account lockout is not set to 15 minutes. " -color Red
$failed++
}
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-Previous5PasswordsAreProhibited {
# CIS 4.5 (L1) Ensure previous 5 passwords are prohibited
Write-MessageWithLogging -message "`n* CIS control 4.5 (L1) Ensure previous 5 passwords are prohibited" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
$VMHosts = Get-VMHost | Select Name, @{N="PasswordHistory";E={$_ | Get-AdvancedSetting -Name Security.PasswordHistory | Select -ExpandProperty Value}}
Foreach ($VMHost in $VMHosts) {
if ($VMHost.PasswordHistory -eq 5) {
Write-MessageWithLogging -message "- $($VMHost.Name): Passed" -color Green
Write-MessageWithLogging -message " The previous 5 passwords are prohibited. " -color Green
$passed++
}
else {
Write-MessageWithLogging -message "- $($VMHost.Name): Failed" -color Red
Write-MessageWithLogging -message " The previous 5 passwords are not prohibited. " -color Red
$failed++
}
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-ADIsUsedForAuthentication {
# CIS 4.6 (L1) Ensure AD is used for authentication
Write-MessageWithLogging -message "`n* CIS control 4.6 (L1) Ensure AD is used for authentication" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
$VMHosts = Get-VMHost | Get-VMHostAuthentication | Select VmHost, Domain, DomainMembershipStatus
Foreach ($VMHost in $VMHosts) {
if ($VMHost.DomainMembershipStatus -ne $null) {
Write-MessageWithLogging -message "- $($VMHost.VmHost): Passed" -color Green
Write-MessageWithLogging -message " AD is used for authentication. " -color Green
$passed++
}
else {
Write-MessageWithLogging -message "- $($VMHost.VmHost): Failed" -color Red
Write-MessageWithLogging -message " AD is not used for authentication. " -color Red
$failed++
}
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-OnlyAuthorizedUsersBelongToEsxAdminsGroup {
# CIS 4.7 (L1) Ensure only authorized users belong to the ESX Admins group
Write-MessageWithLogging -message "`n* CIS control 4.7 (L1) Ensure only authorized users belong to the ESX Admins group" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# This control needs to be verified manually
Write-MessageWithLogging -message "- Check Unknown" -color Yellow
Write-MessageWithLogging -message " This control needs to be verified manually, refer to the CIS Benchmark for details" -color Yellow
$unknown = 1
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-ExceptionUsersIsConfiguredManually {
# CIS 4.8 (L1) Ensure exception users is configured manually
Write-MessageWithLogging -message "`n* CIS control 4.8 (L1) Ensure exception users is configured manually" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# This control needs to be verified manually
Write-MessageWithLogging -message "- Check Unknown" -color Yellow
Write-MessageWithLogging -message " This control needs to be verified manually, refer to the CIS Benchmark for details" -color Yellow
$unknown = 1
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
#endregion
#region CommunicationAudit
# This module assesses against the following CIS controls:
# 2.1 (L1) Ensure NTP time synchronization is configured properly
# 2.2 (L1) Ensure the ESXi host firewall is configured to restrict access to services running on the host
# 2.3 (L1) Ensure Managed Object Browser (MOB) is disabled
# 2.4 (L2) Ensure default self-signed certificate for ESXi communication is not used
# 2.5 (L1) Ensure SNMP is configured properly
# 2.6 (L1) Ensure dvfilter API is not configured if not used
# 2.7 (L1) Ensure expired and revoked SSL certificates are removed from the ESXi server
# 2.8 (L1) Ensure vSphere Authentication Proxy is used when adding hosts to Active Directory
# 2.9 (L2) Ensure VDS health check is disabled
function Ensure-NTPTimeSynchronizationIsConfiguredProperly {
# CIS 2.1 Ensure NTP time synchronization is configured properly
Write-MessageWithLogging -message "`n* CIS control 2.1 Ensure NTP time synchronization is configured properly" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# Get the NTP servers from the host
$VMHosts = Get-VMHost | Select Name, @{N="NTPSetting";E={$_ | Get-VMHostNtpServer}}
# Check if the NTP servers are configured properly
Foreach ($VMHost in $VMHosts) {
if ($VMHost.NTPSetting -eq $null) {
Write-MessageWithLogging -message "- $($VMHost.Name): Fail" -color Red
Write-MessageWithLogging -message " NTP servers are not configured" -color Red
$failed++
}
else {
Write-MessageWithLogging -message "- $($VMHost.Name): Pass" -color Green
Write-MessageWithLogging -message " NtpServers: $($VMHost.NTPSetting)" -color Green
$passed++
}
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-ESXiHostFirewallIsProperlyConfigured {
# CIS 2.2 Ensure the ESXi host firewall is configured to restrict access to services running on the host
Write-MessageWithLogging -message "`n* CIS control 2.2 Ensure the ESXi host firewall is configured to restrict access to services running on the host" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# Check if the firewall rules are configured properly
Foreach ($VMHost in Get-VMHost){
$FirewallExceptions = Get-VMHost $VMHost | Get-VMHostFirewallException
# Check if the firewall rules are configured properly
Foreach ($Rule in $FirewallExceptions) {
if ($Rule.Enabled -eq $true -and ($Rule.ExtensionData.AllowedHosts.AllIP) -eq $true) {
Write-MessageWithLogging -message "- $($VMHost.Name): Fail" -color Red
Write-MessageWithLogging -message " Rule $($Rule.Name) is enabled and allows all hosts" -color Red
$failed++
}
else {
Write-MessageWithLogging -message "- $($VMHost.Name): Pass" -color Green
Write-MessageWithLogging -message " Rule $($Rule.Name) is disabled or allows specific hosts" -color Green
$passed++
}
}
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-MOBIsDisabled {
# CIS 2.3 Ensure Managed Object Browser (MOB) is disabled
Write-MessageWithLogging -message "`n* CIS control 2.3 Ensure Managed Object Browser (MOB) is disabled" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# Get the MOB status from the host
$VMHosts = Get-VMHost | Select Name, @{N="MOBStatus";E={$_ | Get-AdvancedSetting -Name "Config.HostAgent.plugins.solo.enableMob"}}
# Check if the MOB is disabled
Foreach ($VMHost in $VMHosts) {
if ($VMHost.MOBStatus -eq $true) {
Write-MessageWithLogging -message "- $($VMHost.Name): Fail" -color Red
Write-MessageWithLogging -message " MOB is enabled" -color Red
$failed++
}
else {
Write-MessageWithLogging -message "- $($VMHost.Name): Pass" -color Green
Write-MessageWithLogging -message " MOB is disabled" -color Green
$passed++
}
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-DefaultSelfSignedCertificateIsNotUsed {
# CIS 2.4 (L2) Ensure default self-signed certificate for ESXi communication is not used
Write-MessageWithLogging -message "`n* CIS control 2.4 (L2) Ensure default self-signed certificate for ESXi communication is not used" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# This control needs to be verified manually
Write-MessageWithLogging -message "- Check Unknown" -color Yellow
Write-MessageWithLogging -message " This control needs to be verified manually, refer to the CIS Benchmark for details" -color Yellow
$unknown = 1
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-SNMPIsConfiguredProperly {
# CIS 2.5 Ensure SNMP is configured properly
Write-MessageWithLogging -message "`n* CIS control 2.5 Ensure SNMP is configured properly" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# Get the SNMP status from the host
$VMHostSnmp = Get-VMHostSnmp
# Check if any SNMP server is configured and notify the user that they need to invistigate the issue
if ($VMHostSnmp -ne $null) {
Write-MessageWithLogging -message "- SNMP: Unknown" -color Yellow
Write-MessageWithLogging -message " SNMP is enabled, please refer to the vSphere Monitoring and Performance guide, chapter 8 for steps to verify the parameters." -color Yellow
$unknown++
}
else {
Write-MessageWithLogging -message "- SNMP: Pass" -color Green
Write-MessageWithLogging -message " SNMP is not enabled" -color Green
$passed++
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
Write-MessageWithLogging -message "Failed: $failed" -color Red
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-dvfilterIsDisabled {
# CIS 2.6 Ensure dvfilter is disabled
Write-MessageWithLogging -message "`n* CIS control 2.6 Ensure dvfilter is disabled" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# Get the dvfilter status from the host
$VMHosts = Get-VMHost | Select Name, @{N="Net.DVFilterBindIpAddress";E={$_ | Get-AdvancedSetting Net.DVFilterBindIpAddress | Select -ExpandProperty Values}}
# Check if the dvfilter is disabled
Foreach ($VMHost in $VMHosts) {
if ($VMHost.Net.DVFilterBindIpAddress -eq $null) {
Write-MessageWithLogging -message "- $($VMHost.Name): Pass" -color Green
Write-MessageWithLogging -message " dvfilter is disabled" -color Green
$passed++
}
else {
Write-MessageWithLogging -message "- $($VMHost.Name): Fail" -color Red
Write-MessageWithLogging -message " dvfilter is enabled" -color Red
$failed++
}
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-DefaultExpiredOrRevokedCertificateIsNotUsed {
# CIS 2.7 (L1) Ensure expired and revoked SSL certificates are removed from the ESXi server
Write-MessageWithLogging -message "`n* CIS control 2.7 (L1) Ensure expired and revoked SSL certificates are removed from the ESXi server" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# This control needs to be verified manually
Write-MessageWithLogging -message "- Check Unknown" -color Yellow
Write-MessageWithLogging -message " This control needs to be verified manually, refer to the CIS Benchmark for details" -color Yellow
$unknown = 1
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-vSphereAuthenticationProxyIsUsedWithAD {
# CIS 2.8 (L1) Ensure vSphere Authentication Proxy is used with Active Directory
Write-MessageWithLogging -message "`n* CIS control 2.8 (L1) Ensure vSphere Authentication Proxy is used with Active Directory" -color Blue
# Results summary
$passed = 0
$failed = 0
$unknown = 0
# Check each host and their domain membership status
$VMHostsAuth = Get-VMHost | Get-VMHostAuthentication | Select VmHost, Domain, DomainMembershipStatus
# Check if the hosts are joined to a domain or not
Foreach ($VMHost in $VMHostsAuth) {
if ($VMHost.DomainMembershipStatus -eq $null) {
Write-MessageWithLogging -message "- $($VMHost.VmHost): Fail" -color Red
Write-MessageWithLogging -message " Host is not joined to a domain" -color Red
$failed++
}
else {
Write-MessageWithLogging -message "- $($VMHost.VmHost): Pass" -color Green
Write-MessageWithLogging -message " Host is joined to a domain" -color Green
$passed++
}
}
# Print the results
Write-MessageWithLogging -message "`n-- Summary --"
Write-MessageWithLogging -message "Passed: $passed" -color Green
Write-MessageWithLogging -message "Failed: $failed" -color Red
Write-MessageWithLogging -message "Unknown: $unknown" -color Yellow
# Return true if all checks passed
if ($failed -ne 0) {
return -1
}
elseif ($unknown -ne 0) {
return 0
}
else {
return 1
}
}
function Ensure-VDSHealthCheckIsDisabled {
# CIS 2.9 (L2) Ensure VDS Health Check is disabled
Write-MessageWithLogging -message "`n* CIS control 2.9 (L2) Ensure VDS Health Check is disabled" -color Blue