-
Notifications
You must be signed in to change notification settings - Fork 16
/
VMware_vSphere_6.7_STIG_Compliance_Report.ps1
6708 lines (6522 loc) · 312 KB
/
VMware_vSphere_6.7_STIG_Compliance_Report.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
<#
.SYNOPSIS
Generates HTML Report to audit compliance against the vSphere 6.7 Draft STIG.
.DESCRIPTION
-This does not remediate any controls.
-Not all controls can be checked programatically so this script does not cover those or policy type controls.
-Controls and be disabled by updating the Vulnerability ID to $false For example $V94569 = $false. These are all listed out at the top of the script.
.NOTES
File Name : VMware_vSphere_6.7_STIG_Compliance_Report.ps1
Author : Ryan Lakey
Version : 1.0
Tested against
-PowerCLI 11.3
-Powershell 5
-ESXi 6.7 U3+
.PARAMETER vcenter
Enter the vcenter fqdn or IP to connect to for auditing
.PARAMETER vccred
Generate and pass a powershell credential variable to this parameter. For example $cred = Get-Credential then do "-vccred $cred" when running the script
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string]$vcenter,
[Parameter(Mandatory=$true)]
[pscredential]$vccred,
[Parameter(Mandatory=$false,
HelpMessage="Must be the root account credentials at this time. For checking items that require direct access on the host.")]
[pscredential]$esxicred,
[Parameter(Mandatory=$false,
HelpMessage="Enter the Active Directory Admins group to use for administrative access to ESXi")]
[string]$esxAdminGroup="SG-ESXAdmins",
[Parameter(Mandatory=$false,
HelpMessage="Enter allowed IP ranges for the ESXi firewall in comma separated format. For Example `"192.168.0.0/16`",`"10.0.0.0/8`" ")]
[string[]]$allowedNetworks,
[Parameter(Mandatory=$false,
HelpMessage="Enter allowed IP addresses for the ESXi firewall in comma separated format. For Example `"192.168.0.1`",`"10.0.0.1`" ")]
[string[]]$allowedIPs,
[Parameter(Mandatory=$false,
HelpMessage="Enter the syslog server for the ESXi server(s). Example tcp://log.domain.local:514")]
[string]$syslogServer="tcp://log.domain.local:514",
[Parameter(Mandatory=$true,
HelpMessage="Enter NTP servers. For Example `"10.1.1.1`",`"10.1.1.2`" ")]
[string[]]$ntpServers,
[Parameter(Mandatory=$false,
HelpMessage="Specify the native VLAN Id configured on the ports going to the ESXi Hosts. If none is specified the default of 1 will be used.")]
[string]$nativeVLAN = "1"
)
#Get Current Date and Time
$date = Get-Date
#Report Name
$ReportName = "vSphere 6.7 DISA STIG (Draft) Compliance Report"
#Report Path - move to parameter later
$ReportOutputPath = "C:\PowerCLI\Output"
$ReportFile = $ReportOutputPath + "\VMware_vSphere_6.7_STIG_Compliance_Report" + "_" + $Date.Month + "-" + $Date.Day + "-" + $Date.Year + "_" + $Date.Hour + "-" + $Date.Minute + "-" + $Date.Second + ".html"
#HTML Report Options
##Tabs to generate for report
$tabarray = @('Overview','Virtual Machines','ESXi','vCenter')
#Logo Files
[String]$CompanyLogo = "https://www.vmware.com/content/dam/digitalmarketing/vmware/en/files/images/wmrc/VMware_logo_gry_RGB_72dpi.jpg"
[String]$RightLogo = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQm32Zwz84atzMO6bpguQkTLwCEIrOoPUpfrptbkCGMkiMiCtav"
#vSphere 6.7 STIG Settings Created this up here to make it easier to update settings and values in the future without digging for them down in the code
$stigsettings = @{
##### Environment Specific STIG Values #####
syslogHost = @{"Syslog.global.logHost" = $syslogServer}
stigVibRE = "dod-esxi65-stig-re" #Update with STIG VIB version used
stigVibRD = "dod-esxi65-stig-rd" #Update with STIG VIB version used
esxAdminsGroup = @{"Config.HostAgent.plugins.hostsvc.esxAdminsGroup" = $esxAdminGroup}
allowedNetworks = $allowedNetworks #@("10.0.0.0/8","192.168.0.0/16") #Allows IP ranges for the ESXi firewall. These should be in the same order as seen in the UI.
allowedIPs = $allowedIPs #@() #Allows IP addresses if any for the ESXi firewall. These should be in the same order as seen in the UI.
ntpServers = $ntpServers #@("10.1.1.1","10.1.1.2")
esxiLatestBuild = "14320388"
nativeVLANid = $nativeVLAN #"1"
adDomain = "corp.local"
certAuthName = "O=U.S. Government" #certificate authority issuer name For example "O=U.S. Government"
## ESXi
DCUIAccess = @{"DCUI.Access" = "root"}
vibacceptlevel = "PartnerSupported" #VIB Acceptance level CommunitySupported,PartnerSupported,VMwareAccepted,VMwareCertified
accountLockFailures = @{"Security.AccountLockFailures" = "3"}
accountUnlockTime = @{"Security.AccountUnlockTime" = "900"}
logLevel = @{"Config.HostAgent.log.level" = "info"}
enableMob = @{"Config.HostAgent.plugins.solo.enableMob" = $false}
shellIntTimeout = @{"UserVars.ESXiShellInteractiveTimeOut" = "120"}
shellTimeout = @{"UserVars.ESXiShellTimeOut" = "600"}
DCUITImeout = @{"UserVars.DcuiTimeOut" = "120"}
ShareForceSalting = @{"Mem.ShareForceSalting" = "2"}
BlockGuestBPDU = @{"Net.BlockGuestBPDU" = "1"}
DVFilterBindIpAddress = @{"Net.DVFilterBindIpAddress" = ""}
syslogScratch = @{"Syslog.global.logDir" = "[] /scratch/log"}
sslProtocols = @{"UserVars.ESXiVPsDisabledProtocols" = "sslv3,tlsv1,tlsv1.1"}
passHistory = @{"Security.PasswordHistory" = "5"}
passComplexity = @{"Security.PasswordQualityControl" = "similar=deny retry=3 min=disabled,disabled,disabled,disabled,15"}
banner = @{"Config.Etc.issue" = "You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized use only. By using this IS (which includes any device attached to this IS), you consent to the following conditions: -The USG routinely intercepts and monitors communications on this IS for purposes including, but not limited to, penetration testing, COMSEC monitoring, network operations and defense, personnel misconduct (PM), law enforcement (LE), and counterintelligence (CI) investigations. -At any time, the USG may inspect and seize data stored on this IS. -Communications using, or data stored on, this IS are not private, are subject to routine monitoring, interception, and search, and may be disclosed or used for any USG-authorized purpose. -This IS includes security measures (e.g., authentication and access controls) to protect USG interests--not for your personal benefit or privacy. -Notwithstanding the above, using this IS does not constitute consent to PM, LE or CI investigative searching or monitoring of the content of privileged communications, or work product, related to personal representation or services by attorneys, psychotherapists, or clergy, and their assistants. Such communications and work product are private and confidential. See User Agreement for details."}
## Virtual Machines
vmIsoCopyDisable = @{"isolation.tools.copy.disable" = $true}
vmIsoDndDisable = @{"isolation.tools.dnd.disable" = $true}
vmIsoPasteDisable = @{"isolation.tools.paste.disable" = $true}
vmIsoDiskShrink = @{"isolation.tools.diskShrink.disable" = $true}
vmIsoDiskWiper = @{"isolation.tools.diskWiper.disable" = $true}
vmIsoHgfsDisable = @{"isolation.tools.hgfsServerSet.disable" = $true}
vmRemoteMax = @{"RemoteDisplay.maxConnections" = 1}
vmRemoteVnc = @{"RemoteDisplay.vnc.enabled" = $false}
vmToolsInfoSize = @{"tools.setinfo.sizeLimit" = 1048576}
vmDevConnDisable = @{"isolation.device.connectable.disable" = $true}
vmEnableHostInfo = @{"tools.guestlib.enableHostInfo" = $false}
vmGuestLock = @{"tools.guest.desktop.autolock" = $true}
vmMks3D = @{"mks.enable3d" = $false}
## vCenter
vcLogLevel = @{"config.log.level" = "info"}
}
##### Enable or Disable specific STIG Remediations #####
#Virtual Machines
$V94563 = $true #isolation.tools.copy.disable
$V94565 = $true #isolation.tools.dnd.disable
#Removed from 6.7 $V94567 = $true #isolation.tools.setGUIOptions.enable
$V94569 = $true #isolation.tools.paste.disable
$V94571 = $true #isolation.tools.diskShrink.disable
$V94573 = $true #isolation.tools.diskWiper.disable
$V94575 = $true #Independent, non-persistent disks
$V94577 = $true #isolation.tools.hgfsServerSet.disable
#Removed from 6.7 $V94579 = $true #isolation.tools.ghi.autologon.disable
#Removed from 6.7 $V94581 = $true #isolation.tools.ghi.launchmenu.change
#Removed from 6.7 $V94583 = $true #isolation.tools.memSchedFakeSampleStats.disable
#Removed from 6.7 $V94585 = $true #isolation.tools.ghi.protocolhandler.info.disable
#Removed from 6.7 $V94593 = $true #isolation.ghi.host.shellAction.disable
#Removed from 6.7 $V94595 = $true #isolation.tools.ghi.trayicon.disable
#Removed from 6.7 $V94597 = $true #isolation.tools.unity.disable
#Removed from 6.7 $V94599 = $true #isolation.tools.unityInterlockOperation.disable
#Removed from 6.7 $V94601 = $true #isolation.tools.unity.push.update.disable
#Removed from 6.7 $V94603 = $true #isolation.tools.unity.taskbar.disable
#Removed from 6.7 $V94605 = $true #isolation.tools.unityActive.disable
#Removed from 6.7 $V94607 = $true #isolation.tools.unity.windowContents.disable
#Removed from 6.7 $V94609 = $true #isolation.tools.vmxDnDVersionGet.disable
#Removed from 6.7 $V94611 = $true #isolation.tools.guestDnDVersionSet.disable
$V94613 = $true #Unauthorized floppy devices
$V94615 = $true #Unauthorized CD/DVD devices
$V94617 = $true #Unauthorized parallel devices
$V94619 = $true #Unauthorized serial devices
$V94621 = $true #Unauthorized USB devices
$V94623 = $true #Console connection sharing
$V94625 = $true #Console access through the VNC protocol must be disabled
$V94627 = $true #tools.setinfo.sizeLimit
$V94629 = $true #isolation.device.connectable.disable
$V94631 = $true #tools.guestlib.enableHostInfo
$V94633 = $true #sched.mem.pshare.salt
$V94635 = $true #"ethernet*.filter*.name*"
$V94637 = $true #System administrators must use templates to deploy virtual machines whenever possible.
$V94639 = $true #Use of the virtual machine console must be minimized.
$V94641 = $true #tools.guest.desktop.autolock
$V94643 = $true #mks.enable3d
$V94645 = $true #vMotion Encryption
$V94647 = $true #Duplicates
$V94649 = $true #Duplicates
$V94651 = $true #Duplicates
#ESXi
$V93949 = $true #Lockdown Mode
$V93951 = $true #DCUI.Access List
$V93953 = $false #Lockdown Mode Exceptions
$V93955 = $true #Syslog
$V93957 = $true #Account Lock Failures
$V93959 = $true #Account Unlock Timeout
$V93961 = $true #Consent Banner Welcome
$V93963 = $true #Consent Banner /etc/issue
$V93965 = $true #SSH Banner
$V93967 = $true #SSH Ciphers aes128-ctr,aes192-ctr,aes256-ctr
$V93969 = $true #SSH Protocol 2
$V93971 = $true #SSH IgnoreRhosts yes
$V93973 = $true #SSH HostbasedAuthentication no
$V93975 = $true #SSH PermitRootLogin no
$V93977 = $true #SSH PermitEmptyPasswords no
$V93979 = $true #SSH PermitUserEnvironment no
$V93981 = $true #SSH MACs hmac-sha1,hmac-sha2-256,hmac-sha2-512
$V93983 = $true #SSH GSSAPIAuthentication no
$V93985 = $true #SSH KerberosAuthentication no
$V93987 = $true #SSH StrictModes yes
$V93989 = $true #SSH Compression no
$V93991 = $true #SSH GatewayPorts no
$V93993 = $true #SSH X11Forwarding no
$V93995 = $true #SSH AcceptEnv
$V93997 = $true #SSH PermitTunnel no
$V93999 = $true #SSH ClientAliveCountMax 3
$V94001 = $true #SSH ClientAliveInterval 200
$V94003 = $true #SSH MaxSessions 1
$V94005 = $false #Authorized Keys
$V94007 = $true #Log Level
$V94009 = $true #Password Complexity
$V94011 = $true #Password Reuse
$V94013 = $true #Password Hashes
$V94015 = $true #Mob
$V94017 = $true #SSH Running
$V94021 = $true #Active Directory
$V94023 = $true #Authentication Proxy
$V94025 = $true #AD Admin Group
$V94027 = $true #2FA
$V94029 = $true #Shell Interactive Timeout
$V94031 = $true #Shell Timeout
$V94033 = $true #DCUI Timeout
$V94035 = $true #Core Dumps
$V94037 = $true #Persistent Logs
$V94039 = $true #NTP
$V94041 = $false #Acceptance Level
$V94043 = $true #Isolate vMotion
$V94045 = $true #Protect Management
$V94047 = $true #Protect Storage traffic
#$V94049 = $true #VMK Separation #Removed from 6.7
$V94051 = $true #TCP/IP Stacks
$V94053 = $true #SNMP
$V94055 = $true #iSCSI CHAP
$V94057 = $true #Memory Salting
$V94059 = $true #Firewall Rules
$V94061 = $true #Default Firewall
$V94063 = $true #BPDU
$V94065 = $true #Forged Transmits
$V94067 = $true #MAC Changes
$V94069 = $true #Prom Mode
$V94071 = $true #dvFilter
$V94073 = $true #Native VLAN
$V94075 = $true #VLAN 4095
$V94077 = $true #Reserved VLANs
$V94079 = $true #DTP
$V94081 = $true #STP
$V94083 = $true #Required VLANs
$V94349 = $true #CIM Account
$V94477 = $true #Checksum
$V94479 = $true #Patch Level
#Removed from 6.7 $V94481 = $true #TLS 1.2 SFCB
$V94483 = $true #TLS 1.2 ipFilter vSAN
#Removed from 6.7 $V94485 = $true #TLS 1.2 authd
$V94487 = $true #Secureboot
$V94489 = $true #DoD Cert
#vCenter
$V94725 = $true #Permissions
$V94727 = $true #NIOC
$V94735 = $true #DVS Healthcheck
$V94737 = $true #Forged Transmits
$V94739 = $true #Mac Changes
$V94741 = $true #Promiscious Mode
$V94743 = $true #Netflow
$V94745 = $true #Port level settings
$V94747 = $true #native vlan
$V94749 = $true #trunk
$V94751 = $true #reserved vlans
$V94753 = $true #
$V94755 = $true #
$V94781 = $true #log level
#Modules needed to run script and load
$modules = @("VMware.PowerCLI","ReportHTML")
#Check for correct modules
Function checkModule ($m){
if (Get-Module | Where-Object {$_.Name -eq $m}) {
Write-ToConsole "...Module $m is already imported."
}
else{
Write-ToConsole "...Trying to import module $m"
Import-Module $m -Verbose
}
}
Function Test-WebServerSSL {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
[string]$URL,
[Parameter(Position = 1)]
[ValidateRange(1,65535)]
[int]$Port = 443,
[Parameter(Position = 2)]
[Net.WebProxy]$Proxy,
[Parameter(Position = 3)]
[int]$Timeout = 15000,
[switch]$UseUserContext
)
Add-Type @"
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
namespace PKI {
namespace Web {
public class WebSSL {
public Uri OriginalURi;
public Uri ReturnedURi;
public X509Certificate2 Certificate;
//public X500DistinguishedName Issuer;
//public X500DistinguishedName Subject;
public string Issuer;
public string Subject;
public string[] SubjectAlternativeNames;
public bool CertificateIsValid;
//public X509ChainStatus[] ErrorInformation;
public string[] ErrorInformation;
public HttpWebResponse Response;
}
}
}
"@
$ConnectString = "https://$url`:$port"
$WebRequest = [Net.WebRequest]::Create($ConnectString)
$WebRequest.Proxy = $Proxy
$WebRequest.Credentials = $null
$WebRequest.Timeout = $Timeout
$WebRequest.AllowAutoRedirect = $true
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
try {$Response = $WebRequest.GetResponse()}
catch {}
if ($WebRequest.ServicePoint.Certificate -ne $null) {
$Cert = [Security.Cryptography.X509Certificates.X509Certificate2]$WebRequest.ServicePoint.Certificate.Handle
try {$SAN = ($Cert.Extensions | Where-Object {$_.Oid.Value -eq "2.5.29.17"}).Format(0) -split ", "}
catch {$SAN = $null}
$chain = New-Object Security.Cryptography.X509Certificates.X509Chain -ArgumentList (!$UseUserContext)
[void]$chain.ChainPolicy.ApplicationPolicy.Add("1.3.6.1.5.5.7.3.1")
$Status = $chain.Build($Cert)
New-Object PKI.Web.WebSSL -Property @{
OriginalUri = $ConnectString;
ReturnedUri = $Response.ResponseUri;
Certificate = $WebRequest.ServicePoint.Certificate;
Issuer = $WebRequest.ServicePoint.Certificate.Issuer;
Subject = $WebRequest.ServicePoint.Certificate.Subject;
SubjectAlternativeNames = $SAN;
CertificateIsValid = $Status;
Response = $Response;
ErrorInformation = $chain.ChainStatus | ForEach-Object {$_.Status}
}
$chain.Reset()
[Net.ServicePointManager]::ServerCertificateValidationCallback = $null
} else {
Write-Error $Error[0]
}
}
Function Write-ToConsole ($Details){
$LogDate = Get-Date -Format T
Write-Host "$($LogDate) $Details"
}
Function Write-ToConsoleRed ($Details){
$LogDate = Get-Date -Format T
Write-Host "$($LogDate) $Details" -ForegroundColor Red
}
Function Write-ToConsoleGreen ($Details){
$LogDate = Get-Date -Format T
Write-Host "$($LogDate) $Details" -ForegroundColor Green
}
#Add type to trust all certificates during checks otherwise some items will fail
If(-not [System.Net.ServicePointManager].DeclaredProperties | Where {$_.name -eq "CertificatePolicy"}){
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
}
#Load Modules
Try
{
ForEach($module in $modules){
Write-ToConsole "...checking for $module"
checkModule $module
}
}
Catch
{
Write-Error "Failed to load modules"
Write-Error $_.Exception
Exit -1
}
#Test report path
Try
{
If(Test-Path -Path $ReportOutputPath){
Write-ToConsole "...Validated path for report at $ReportOutputPath"
}Else{
Write-ToConsole "...Report path $ReportOutputPath doesn't exist...attempting to create..."
New-Item -ItemType Directory -Path $ReportOutputPath -Force -ErrorAction Stop
}
}
Catch
{
Write-Error "Failed to validate or create specified report directory"
Write-Error $_.Exception
Exit -1
}
#Connect to vCenter
Try
{
Write-ToConsole "...Connecting to vCenter $vcenter"
Connect-VIServer -Server $vcenter -Credential $vccred -Protocol https -ErrorAction Stop
}
Catch
{
Write-Error "Failed to connect to $vcenter"
Write-Error $_.Exception
Exit -1
}
#Initiate Variables
$report = @()
#Gather vCenter, ESXi, and VM Info
Try
{
Write-ToConsole "...Gathering info on target hosts in $vcenter"
$vmhosts = Get-VMHost | Where {$_.version -match "^6.7*"} | Sort-Object -Property Name -ErrorAction Stop
$vmhostsv = $vmhosts | Get-View | Sort-Object -Property Name -ErrorAction Stop
Write-ToConsole "...Gathering info on target virtual machines in $vcenter"
$vms = Get-VM | Sort-Object -Property Name -ErrorAction Stop
$vmsv = $vms | Get-View | Sort-Object -Property Name -ErrorAction Stop
Write-ToConsole "...Gathering info on $vcenter"
$datastores = Get-Datastore | Sort-Object -Property Name -ErrorAction Stop
$clusters = Get-Cluster | Sort-Object -Property Name -ErrorAction Stop
$vdswitches = Get-VDSwitch | Sort-Object -Property Name -ErrorAction Stop
$dportgroups = Get-VDPortGroup | Where {$_.IsUplink -eq $false} | Sort-Object -Property Name -ErrorAction Stop
}
Catch
{
Write-Error "Failed to gather info on environment in $vcenter"
Write-Error $_.Exception
Write-ToConsole "...Disconnecting from vCenter Server $vcenter"
Disconnect-VIServer -Server $vcenter -Force -Confirm:$false
Exit -1
}
#Virtual Machine Processing
#Initialize array for all VM report data
$vmsarrayall = @()
## VMCH-65-000001
Try{
$VULID = "V-94563"
$STIGID = "VMCH-65-000001"
$Title = "Copy operations must be disabled on the virtual machine."
$Severity = "CAT III"
If($V94563){
$vmtitle01 = "Vulnerability ID:$VULID STIG ID:$STIGID Title: $Title"
$settingname = [string]$stigSettings.vmIsoCopyDisable.Keys
$settingvalue = [boolean]$stigSettings.vmIsoCopyDisable.Values
Write-ToConsole "...Checking STIG Control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
$vmsarray = @()
ForEach($vm in $vmsv){
Write-ToConsole "...Checking VM $($vm.Name) for $settingname"
If($vm.config.extraconfig.key -contains "$settingname"){
$currentvalue = $vm.config.extraconfig | where {$_.key -eq "$settingname"}
If($currentvalue.value -ne $settingvalue){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
Else{
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $true
})
}
}
If($vm.config.extraconfig.key -notcontains "$settingname"){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $settingname
"Value" = "Setting does not exist on VM"
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
}
$vmsarray01 = Set-TableRowColor -ArrayOfObjects $vmsarray -Red '$this.Compliant -eq $false' | Sort-Object -Property @{Expression = {$_.RowColor}; Ascending = $false},Name
$vmsarrayall += $vmsarray
}
Else{
Write-ToConsoleRed "...Skipping disabled control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
}
}
Catch{
Write-Error "Failed to check control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title on $($vm.name)"
Write-Error $_.Exception
Write-ToConsole "...Disconnecting from vCenter Server $vcenter"
Disconnect-VIServer -Server $vcenter -Force -Confirm:$false
Exit -1
}
## VMCH-65-000002
Try{
$VULID = "V-94565"
$STIGID = "VMCH-65-000002"
$Title = "Drag and drop operations must be disabled on the virtual machine."
$Severity = "CAT III"
If($V94565){
$vmtitle02 = "Vulnerability ID:$VULID STIG ID:$STIGID Title: $Title"
$settingname = [string]$stigSettings.vmIsoDndDisable.Keys
$settingvalue = [boolean]$stigSettings.vmIsoDndDisable.Values
Write-ToConsole "...Checking STIG Control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
$vmsarray = @()
ForEach($vm in $vmsv){
Write-ToConsole "...Checking VM $($vm.Name) for $settingname"
If($vm.config.extraconfig.key -contains "$settingname"){
$currentvalue = $vm.config.extraconfig | where {$_.key -eq "$settingname"}
If($currentvalue.value -ne $settingvalue){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
Else{
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $true
})
}
}
If($vm.config.extraconfig.key -notcontains "$settingname"){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $settingname
"Value" = "Setting does not exist on VM"
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
}
$vmsarray02 = Set-TableRowColor -ArrayOfObjects $vmsarray -Red '$this.Compliant -eq $false' | Sort-Object -Property @{Expression = {$_.RowColor}; Ascending = $false},Name
$vmsarrayall += $vmsarray
}
Else{
Write-ToConsoleRed "...Skipping disabled control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
}
}
Catch{
Write-Error "Failed to check control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title on $($vm.name)"
Write-Error $_.Exception
Write-ToConsole "...Disconnecting from vCenter Server $vcenter"
Disconnect-VIServer -Server $vcenter -Force -Confirm:$false
Exit -1
}
## VMCH-65-000004
Try{
$VULID = "V-94569"
$STIGID = "VMCH-65-000004"
$Title = "Paste operations must be disabled on the virtual machine."
$Severity = "CAT III"
If($V94569){
$vmtitle04 = "Vulnerability ID:$VULID STIG ID:$STIGID Title: $Title"
$settingname = [string]$stigSettings.vmIsoPasteDisable.Keys
$settingvalue = [boolean]$stigSettings.vmIsoPasteDisable.Values
Write-ToConsole "...Checking STIG Control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
$vmsarray = @()
ForEach($vm in $vmsv){
Write-ToConsole "...Checking VM $($vm.Name) for $settingname"
If($vm.config.extraconfig.key -contains "$settingname"){
$currentvalue = $vm.config.extraconfig | where {$_.key -eq "$settingname"}
If($currentvalue.value -ne $settingvalue){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
Else{
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $true
})
}
}
If($vm.config.extraconfig.key -notcontains "$settingname"){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $settingname
"Value" = "Setting does not exist on VM"
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
}
$vmsarray04 = Set-TableRowColor -ArrayOfObjects $vmsarray -Red '$this.Compliant -eq $false' | Sort-Object -Property @{Expression = {$_.RowColor}; Ascending = $false},Name
$vmsarrayall += $vmsarray
}
Else{
Write-ToConsoleRed "...Skipping disabled control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
}
}
Catch{
Write-Error "Failed to check control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title on $($vm.name)"
Write-Error $_.Exception
Write-ToConsole "...Disconnecting from vCenter Server $vcenter"
Disconnect-VIServer -Server $vcenter -Force -Confirm:$false
Exit -1
}
## VMCH-65-000005
Try{
$VULID = "V-94571"
$STIGID = "VMCH-65-000005"
$Title = "Virtual disk shrinking must be disabled on the virtual machine."
$Severity = "CAT II"
If($V94571){
$vmtitle05 = "Vulnerability ID:$VULID STIG ID:$STIGID Title: $Title"
$settingname = [string]$stigSettings.vmIsoDiskShrink.Keys
$settingvalue = [boolean]$stigSettings.vmIsoDiskShrink.Values
Write-ToConsole "...Checking STIG Control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
$vmsarray = @()
ForEach($vm in $vmsv){
Write-ToConsole "...Checking VM $($vm.Name) for $settingname"
If($vm.config.extraconfig.key -contains "$settingname"){
$currentvalue = $vm.config.extraconfig | where {$_.key -eq "$settingname"}
If($currentvalue.value -ne $settingvalue){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
Else{
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $true
})
}
}
If($vm.config.extraconfig.key -notcontains "$settingname"){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $settingname
"Value" = "Setting does not exist on VM"
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
}
$vmsarray05 = Set-TableRowColor -ArrayOfObjects $vmsarray -Red '$this.Compliant -eq $false' | Sort-Object -Property @{Expression = {$_.RowColor}; Ascending = $false},Name
$vmsarrayall += $vmsarray
}
Else{
Write-ToConsoleRed "...Skipping disabled control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
}
}
Catch{
Write-Error "Failed to check control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title on $($vm.name)"
Write-Error $_.Exception
Write-ToConsole "...Disconnecting from vCenter Server $vcenter"
Disconnect-VIServer -Server $vcenter -Force -Confirm:$false
Exit -1
}
## VMCH-65-000006
Try{
$VULID = "V-94573"
$STIGID = "VMCH-65-000006"
$Title = "Virtual disk erasure must be disabled on the virtual machine."
$Severity = "CAT II"
If($V94573){
$vmtitle06 = "Vulnerability ID:$VULID STIG ID:$STIGID Title: $Title"
$settingname = [string]$stigSettings.vmIsoDiskWiper.Keys
$settingvalue = [boolean]$stigSettings.vmIsoDiskWiper.Values
Write-ToConsole "...Checking STIG Control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
$vmsarray = @()
ForEach($vm in $vmsv){
Write-ToConsole "...Checking VM $($vm.Name) for $settingname"
If($vm.config.extraconfig.key -contains "$settingname"){
$currentvalue = $vm.config.extraconfig | where {$_.key -eq "$settingname"}
If($currentvalue.value -ne $settingvalue){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
Else{
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $true
})
}
}
If($vm.config.extraconfig.key -notcontains "$settingname"){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $settingname
"Value" = "Setting does not exist on VM"
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
}
$vmsarray06 = Set-TableRowColor -ArrayOfObjects $vmsarray -Red '$this.Compliant -eq $false' | Sort-Object -Property @{Expression = {$_.RowColor}; Ascending = $false},Name
$vmsarrayall += $vmsarray
}
Else{
Write-ToConsoleRed "...Skipping disabled control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
}
}
Catch{
Write-Error "Failed to check control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title on $($vm.name)"
Write-Error $_.Exception
Write-ToConsole "...Disconnecting from vCenter Server $vcenter"
Disconnect-VIServer -Server $vcenter -Force -Confirm:$false
Exit -1
}
## VMCH-65-000007
Try{
$VULID = "V-94575"
$STIGID = "VMCH-65-000007"
$Title = "Independent, non-persistent disks must be not be used on the virtual machine."
$Severity = "CAT II"
If($V94575){
$vmtitle07 = "Vulnerability ID:$VULID STIG ID:$STIGID Title: $Title"
Write-ToConsole "...Checking STIG Control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
$vmsarray = @()
ForEach($vm in $vms){
Write-ToConsole "...Checking VM $($vm.Name) for $title"
$vminddisks = $vm | Get-HardDisk | Where {$_.Persistence -eq "IndependentNonPersistent"}
If($vminddisks){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Found" = "VM has $($vminddisks.count) independent non-persistent disks"
"Expected" = "Indepenent non-persistent disks do not exist"
"Severity" = $Severity
"Compliant" = $false
})
}Else{
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Found" = "VM has $($vminddisks.count) independent non-persistent disks"
"Expected" = "Indepenent non-persistent disks do not exist"
"Severity" = $Severity
"Compliant" = $true
})
}
}
$vmsarray07 = Set-TableRowColor -ArrayOfObjects $vmsarray -Red '$this.Compliant -eq $false' | Sort-Object -Property @{Expression = {$_.RowColor}; Ascending = $false},Name
$vmsarrayall += $vmsarray
}
Else{
Write-ToConsoleRed "...Skipping disabled control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
}
}
Catch{
Write-Error "Failed to check control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title on $($vm.name)"
Write-Error $_.Exception
Write-ToConsole "...Disconnecting from vCenter Server $vcenter"
Disconnect-VIServer -Server $vcenter -Force -Confirm:$false
Exit -1
}
## VMCH-65-000008
Try{
$VULID = "V-94577"
$STIGID = "VMCH-65-000008"
$Title = "HGFS file transfers must be disabled on the virtual machine."
$Severity = "CAT II"
If($V94577){
$vmtitle08 = "Vulnerability ID:$VULID STIG ID:$STIGID Title: $Title"
$settingname = [string]$stigSettings.vmIsoHgfsDisable.Keys
$settingvalue = [boolean]$stigSettings.vmIsoHgfsDisable.Values
Write-ToConsole "...Checking STIG Control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
$vmsarray = @()
ForEach($vm in $vmsv){
Write-ToConsole "...Checking VM $($vm.Name) for $settingname"
If($vm.config.extraconfig.key -contains "$settingname"){
$currentvalue = $vm.config.extraconfig | where {$_.key -eq "$settingname"}
If($currentvalue.value -ne $settingvalue){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
Else{
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $currentvalue.key
"Value" = $currentvalue.value
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $true
})
}
}
If($vm.config.extraconfig.key -notcontains "$settingname"){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Setting" = $settingname
"Value" = "Setting does not exist on VM"
"Expected" = $settingvalue
"Severity" = $Severity
"Compliant" = $false
})
}
}
$vmsarray08 = Set-TableRowColor -ArrayOfObjects $vmsarray -Red '$this.Compliant -eq $false' | Sort-Object -Property @{Expression = {$_.RowColor}; Ascending = $false},Name
$vmsarrayall += $vmsarray
}
Else{
Write-ToConsoleRed "...Skipping disabled control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
}
}
Catch{
Write-Error "Failed to check control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title on $($vm.name)"
Write-Error $_.Exception
Write-ToConsole "...Disconnecting from vCenter Server $vcenter"
Disconnect-VIServer -Server $vcenter -Force -Confirm:$false
Exit -1
}
## VMCH-65-000028
Try{
$VULID = "V-94613"
$STIGID = "VMCH-65-000028"
$Title = "Unauthorized floppy devices must be disconnected on the virtual machine."
$Severity = "CAT II"
If($V94613){
$vmtitle28 = "Vulnerability ID:$VULID STIG ID:$STIGID Title: $Title"
Write-ToConsole "...Checking STIG Control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
$vmsarray = @()
ForEach($vm in $vms){
Write-ToConsole "...Checking VM $($vm.Name) for $title"
$vmfloppys = $vm | Get-FloppyDrive
If($vmfloppys){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Found" = "VM has $($vmfloppys.count) floppy drives"
"Expected" = "Floppy drives do not exist"
"Severity" = $Severity
"Compliant" = $false
})
}Else{
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Found" = "VM has $($vmfloppys.count) floppy drives"
"Expected" = "Floppy drives do not exist"
"Severity" = $Severity
"Compliant" = $true
})
}
}
$vmsarray28 = Set-TableRowColor -ArrayOfObjects $vmsarray -Red '$this.Compliant -eq $false' | Sort-Object -Property @{Expression = {$_.RowColor}; Ascending = $false},Name
$vmsarrayall += $vmsarray
}
Else{
Write-ToConsoleRed "...Skipping disabled control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
}
}
Catch{
Write-Error "Failed to check control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title on $($vm.name)"
Write-Error $_.Exception
Write-ToConsole "...Disconnecting from vCenter Server $vcenter"
Disconnect-VIServer -Server $vcenter -Force -Confirm:$false
Exit -1
}
## VMCH-65-000029
Try{
$VULID = "V-94615"
$STIGID = "VMCH-65-000029"
$Title = "Unauthorized CD/DVD devices must be disconnected on the virtual machine."
$Severity = "CAT III"
If($V94615){
$vmtitle29 = "Vulnerability ID:$VULID STIG ID:$STIGID Title: $Title"
Write-ToConsole "...Checking STIG Control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
$vmsarray = @()
ForEach($vm in $vms){
Write-ToConsole "...Checking VM $($vm.Name) for $title"
$vmcds = $vm | Get-CDDrive | Where {$_.extensiondata.connectable.connected -eq $true}
If($vmcds){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Found" = "VM has $($vmcds.count) CD/DVD drives connected"
"Expected" = "CD/DVD drives are not connected when not in use"
"Severity" = $Severity
"Compliant" = $false
})
}Else{
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Found" = "VM has $($vmcds.count) CD/DVD drives connected"
"Expected" = "CD/DVD drives are not connected when not in use"
"Severity" = $Severity
"Compliant" = $true
})
}
}
$vmsarray29 = Set-TableRowColor -ArrayOfObjects $vmsarray -Red '$this.Compliant -eq $false' | Sort-Object -Property @{Expression = {$_.RowColor}; Ascending = $false},Name
$vmsarrayall += $vmsarray
}
Else{
Write-ToConsoleRed "...Skipping disabled control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
}
}
Catch{
Write-Error "Failed to check control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title on $($vm.name)"
Write-Error $_.Exception
Write-ToConsole "...Disconnecting from vCenter Server $vcenter"
Disconnect-VIServer -Server $vcenter -Force -Confirm:$false
Exit -1
}
## VMCH-65-000030
Try{
$VULID = "V-94617"
$STIGID = "VMCH-65-000030"
$Title = "Unauthorized parallel devices must be disconnected on the virtual machine."
$Severity = "CAT II"
If($V94617){
$vmtitle30 = "Vulnerability ID:$VULID STIG ID:$STIGID Title: $Title"
Write-ToConsole "...Checking STIG Control with Vulnerability ID:$VULID STIG ID:$STIGID with Title: $Title"
$vmsarray = @()
ForEach($vm in $vms){
Write-ToConsole "...Checking VM $($vm.Name) for $title"
$vmparrallel = $vm.config.hardware.device.deviceinfo | Where {$_.Label -match "parallel"}
If($vmparrallel){
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Found" = "VM has $($vmparrallel.count) parrallel devices connected"
"Expected" = "Parrallel devices do not exist"
"Severity" = $Severity
"Compliant" = $false
})
}Else{
$vmsarray += New-Object PSObject -Property ([ordered]@{
"Name" = $vm.name
"Found" = "VM has $($vmparrallel.count) parrallel devices connected"
"Expected" = "Parrallel devices do not exist"
"Severity" = $Severity
"Compliant" = $true
})
}
}
$vmsarray30 = Set-TableRowColor -ArrayOfObjects $vmsarray -Red '$this.Compliant -eq $false' | Sort-Object -Property @{Expression = {$_.RowColor}; Ascending = $false},Name
$vmsarrayall += $vmsarray