-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
sos-optimize-windows.ps1
3040 lines (2777 loc) · 243 KB
/
sos-optimize-windows.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
<#PSScriptInfo
.VERSION 4.0.2
.GUID 0805b351-a70d-4688-83d1-f8b8827e8ce0
.AUTHOR SimeonOnSecurity
.COMPANYNAME SimeonOnSecurity
.COPYRIGHT '2020 - Present SimeonOnSecurity, All Rights Reserved'
.TAGS 'Windows', 'Optimization', 'Hardening', 'Debloat'
.LICENSEURI 'https://github.com/simeononsecurity/Windows-Optimize-Harden-Debloat/blob/master/LICENSE'
.PROJECTURI 'https://github.com/simeononsecurity/Windows-Optimize-Harden-Debloat'
.ICONURI 'https://simeononsecurity.com/img/transparentavatar.png"
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES 'Initial release.'
.PRIVATEDATA
#>
<#
.DESCRIPTION "Enhance the security and privacy of your Windows 10 and Windows 11 deployments with our fully optimized, hardened, and debloated script. Adhere to industry best practices and Department of Defense STIG/SRG requirements for optimal performance and security."
#>
param(
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Clear Existing GPOs: Clears Group Policy Objects settings.")]
[bool]$cleargpos = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Install Windows Updates: Installs updates to the system.")]
[bool]$installupdates = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Adobe Acrobat Reader/Pro DC: Implements the Adobe Acrobat Reader STIGs.")]
[bool]$adobe = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Firefox: Implements the FireFox STIG.")]
[bool]$firefox = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Google Chrome: Implements the Google Chrome STIG.")]
[bool]$chrome = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Internet Explorer 11: Implements the Internet Explorer 11 STIG.")]
[bool]$IE11 = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Microsoft Edge: Implements the Microsoft Chromium Edge STIG.")]
[bool]$edge = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Microsoft .Net Framework: Implements the Dot Net 4 STIG.")]
[bool]$dotnet = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Microsoft Office: Implements the Microsoft Office Related STIGs.")]
[bool]$office = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Microsoft Onedrive: Implements the Onedrive STIGs.")]
[bool]$onedrive = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Oracle JRE 8: Implements the Oracle Java JRE 8 STIG.")]
[bool]$java = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Windows 10/11: Implements the Windows Desktop STIGs.")]
[bool]$windows = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Windows Defender Antivirus: Implements the Windows Defender STIG.")]
[bool]$defender = $true,
[Parameter(Mandatory = $false, HelpMessage="STIGs: Windows Firewall: Implements the Windows Firewall STIG.")]
[bool]$firewall = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: General Mitigations: Implements General Best Practice Mitigations.")]
[bool]$mitigations = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Windows Defender Hardening: Implements and Hardens Windows Defender Beyond STIG Requirements.")]
[bool]$defenderhardening = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: PowerShell Hardening: Implements PowerShell Hardening and Logging.")]
[bool]$pshardening = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: SSl Hardening: Implements SSL Hardening.")]
[bool]$sslhardening = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: SMB Hardening: Hardens SMB Client and Server Settings.")]
[bool]$smbhardening = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Applocker Hardening: Installs and Configures Applocker (In Audit Only Mode).")]
[bool]$applockerhardening = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Harden Bitlocker Implementation.")]
[bool]$bitlockerhardening = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Remove Bloatware: Removes unnecessary programs and features from the system.")]
[bool]$removebloatware = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Disable Telemetry: Disables data collection and telemetry.")]
[bool]$disabletelemetry = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Privacy Configurations: Makes changes to improve privacy.")]
[bool]$privacy = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Image Cleanup: Cleans up unneeded files from the system")]
[bool]$imagecleanup = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Nessus PID 63155: Resolves Unquoted System Strings in Path")]
[bool]$nessusPID = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Sysmon Configurations: Installs and configures sysmon to improve auditing capabilities.")]
[bool]$sysmon = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Enable Disk Compression: Compresses the system disk.")]
[bool]$diskcompression = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: EMET: Implements STIG Requirements and Hardening for EMET on Windows 7 Systems.")]
[bool]$emet = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Update Optimizations: Changes the way updates are managed and improved on the system.")]
[bool]$updatemanagement = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Enable Device Guard: Enables Device Guard Hardening.")]
[bool]$deviceguard = $true,
[Parameter(Mandatory = $false, HelpMessage="SoS Configurations: Browser Configurations: Optimizes the system's web browsers.")]
[bool]$sosbrowsers = $true
)
######SCRIPT FOR FULL INSTALL AND CONFIGURE ON STANDALONE MACHINE#####
#Continue on error
$ErrorActionPreference = 'silentlycontinue'
#Require elivation for script run
#Requires -RunAsAdministrator
#Set Directory to PSScriptRoot
if ((Get-Location).Path -NE $PSScriptRoot) { Set-Location $PSScriptRoot }
$paramscheck = $cleargpos, $installupdates, $adobe, $firefox, $chrome, $IE11, $edge, $dotnet, $office, $onedrive, $java, $windows, $defender, $firewall, $mitigations, $defenderhardening, $pshardening, $sslhardening, $smbhardening, $applockerhardening, $bitlockerhardening, $removebloatware, $disabletelemetry, $privacy, $imagecleanup, $nessusPID, $sysmon, $diskcompression, $emet, $updatemanagement, $deviceguard, $sosbrowsers
# run a warning if no options are set to true
if ($paramscheck | Where-Object { $_ -eq $false } | Select-Object -Count -EQ $params.Count) {
Write-Error "No Options Were Selected. Exiting..."
Exit
}
# if any parameters are set to true take a restore point
$date = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$scriptName = $MyInvocation.MyCommand.Name
if ($paramscheck | Where-Object { $_ } | Select-Object) {
$freespace = (Get-WmiObject -class Win32_LogicalDisk | Where-Object { $_.DeviceID -eq 'C:' }).FreeSpace
$minfreespace = 10000000000 #10GB
if ($freespace -gt $minfreespace) {
Write-Host "Taking a Restore Point Before Continuing...."
$job = Start-Job -Name "Take Restore Point" -ScriptBlock {
New-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\SystemRestore' -Name 'SystemRestorePointCreationFrequency' -PropertyType DWORD -Value 0 -Force
Checkpoint-Computer -Description "RestorePoint $scriptName $date" -RestorePointType "MODIFY_SETTINGS"
}
Wait-Job -Job $job
}
else {
Write-Output "Not enough disk space to create a restore point. Current free space: $(($freespace/1GB)) GB"
}
}
# Install Local Group Policy if Not Already Installed
if ($paramscheck | Where-Object { $_ } | Select-Object) {
Start-Job -Name InstallGPOPackages -ScriptBlock {
foreach ($F in (Get-ChildItem "$env:SystemRoot\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~*.mum").FullName) {
if ((dism /online /get-packages | where-object { $_.name -like "*Microsoft-Windows-GroupPolicy-ClientTools*" }).count -eq 0) {
dism /Online /NoRestart /Add-Package:$F
}
}
foreach ($F in (Get-ChildItem "$env:SystemRoot\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~*.mum").FullName) {
if ((dism /online /get-packages | where-object { $_.name -like "*Microsoft-Windows-GroupPolicy-ClientExtensions*" }).count -eq 0) {
dism /Online /NoRestart /Add-Package:$F
}
}
}
}
#GPO Configurations
function Import-GPOs([string]$gposdir) {
Write-Host "Importing Group Policies from $gposdir ..." -ForegroundColor Green
Foreach ($gpoitem in Get-ChildItem $gposdir) {
Write-Host "Importing $gpoitem GPOs..." -ForegroundColor White
$gpopath = "$gposdir\$gpoitem"
#Write-Host "Importing $gpo" -ForegroundColor White
.\Files\LGPO\LGPO.exe /g $gpopath > $null 2>&1
#Write-Host "Done" -ForegroundColor Green
}
}
if ($cleargpos -eq $true) {
Write-Host "Removing Existing Local GPOs" -ForegroundColor Green
#Remove and Refresh Local Policies
Remove-Item -Recurse -Force "$env:WinDir\System32\GroupPolicy" | Out-Null
Remove-Item -Recurse -Force "$env:WinDir\System32\GroupPolicyUsers" | Out-Null
secedit /configure /cfg "$env:WinDir\inf\defltbase.inf" /db defltbase.sdb /verbose | Out-Null
gpupdate /force | Out-Null
}
else {
Write-Output "The Clear Existing GPOs Section Was Skipped..."
}
if ($installupdates -eq $true) {
Write-Host "Installing the Latest Windows Updates" -ForegroundColor Green
#Install PowerShell Modules
Copy-Item -Path .\Files\"PowerShell Modules"\* -Destination C:\Windows\System32\WindowsPowerShell\v1.0\Modules -Force -Recurse
#Unblock New PowerShell Modules
Get-ChildItem C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate\ -recurse | Unblock-File
#Install PSWindowsUpdate
Import-Module -Name PSWindowsUpdate -Force -Global
#Install Latest Windows Updates
Start-Job -Name "Windows Updates" -ScriptBlock {
Install-WindowsUpdate -MicrosoftUpdate -AcceptAll; Get-WuInstall -AcceptAll -IgnoreReboot; Get-WuInstall -AcceptAll -Install -IgnoreReboot
}
}
else {
Write-Output "The Install Update Section Was Skipped..."
}
if ($adobe -eq $true) {
Write-Host "Implementing the Adobe STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\DoD\Adobe"
Start-Job -Name "Adobe Reader DC STIG" -ScriptBlock {
#Adobe Reader DC STIG
New-Item -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\" -Name cCloud -Force
New-Item -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\" -Name cDefaultLaunchURLPerms -Force
New-Item -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\" -Name cServices -Force
New-Item -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\" -Name cSharePoint -Force
New-Item -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\" -Name cWebmailProfiles -Force
New-Item -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\" -Name cWelcomeScreen -Force
Set-ItemProperty -Path "HKLM:\Software\Adobe\Acrobat Reader\DC\Installer" -Name DisableMaintenance -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown" -Name bAcroSuppressUpsell -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown" -Name bDisablePDFHandlerSwitching -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown" -Name bDisableTrustedFolders -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown" -Name bDisableTrustedSites -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown" -Name bEnableFlash -Type "DWORD" -Value 0 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown" -Name bEnhancedSecurityInBrowser -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown" -Name bEnhancedSecurityStandalone -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown" -Name bProtectedMode -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown" -Name iFileAttachmentPerms -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown" -Name iProtectedView -Type "DWORD" -Value 2 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\cCloud" -Name bAdobeSendPluginToggle -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\cDefaultLaunchURLPerms" -Name iURLPerms -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\cDefaultLaunchURLPerms" -Name iUnknownURLPerms -Type "DWORD" -Value 3 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\cServices" -Name bToggleAdobeDocumentServices -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\cServices" -Name bToggleAdobeSign -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\cServices" -Name bTogglePrefsSync -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\cServices" -Name bToggleWebConnectors -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\cServices" -Name bUpdater -Type "DWORD" -Value 0 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\cSharePoint" -Name bDisableSharePointFeatures -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\cWebmailProfiles" -Name bDisableWebmail -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown\cWelcomeScreen" -Name bShowWelcomeScreen -Type "DWORD" -Value 0 -Force
Set-ItemProperty -Path "HKLM:\Software\Wow6432Node\Adobe\Acrobat Reader\DC\Installer" -Name DisableMaintenance -Type "DWORD" -Value 1 -Force
}
}
else {
Write-Output "The Adobe Section Was Skipped..."
}
if ($firefox -eq $true) {
Write-Host "Implementing the FireFox STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\DoD\FireFox"
Import-GPOs -gposdir ".\Files\GPOs\SoS\FireFox"
Write-Host "simeononsecurity/FireFox-STIG-Script" -ForegroundColor Green
Write-Host "https://github.com/simeononsecurity/FireFox-STIG-Script" -ForegroundColor Green
#https://www.itsupportguides.com/knowledge-base/tech-tips-tricks/how-to-customise-firefox-installs-using-mozilla-cfg/
$firefox64 = "C:\Program Files\Mozilla Firefox"
$firefox32 = "C:\Program Files (x86)\Mozilla Firefox"
Write-Host "Installing Firefox Configurations - Please Wait." -ForegroundColor White
Write-Host "Window will close after install is complete" -ForegroundColor White
If (Test-Path -Path $firefox64) {
Copy-Item -Path .\Files\"FireFox Configuration Files"\defaults -Destination $firefox64 -Force -Recurse
Copy-Item -Path .\Files\"FireFox Configuration Files"\mozilla.cfg -Destination $firefox64 -Force
Copy-Item -Path .\Files\"FireFox Configuration Files"\local-settings.js -Destination $firefox64 -Force
Write-Host "Firefox 64-Bit Configurations Installed" -ForegroundColor Green
}
Else {
Write-Host "FireFox 64-Bit Is Not Installed" -ForegroundColor Red
}
If (Test-Path -Path $firefox32) {
Copy-Item -Path .\Files\"FireFox Configuration Files"\defaults -Destination $firefox32 -Force -Recurse
Copy-Item -Path .\Files\"FireFox Configuration Files"\mozilla.cfg -Destination $firefox32 -Force
Copy-Item -Path .\Files\"FireFox Configuration Files"\local-settings.js -Destination $firefox32 -Force
Write-Host "Firefox 32-Bit Configurations Installed" -ForegroundColor Green
}
Else {
Write-Host "FireFox 32-Bit Is Not Installed" -ForegroundColor Red
}
}
else {
Write-Output "The FireFox Section Was Skipped..."
}
if ($chrome -eq $true) {
Write-Host "Implementing the Google Chrome STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\DoD\Chrome"
}
else {
Write-Output "The Google Chrome Section Was Skipped..."
}
if ($IE11 -eq $true) {
Write-Host "Implementing the Internet Explorer 11 STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\DoD\IE11"
}
else {
Write-Output "The Internet Explorer 11 Section Was Skipped..."
}
if ($edge -eq $true) {
Write-Host "Implementing the Microsoft Edge STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\DoD\Edge"
#InPrivate browsing in Microsoft Edge must be disabled.
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\MicrosoftEdge\Main" -Name "AllowInPrivate" -Type "DWORD" -Value 0 -Force
#Windows 10 must be configured to prevent Microsoft Edge browser data from being cleared on exit.
New-Item -Path "HKLM:\Software\Policies\Microsoft\MicrosoftEdge\" -Name "Privacy" -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\MicrosoftEdge\Privacy" -Name ClearBrowsingHistoryOnExit -Type "DWORD" -Value 0 -Force
}
else {
Write-Output "The Microsoft Edge Section Was Skipped..."
}
if ($dotnet -eq $true) {
Write-Host "Implementing the Dot Net Framework STIGs" -ForegroundColor Green
#SimeonOnSecurity - Microsoft .Net Framework 4 STIG Script
#https://github.com/simeononsecurity
#https://dl.dod.cyber.mil/wp-content/uploads/stigs/zip/U_MS_DotNet_Framework_4-0_V1R9_STIG.zip
#https://docs.microsoft.com/en-us/dotnet/framework/tools/caspol-exe-code-access-security-policy-tool
Write-Host "Implementing simeononsecurity/.NET-STIG-Script" -ForegroundColor Green
Write-Host "https://github.com/simeononsecurity/.NET-STIG-Script" -ForegroundColor Green
#Setting Netframework path variables
$NetFramework32 = "C:\Windows\Microsoft.NET\Framework"
$NetFramework64 = "C:\Windows\Microsoft.NET\Framework64"
Write-Host "Beginning .NET STIG Script" -ForegroundColor Green
#Vul ID: V-7055 Rule ID: SV-7438r3_rule STIG ID: APPNET0031
#Removing registry value
If (Test-Path -Path "HKLM:\Software\Microsoft\StrongName\Verification") {
Remove-Item "HKLM:\Software\Microsoft\StrongName\Verification" -Recurse -Force
Write-Host ".Net StrongName Verification Registry Removed"
}
Else {
Write-Host ".Net StrongName Verification Registry Does Not Exist" -ForegroundColor Green
}
#Vul ID: V-7061 Rule ID: SV-7444r3_rule STIG ID: APPNET0046
#The Trust Providers Software Publishing State must be set to 0x23C00.
New-PSDrive HKU Registry HKEY_USERS | Out-Null
ForEach ($UserSID in (Get-ChildItem "HKU:\")) {
Write-Output $UserSID.Name | ConvertFrom-String -Delimiter "\\" -PropertyNames "PATH", "SID" | Set-Variable -Name "SIDs"
ForEach ($SID in $SIDs.SID) {
#Vul ID: V-30935 Rule ID: SV-40977r3_rule STIG ID: APPNET0063
If (Test-Path -Path "HKU:\$SID\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing\State") {
Set-ItemProperty -Path "HKU:\$SID\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing\" -Name "State" -Value "0x23C00" -Force | Out-Null
Write-Host "Set Trust Providers Software Publishing State to 146432/0x23C00 for SID $SID" -ForegroundColor White
}
Else {
New-Item -Path "HKU:\$SID\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing\" -Name "State" -Force | Out-Null
New-ItemProperty -Path "HKU:\$SID\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing\" -Name "State" -Value "0x23C00" -Force | Out-Null
Write-Host "Set Trust Providers Software Publishing State to 146432/0x23C00 for SID $SID" -ForegroundColor White
}
}
}
[gc]::collect()
<#
Creating secure configuration Function. It needs to be called in the
two foreach loops as it has to touch every config file in each
.net framework version folder
Function Set-SecureConfig {
param (
$VersionPath,
$SecureMachineConfigPath
)
#Declaration and error prevention
$SecureMachineConfig = $Null
$MachineConfig = $Null
[system.gc]::Collect()
#Getting Secure Machine.Configs
$SecureMachineConfig = [xml](Get-Content $SecureMachineConfigPath)
#Write-Host "Still using test path at $(Get-CurrentLine)"
#$MachineConfigPath = "C:\Users\hiden\Desktop\NET-STIG-Script-master\Files\secure.machine - Copy.config"
$MachineConfigPath = "$VersionPath"
$MachineConfig = [xml](Get-Content $MachineConfigPath)
#Ensureing file is closed
[IO.File]::OpenWrite((Resolve-Path $MachineConfigPath).Path).close()
#Apply Machine.conf Configurations
#Pulled XML assistance from https://stackoverflow.com/questions/9944885/powershell-xml-importnode-from-different-file
#Pulled more XML details from http://www.maxtblog.com/2012/11/add-from-one-xml-data-to-another-existing-xml-file/
Write-Host "Begining work on $MachineConfigPath..." -ForegroundColor White
# Do out. Automate each individual childnode for infinite nested. Currently only goes two deep
$SecureChildNodes = $SecureMachineConfig.configuration | Get-Member | Where-Object MemberType -match "^Property" | Select-Object -ExpandProperty Name
$MachineChildNodes = $MachineConfig.configuration | Get-Member | Where-Object MemberType -match "^Property" | Select-Object -ExpandProperty Name
#Checking if each secure node is present in the XML file
ForEach ($SecureChildNode in $SecureChildNodes) {
#If it is not present, easy day. Add it in.
If ($SecureChildNode -notin $MachineChildNodes) {
#Adding node from the secure.machine.config file and appending it to the XML file
$NewNode = $MachineConfig.ImportNode($SecureMachineConfig.configuration.$SecureChildNode, $true)
$MachineConfig.DocumentElement.AppendChild($NewNode) | Out-Null
#Saving changes to XML file
$MachineConfig.Save($MachineConfigPath)
}
Elseif ($MachineConfig.configuration.$SecureChildNode -eq "") {
#Turns out element sometimes is present but entirely empty. If that is the case we need to remove it
# and add what we want
$MachineConfig.configuration.ChildNodes | Where-Object name -eq $SecureChildNode | ForEach-Object { $MachineConfig.configuration.RemoveChild($_) } | Out-Null
$MachineConfig.Save($MachineConfigPath)
#Adding node from the secure.machine.config file and appending it to the XML file
$NewNode = $MachineConfig.ImportNode($SecureMachineConfig.configuration.$SecureChildNode, $true)
$MachineConfig.DocumentElement.AppendChild($NewNode) | Out-Null
#Saving changes to XML file
$MachineConfig.Save($MachineConfigPath)
}
Else {
#If it is present... we have to check if the node contains the elements we want.
#Going through each node in secure.machine.config for comparison
$SecureElements = $SecureMachineConfig.configuration.$SecureChildNode | Get-Member | Where-Object MemberType -Match "^Property" | Where-object Name -notmatch "#comment" | Select-Object -Expandproperty Name
#Pull the Machine.config node and childnode and get the data properties for comparison
$MachineElements = $MachineConfig.configuration.$SecureChildNode | Get-Member | Where-Object MemberType -Match "^Property" | Where-object Name -notmatch "#comment" | Select-Object -Expandproperty Name
#I feel like there has got to be a better way to do this as we're three loops deep
foreach ($SElement in $SecureElements) {
#Comparing Element pulled earlier against Machine Elements. If it's not present we will add it in
If ($SElement -notin $MachineElements) {
#Adding in element that is not present
If ($SecureMachineConfig.configuration.$SecureChildNode.$SElement -NE "") {
$NewNode = $MachineConfig.ImportNode($SecureMachineConfig.configuration.$SecureChildNode.$SElement, $true)
$MachineConfig.configuration.$SecureChildNode.AppendChild($NewNode) | Out-Null
#Saving changes to XML file
$MachineConfig.Save($MachineConfigPath)
}
Else {
#This is for when the value declared is empty.
$NewNode = $MachineConfig.CreateElement("$SElement")
$MachineConfig.configuration.$SecureChildNode.AppendChild($NewNode) | Out-Null
#Saving changes to XML file
$MachineConfig.Save($MachineConfigPath)
}
}
Else {
$OldNode = $MachineConfig.SelectSingleNode("//$SElement")
$MachineConfig.configuration.$SecureChildNode.RemoveChild($OldNode) | Out-Null
$MachineConfig.Save($MachineConfigPath)
If ($SecureMachineConfig.configuration.$SecureChildNode.$SElement -EQ "") {
$NewElement = $MachineConfig.CreateElement("$SElement")
$MachineConfig.configuration.$SecureChildNode.AppendChild($NewElement) | Out-Null
}
Else {
$NewNode = $MachineConfig.ImportNode($SecureMachineConfig.configuration.$SecureChildNode.$SElement, $true)
$MachineConfig.configuration.$SecureChildNode.AppendChild($NewNode) | Out-Null
}
#Saving changes to XML file
$MachineConfig.Save($MachineConfigPath)
}#End else
}#Foreach Element within SecureElements
}#Else end for an if statement checking if the desired childnode is in the parent file
}#End of iterating through SecureChildNodes
Write-Host "Merge Complete" -ForegroundColor White
}
#>
# .Net 32-Bit
ForEach ($DotNetVersion in (Get-ChildItem $netframework32 -Directory)) {
Write-Host ".Net 32-Bit $DotNetVersion Is Installed" -ForegroundColor Green
#Starting .net exe/API to pass configuration Arguments
If (Test-Path "$($DotNetVersion.FullName)\caspol.exe") {
Start-Process "$($DotNetVersion.FullName)\caspol.exe" -ArgumentList "-q -f -pp on" -WindowStyle Hidden
Start-Process "$($DotNetVersion.FullName)\caspol.exe" -ArgumentList "-m -lg" -WindowStyle Hidden
# Comment lines above and uncomment lines below to see output
#Start-Process "$($DotNetVersion.FullName)\caspol.exe" -ArgumentList "-q -f -pp on" -NoNewWindow
#Start-Process "$($DotNetVersion.FullName)\caspol.exe" -ArgumentList "-m -lg" -NoNewWindow
Write-Host "Set CAS policy for $DotNetVersion 32-Bit" -ForegroundColor White
}
#Vul ID: V-30935 Rule ID: SV-40977r3_rule STIG ID: APPNET0063
If (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework\AllowStrongNameBypass") {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework\" -Name "AllowStrongNameBypass" -Value "0" -Force | Out-Null
Write-Host "Disabled Strong Name Bypass for $DotNetVersion 32-Bit" -ForegroundColor White
}
Else {
New-Item -Path "HKLM:\SOFTWARE\Microsoft\" -Name ".NETFramework" -Force | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework\" -Name "AllowStrongNameBypass" -PropertyType "DWORD" -Value "0" -Force | Out-Null
Write-Host "Disabled Strong Name Bypass for $DotNetVersion 32-Bit" -ForegroundColor White
}
#Vul ID: V-81495 Rule ID: SV-96209r2_rule STIG ID: APPNET0075
If (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework\$DotNetVersion\SchUseStrongCrypto") {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework\$DotNetVersion\" -Name "SchUseStrongCrypto" -Value "1" -Force | Out-Null
Write-Host "Enforced Strong Crypto for $DotNetVersion 32-Bit" -ForegroundColor White
}
Else {
New-Item -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework" -Name "$DotNetVersion" -Force | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework\$DotNetVersion\" -Name "SchUseStrongCrypto" -PropertyType "DWORD" -Value "1" -Force | Out-Null
Write-Host "Enforced Strong Crypto for $DotNetVersion 32-Bit" -ForegroundColor White
}
<# Source for specifying configs for specific .Net versions
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/enforcefipspolicy-element (2.0 or higher)
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/loadfromremotesources-element (4.0 or higher)
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/netfx40-legacysecuritypolicy-element (4.0 or higher)
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/etwenable-element (Doesn't specify. Assuming 3.0 or higher because it mentions Vista)
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/network/defaultproxy-element-network-settings (Doesn't specify.)
#Ensuring .net version has machine.config
If (Test-Path "$($DotNetVersion.FullName)\Config\Machine.config") {
#.net Version testing.
If (($DotNetVersion -Split "v" )[1] -ge 2) {
#.net version testing.
If (($DotNetVersion -Split "v" )[1] -ge 4) {
Write-Host ".Net version 4 or higher... Continuing with v4.0+ Machine.conf Merge..." -ForegroundColor White
Set-SecureConfig -VersionPath "$($DotNetVersion.FullName)\Config\Machine.config" -SecureMachineConfigPath "$PSScriptRoot\Files\.Net Configuration Files\secure.machine-v4.config"
}
Else {
Write-Host ".Net version is less than 4... Continuing with v2.0+ Machine.conf Merge..." -ForegroundColor White
Set-SecureConfig -VersionPath "$($DotNetVersion.FullName)\Config\Machine.config" -SecureMachineConfigPath "$PSScriptRoot\Files\.Net Configuration Files\secure.machine-v2.config"
}
}
Else {
Write-Host ".Net version is less than 2... Skipping Machine.conf Merge..." -ForegroundColor Yellow
}#End dotnet version test
}
Else {
Write-Host "No Machine.Conf file exists for .Net version $DotNetVersion" -ForegroundColor Red
}#End testpath
#>
}
# .Net 64-Bit
ForEach ($DotNetVersion in (Get-ChildItem $netframework64 -Directory)) {
Write-Host ".Net 64-Bit $DotNetVersion Is Installed" -ForegroundColor Green
#Starting .net exe/API to pass configuration Arguments
If (Test-Path "$($DotNetVersion.FullName)\caspol.exe") {
Start-Process "$($DotNetVersion.FullName)\caspol.exe" -ArgumentList "-q -f -pp on" -WindowStyle Hidden
Start-Process "$($DotNetVersion.FullName)\caspol.exe" -ArgumentList "-m -lg" -WindowStyle Hidden
# Comment lines above and uncomment lines below to see output
#Start-Process "$($DotNetVersion.FullName)\caspol.exe" -ArgumentList "-q -f -pp on" -NoNewWindow
#Start-Process "$($DotNetVersion.FullName)\caspol.exe" -ArgumentList "-m -lg" -NoNewWindow
Write-Host "Set CAS policy for $DotNetVersion 64-Bit" -ForegroundColor White
}
#Vul ID: V-30935 Rule ID: SV-40977r3_rule STIG ID: APPNET0063
If (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework\AllowStrongNameBypass") {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework\" -Name "AllowStrongNameBypass" -Value "0" -Force | Out-Null
Write-Host "Disabled Strong Name Bypass for $DotNetVersion 64-Bit" -ForegroundColor White
}
Else {
New-Item -Path "HKLM:\SOFTWARE\Microsoft\" -Name ".NETFramework" -Force | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework\" -Name "AllowStrongNameBypass" -PropertyType "DWORD" -Value "0" -Force | Out-Null
Write-Host "Disabled Strong Name Bypass for $DotNetVersion 64-Bit" -ForegroundColor White
}
#Vul ID: V-81495 Rule ID: SV-96209r2_rule STIG ID: APPNET0075
If (Test-Path -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\$DotNetVersion\") {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\$DotNetVersion\" -Name "SchUseStrongCrypto" -Value "1" -Force | Out-Null
Write-Host "Enforced Strong Crypto for $DotNetVersion 64-Bit" -ForegroundColor White
}
Else {
New-Item -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\" -Name "$DotNetVersion" -Force | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\$DotNetVersion\" -Name "SchUseStrongCrypto" -PropertyType "DWORD" -Value "1" -Force | Out-Null
Write-Host "Enforced Strong Crypto for $DotNetVersion 64-Bit" -ForegroundColor White
}
<# Source for specifying configs for specific .Net versions
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/enforcefipspolicy-element (2.0 or higher)
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/loadfromremotesources-element (4.0 or higher)
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/netfx40-legacysecuritypolicy-element (4.0 or higher)
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/etwenable-element (Doesn't specify. Assuming 3.0 or higher because it mentions Vista)
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/network/defaultproxy-element-network-settings (Doesn't specify.)
#Ensuring current version has a machine.config to use
If (Test-Path "$($DotNetVersion.FullName)\Config\Machine.config") {
#version testing
If (($DotNetVersion -Split "v" )[1] -ge 2) {
#More version testing.
If (($DotNetVersion -Split "v" )[1] -ge 4) {
Write-Host ".Net version 4 or higher... Continuing with v4.0+ Machine.conf Merge..." -ForegroundColor White
Set-SecureConfig -VersionPath "$($DotNetVersion.FullName)\Config\Machine.config" -SecureMachineConfigPath "$PSScriptRoot\Files\.Net Configuration Files\secure.machine-v4.config"
}
Else {
Write-Host ".Net version is less than 4... Continuing with v2.0+ Machine.conf Merge..." -ForegroundColor White
Set-SecureConfig -VersionPath "$($DotNetVersion.FullName)\Config\Machine.config" -SecureMachineConfigPath "$PSScriptRoot\Files\.Net Configuration Files\secure.machine-v2.config"
}
}
Else {
Write-Host ".Net version is less than 2... Skipping Machine.conf Merge..." -ForegroundColor Yellow
}#End .net version test
}
Else {
Write-Host "No Machine.Conf file exists for .Net version $DotNetVersion" -ForegroundColor Red
}#End testpath
#>
}
}
else {
Write-Output "The Dot Net Framework Section Was Skipped..."
}
if ($office -eq $true) {
Write-Host "Implementing the Microsoft Office STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\DoD\Office"
}
else {
Write-Output "The Microsoft Office Section Was Skipped..."
}
if ($onedrive -eq $true) {
Write-Host "Implementing the Microsoft OneDrive STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\SoS\Onedrive"
}
else {
Write-Output "The OneDrive Section Was Skipped..."
}
if ($java -eq $true) {
Write-Host "Implementing the Oracle Java JRE 8 STIGs" -ForegroundColor Green
Write-Host "Implementing simeononsecurity/JAVA-STIG-Script" -ForegroundColor Green
Write-Host "https://github.com/simeononsecurity/JAVA-STIG-Script" -ForegroundColor Green
#https://gist.github.com/MyITGuy/9628895
#http://stu.cbu.edu/java/docs/technotes/guides/deploy/properties.html
#<Windows Directory>\Sun\Java\Deployment\deployment.config
#- or -
#<JRE Installation Directory>\lib\deployment.config
if (Test-Path -Path "C:\Windows\Sun\Java\Deployment\deployment.config") {
Write-Host "JAVA Deployment Config Already Installed" -ForegroundColor Green
}
else {
Write-Host "Installing JAVA Deployment Config...." -ForegroundColor Green
Mkdir "C:\Windows\Sun\Java\Deployment\"
Copy-Item -Path .\Files\"JAVA Configuration Files"\deployment.config -Destination "C:\Windows\Sun\Java\Deployment\" -Force
Write-Host "JAVA Configs Installed" -ForegroundColor White
}
if (Test-Path -Path "C:\Windows\Java\Deployment\") {
Write-Host "JAVA Configs Already Deployed" -ForegroundColor Green
}
else {
Write-Host "Installing JAVA Configurations...." -ForegroundColor Green
Mkdir "C:\Windows\Java\Deployment\"
Copy-Item -Path .\Files\"JAVA Configuration Files"\deployment.properties -Destination "C:\Windows\Java\Deployment\" -Force
Copy-Item -Path .\Files\"JAVA Configuration Files"\exception.sites -Destination "C:\Windows\Java\Deployment\" -Force
Write-Host "JAVA Configs Installed" -ForegroundColor White
}
}
else {
Write-Output "The Oracle Java JRE 8 Section Was Skipped..."
}
if ($windows -eq $true) {
Write-Host "Implementing the Windows 10/11 STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\DoD\Windows"
Write-Host "Implementing simeononsecurity/Windows-Audit-Policy" -ForegroundColor Green
Write-Host "https://github.com/simeononsecurity/Windows-Audit-Policy" -ForegroundColor Green
New-Item -Force -ItemType "Directory" "C:\temp"
Copy-Item $PSScriptRoot\files\auditing\auditbaseline.csv C:\temp\auditbaseline.csv
#Clear Audit Policy
auditpol /clear /y
#Enforce the Audit Policy Baseline
auditpol /restore /file:C:\temp\auditbaseline.csv
#Confirm Changes
auditpol /list /user /v
auditpol.exe /get /category:*
#Basic authentication for RSS feeds over HTTP must not be used.
New-Item -Path "HKLM:\Software\Policies\Microsoft\Internet Explorer" -Name "Feeds" -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Internet Explorer\Feeds" -Name "AllowBasicAuthInClear" -Type "DWORD" -Value 0 -Force
#Check for publishers certificate revocation must be enforced.
New-Item -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\" -Name "Software Publishing" -Force
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing" -Name State -Type "DWORD" -Value 146432 -Force
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\" -Name "Software Publishing" -Force
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing" -Name State -Type "DWORD" -Value 146432 -Force
#AutoComplete feature for forms must be disallowed.
New-Item -Path "HKLM:\Software\Policies\Microsoft\Internet Explorer\" -Name "Main Criteria" -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Internet Explorer\Main Criteria" -Name "Use FormSuggest" -Type "String" -Value no -Force
New-Item -Path "HKCU:\Software\Policies\Microsoft\Internet Explorer\" -Name "Main Criteria" -Force
Set-ItemProperty -Path "HKCU:\Software\Policies\Microsoft\Internet Explorer\Main Criteria" -Name "Use FormSuggest" -Type "String" -Value no -Force
#Turn on the auto-complete feature for user names and passwords on forms must be disabled.
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Internet Explorer\Main Criteria" -Name "FormSuggest PW Ask" -Type "String" -Value no -Force
Set-ItemProperty -Path "HKCU:\Software\Policies\Microsoft\Internet Explorer\Main Criteria" -Name "FormSuggest PW Ask" -Type "String" -Value no -Force
#Windows 10 must be configured to prioritize ECC Curves with longer key lengths first.
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Cryptography\Configuration\SSL\00010002" -Name "EccCurves" -Type "MultiString" -Value "NistP384 NistP256" -Force
#Zone information must be preserved when saving attachments.
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Attachments\" -Name "Main Criteria" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Attachments\" -Name "SaveZoneInformation" -Type "DWORD" -Value 2 -Force
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Attachments\" -Name "SaveZoneInformation" -Type "DWORD" -Value 2 -Force
#Toast notifications to the lock screen must be turned off.
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\" -Name "PushNotifications" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\PushNotifications\" -Name "NoToastApplicationNotificationOnLockScreen" -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\PushNotifications\" -Name "NoToastApplicationNotificationOnLockScreen" -Type "DWORD" -Value 1 -Force
#Windows 10 should be configured to prevent users from receiving suggestions for third-party or additional applications.
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows" -Name "CloudContent" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Name "DisableThirdPartySuggestions" -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Name "DisableThirdPartySuggestions" -Type "DWORD" -Value 1 -Force
#Windows 10 must be configured to prevent Windows apps from being activated by voice while the system is locked.
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows" -Name "AppPrivacy" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy\" -Name "LetAppsActivateWithVoice" -Type "DWORD" -Value 2 -Force
#The Windows Explorer Preview pane must be disabled for Windows 10.
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies" -Name "Explorer" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "NoReadingPane" -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "NoReadingPane" -Type "DWORD" -Value 1 -Force
#The use of a hardware security device with Windows Hello for Business must be enabled.
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft" -Name "PassportForWork" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\PassportForWork\" -Name "RequireSecurityDevice" -Type "DWORD" -Value 1 -Force
}
else {
Write-Output "The Windows Desktop Section Was Skipped..."
}
if ($defender -eq $true) {
Write-Host "Implementing the Windows Defender STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\DoD\Defender"
}
else {
Write-Output "The Windows Defender Section Was Skipped..."
}
if ($firewall -eq $true) {
Write-Host "Implementing the Windows Firewall STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\DoD\FireWall"
}
else {
Write-Output "The Windows Firewall Section Was Skipped..."
}
if ($mitigations -eq $true) {
Write-Host "Implementing the General Vulnerability Mitigations" -ForegroundColor Green
Start-Job -Name "Mitigations" -ScriptBlock {
#####SPECTURE MELTDOWN#####
#https://support.microsoft.com/en-us/help/4073119/protect-against-speculative-execution-side-channel-vulnerabilities-in
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" -Name FeatureSettingsOverride -Type "DWORD" -Value 72 -Force
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" -Name FeatureSettingsOverrideMask -Type "DWORD" -Value 3 -Force
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Virtualization" -Name MinVmVersionForCpuBasedMitigations -Type "String" -Value "1.0" -Force
#Disable LLMNR
#https://www.blackhillsinfosec.com/how-to-disable-llmnr-why-you-want-to/
New-Item -Path "HKLM:\Software\policies\Microsoft\Windows NT\" -Name "DNSClient" -Force
Set-ItemProperty -Path "HKLM:\Software\policies\Microsoft\Windows NT\DNSClient" -Name "EnableMulticast" -Type "DWORD" -Value 0 -Force
#Disable TCP Timestamps
netsh int tcp set global timestamps=disabled
#Enable DEP
BCDEDIT /set "{current}" nx OptOut
Set-Processmitigation -System -Enable DEP
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer" -Name "NoDataExecutionPrevention" -Type "DWORD" -Value 0 -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\System" -Name "DisableHHDEP" -Type "DWORD" -Value 0 -Force
#Enable SEHOP
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\kernel" -Name "DisableExceptionChainValidation" -Type "DWORD" -Value 0 -Force
#Disable NetBIOS by updating Registry
#http://blog.dbsnet.fr/disable-netbios-with-powershell#:~:text=Disabling%20NetBIOS%20over%20TCP%2FIP,connection%2C%20then%20set%20NetbiosOptions%20%3D%202
$key = "HKLM:SYSTEM\CurrentControlSet\services\NetBT\Parameters\Interfaces"
Get-ChildItem $key | ForEach-Object {
Write-Host("Modify $key\$($_.pschildname)")
$NetbiosOptions_Value = (Get-ItemProperty "$key\$($_.pschildname)").NetbiosOptions
Write-Host("NetbiosOptions updated value is $NetbiosOptions_Value")
}
#Disable WPAD
#https://adsecurity.org/?p=3299
New-Item -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\" -Name "Wpad" -Force
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Wpad" -Name "Wpad" -Force
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Wpad" -Name "WpadOverride" -Type "DWORD" -Value 1 -Force
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Wpad" -Name "WpadOverride" -Type "DWORD" -Value 1 -Force
#Enable LSA Protection/Auditing
#https://adsecurity.org/?p=3299
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\" -Name "LSASS.exe" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\LSASS.exe" -Name "AuditLevel" -Type "DWORD" -Value 8 -Force
#Disable Windows Script Host
#https://adsecurity.org/?p=3299
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows Script Host\" -Name "Settings" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Script Host\Settings" -Name "Enabled" -Type "DWORD" -Value 0 -Force
#Disable WDigest
#https://adsecurity.org/?p=3299
Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\SecurityProviders\Wdigest" -Name "UseLogonCredential" -Type "DWORD" -Value 0 -Force
#Block Untrusted Fonts
#https://adsecurity.org/?p=3299
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Kernel\" -Name "MitigationOptions" -Type "QWORD" -Value "1000000000000" -Force
#Disable Office OLE
#https://adsecurity.org/?p=3299
$officeversions = '16.0', '15.0', '14.0', '12.0'
ForEach ($officeversion in $officeversions) {
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Office\$officeversion\Outlook\" -Name "Security" -Force
New-Item -Path "HKCU:\SOFTWARE\Microsoft\Office\$officeversion\Outlook\" -Name "Security" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Office\$officeversion\Outlook\Security\" -Name "ShowOLEPackageObj" -Type "DWORD" -Value "0" -Force
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\$officeversion\Outlook\Security\" -Name "ShowOLEPackageObj" -Type "DWORD" -Value "0" -Force
}
#Disable Hibernate
powercfg -h off
}
}
else {
Write-Output "The General Mitigations Section Was Skipped..."
}
if ($defenderhardening -eq $true) {
Write-Host "Implementing Windows Defender Hardening Beyond STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\SoS\WDAC"
#Windows Defender Configuration Files
New-Item -Path "C:\" -Name "Temp" -ItemType "directory" -Force | Out-Null; New-Item -Path "C:\temp\" -Name "Windows Defender" -ItemType "directory" -Force | Out-Null; Copy-Item -Path .\Files\"Windows Defender Configuration Files"\* -Destination "C:\temp\Windows Defender\" -Force -Recurse -ErrorAction SilentlyContinue | Out-Null
Start-Job -Name "Windows Defender Hardening" -ScriptBlock {
#Enable Windows Defender Exploit Protection
Set-ProcessMitigation -PolicyFilePath "C:\temp\Windows Defender\DOD_EP_V3.xml"
#Enable Windows Defender Application Control
#https://docs.microsoft.com/en-us/windows/security/threat-protection/windows-defender-application-control/select-types-of-rules-to-create
Set-RuleOption -FilePath "C:\temp\Windows Defender\WDAC_V1_Recommended_Audit.xml" -Option 0
#Windows Defender Hardening
#https://www.powershellgallery.com/packages/WindowsDefender_InternalEvaluationSetting
#Enable real-time monitoring
Write-Host "Enable real-time monitoring"
Set-MpPreference -DisableRealtimeMonitoring 0
#Enable sample submission
Write-Host "Enable sample submission"
Set-MpPreference -SubmitSamplesConsent 2
#Enable checking signatures before scanning
Write-Host "Enable checking signatures before scanning"
Set-MpPreference -CheckForSignaturesBeforeRunningScan 1
#Enable behavior monitoring
Write-Host "Enable behavior monitoring"
Set-MpPreference -DisableBehaviorMonitoring 0
#Enable IOAV protection
Write-Host "Enable IOAV protection"
Set-MpPreference -DisableIOAVProtection 0
#Enable script scanning
Write-Host "Enable script scanning"
Set-MpPreference -DisableScriptScanning 0
#Enable removable drive scanning
Write-Host "Enable removable drive scanning"
Set-MpPreference -DisableRemovableDriveScanning 0
#Enable Block at first sight
Write-Host "Enable Block at first sight"
Set-MpPreference -DisableBlockAtFirstSeen 0
#Enable potentially unwanted
Write-Host "Enable potentially unwanted apps"
Set-MpPreference -PUAProtection Enabled
#Schedule signature updates every 8 hours
Write-Host "Schedule signature updates every 8 hours"
Set-MpPreference -SignatureUpdateInterval 8
#Enable archive scanning
Write-Host "Enable archive scanning"
Set-MpPreference -DisableArchiveScanning 0
#Enable email scanning
Write-Host "Enable email scanning"
Set-MpPreference -DisableEmailScanning 0
#Enable File Hash Computation
Write-Host "Enable File Hash Computation"
Set-MpPreference -EnableFileHashComputation 1
#Enable Intrusion Prevention System
Write-Host "Enable Intrusion Prevention System"
Set-MpPreference -DisableIntrusionPreventionSystem $false
#Enable Windows Defender Exploit Protection
Write-Host "Enabling Exploit Protection"
Set-ProcessMitigation -PolicyFilePath C:\temp\"Windows Defender"\DOD_EP_V3.xml
#Set cloud block level to 'High'
Write-Host "Set cloud block level to 'High'"
Set-MpPreference -CloudBlockLevel High
#Set cloud block timeout to 1 minute
Write-Host "Set cloud block timeout to 1 minute"
Set-MpPreference -CloudExtendedTimeout 50
Write-Host "`nUpdating Windows Defender Exploit Guard settings`n" -ForegroundColor Green
#Enabling Controlled Folder Access and setting to block mode
#Write-Host "Enabling Controlled Folder Access and setting to block mode"
#Set-MpPreference -EnableControlledFolderAccess Enabled
#Enabling Network Protection and setting to block mode
Write-Host "Enabling Network Protection and setting to block mode"
Set-MpPreference -EnableNetworkProtection Enabled
#Enable Cloud-delivered Protections
#Set-MpPreference -MAPSReporting Advanced
#Set-MpPreference -SubmitSamplesConsent SendAllSamples
#Enable Windows Defender Attack Surface Reduction Rules
#https://docs.microsoft.com/en-us/windows/security/threat-protection/microsoft-defender-atp/enable-attack-surface-reduction
#https://docs.microsoft.com/en-us/windows/security/threat-protection/microsoft-defender-atp/attack-surface-reduction
#Block executable content from email client and webmail
Add-MpPreference -AttackSurfaceReductionRules_Ids BE9BA2D9-53EA-4CDC-84E5-9B1EEEE46550 -AttackSurfaceReductionRules_Actions Enabled
#Block all Office applications from creating child processes
Add-MpPreference -AttackSurfaceReductionRules_Ids D4F940AB-401B-4EFC-AADC-AD5F3C50688A -AttackSurfaceReductionRules_Actions Enabled
#Block Office applications from creating executable content
Add-MpPreference -AttackSurfaceReductionRules_Ids 3B576869-A4EC-4529-8536-B80A7769E899 -AttackSurfaceReductionRules_Actions Enabled
#Block Office applications from injecting code into other processes
Add-MpPreference -AttackSurfaceReductionRules_Ids 75668C1F-73B5-4CF0-BB93-3ECF5CB7CC84 -AttackSurfaceReductionRules_Actions Enabled
#Block JavaScript or VBScript from launching downloaded executable content
Add-MpPreference -AttackSurfaceReductionRules_Ids D3E037E1-3EB8-44C8-A917-57927947596D -AttackSurfaceReductionRules_Actions Enabled
#Block execution of potentially obfuscated scripts
Add-MpPreference -AttackSurfaceReductionRules_Ids 5BEB7EFE-FD9A-4556-801D-275E5FFC04CC -AttackSurfaceReductionRules_Actions Enabled
#Block Win32 API calls from Office macros
Add-MpPreference -AttackSurfaceReductionRules_Ids 92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B -AttackSurfaceReductionRules_Actions Enabled
#Block executable files from running unless they meet a prevalence, age, or trusted list criterion
Add-MpPreference -AttackSurfaceReductionRules_Ids 01443614-cd74-433a-b99e-2ecdc07bfc25 -AttackSurfaceReductionRules_Actions AuditMode
#Use advanced protection against ransomware
Add-MpPreference -AttackSurfaceReductionRules_Ids c1db55ab-c21a-4637-bb3f-a12568109d35 -AttackSurfaceReductionRules_Actions Enabled
#Block credential stealing from the Windows local security authority subsystem
Add-MpPreference -AttackSurfaceReductionRules_Ids 9e6c4e1f-7d60-472f-ba1a-a39ef669e4b2 -AttackSurfaceReductionRules_Actions Enabled
#Block process creations originating from PSExec and WMI commands
Add-MpPreference -AttackSurfaceReductionRules_Ids d1e49aac-8f56-4280-b9ba-993a6d77406c -AttackSurfaceReductionRules_Actions AuditMode
#Block untrusted and unsigned processes that run from USB
Add-MpPreference -AttackSurfaceReductionRules_Ids b2b3f03d-6a65-4f7b-a9c7-1c7ef74a9ba4 -AttackSurfaceReductionRules_Actions Enabled
#Block Office communication application from creating child processes
Add-MpPreference -AttackSurfaceReductionRules_Ids 26190899-1602-49e8-8b27-eb1d0a1ce869 -AttackSurfaceReductionRules_Actions Enabled
#Block Adobe Reader from creating child processes
Add-MpPreference -AttackSurfaceReductionRules_Ids 7674ba52-37eb-4a4f-a9a1-f0f9a1619a2c -AttackSurfaceReductionRules_Actions Enabled
#Block persistence through WMI event subscription
Add-MpPreference -AttackSurfaceReductionRules_Ids e6db77e5-3df2-4cf1-b95a-636979351e5b -AttackSurfaceReductionRules_Actions Enabled
}
}
else {
Write-Output "The Windows Defender Hardening Section Was Skipped..."
}
if ($pshardening -eq $true) {
Write-Host "Implementing PowerShell Hardening Beyond STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\SoS\Powershell"
Start-Job -Name "PowerShell Hardening" -ScriptBlock {
#Disable Powershell v2
Disable-WindowsOptionalFeature -Online -FeatureName "MicrosoftWindowsPowerShellV2Root" -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName "MicrosoftWindowsPowerShellV2" -NoRestart
#Enable PowerShell Logging
#https://www.digitalshadows.com/blog-and-research/powershell-security-best-practices/
#https://www.cyber.gov.au/acsc/view-all-content/publications/securing-powershell-enterprise
New-Item -Path "HKLM:\Software\Policies\Microsoft\Windows\PowerShell\" -Name "Transcription" -Force
New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\PowerShell\Transcription" -Name "OutputDirectory" -Type "STRING" -Value "C:\PowershellLogs" -Force
New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging\" -Name "EnableScriptBlockLogging" -Type "DWORD" -Value "1" -Force
New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\PowerShell\Transcription\" -Name "EnableTranscripting" -Type "DWORD" -Value "1" -Force
New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\PowerShell\Transcription\" -Name "EnableInvocationHeader" -Type "DWORD" -Value "1" -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\PowerShell\Transcription" -Name "OutputDirectory" -Type "STRING" -Value "C:\PowershellLogs" -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging\" -Name "EnableScriptBlockLogging" -Type "DWORD" -Value "1" -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\PowerShell\Transcription\" -Name "EnableTranscripting" -Type "DWORD" -Value "1" -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\PowerShell\Transcription\" -Name "EnableInvocationHeader" -Type "DWORD" -Value "1" -Force
#Prevent WinRM from using Basic Authentication
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client" -Name "AllowBasic" -Type "DWORD" -Value 0 -Force
#WinRM Hardening
#https://4sysops.com/archives/powershell-remoting-over-https-with-a-self-signed-ssl-certificate/
#$Cert = New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName (cmd /c hostname)
#Export-Certificate -Cert $Cert -FilePath C:\temp\cert
#Remove Previous WinRM Listeners
#Get-ChildItem WSMan:\Localhost\listener | Where-Object -Property Keys -eq "Transport=HTTP" | Remove-Item -Recurse
#Remove-Item -Path WSMan:\Localhost\listener\listener* -Recurse
#Add New HTTPS (ONLY) Listener
#New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $Cert.Thumbprint –Force
#Start the service at boot
#Set-Service -Name "WinRM" -StartupType Automatic -Status Running
#Enable Firewall rule
#New-NetFirewallRule -DisplayName "Windows Remote Management (HTTPS-In)" -Name "Windows Remote Management (HTTPS-In)" -Profile Private, Domain -LocalPort 5986 -Protocol TCP
#Enable PSRemoting
#Enable-PSRemoting -SkipNetworkProfileCheck -Force
}
}
else {
Write-Output "The PowerShell Hardening Section Was Skipped..."
}
if ($applockerhardening -eq $true) {
Write-Host "Implementing Applocker Hardening Beyond STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\NSACyber\Applocker"
}
else {
Write-Output "The Applocker Hardening Section Was Skipped..."
}
if ($bitlockerhardening -eq $true) {
Write-Host "Implementing Bitlocker Hardening Beyond STIGs" -ForegroundColor Green
Import-GPOs -gposdir ".\Files\GPOs\NSACyber\Bitlocker"
}
else {
Write-Output "The Bitlocker Hardening Section Was Skipped..."
}
if ($sslhardening -eq $true) {
Write-Host "Implementing SSL Hardening Beyond STIGs" -ForegroundColor Green
Start-Job -Name "SSL Hardening" -ScriptBlock {
#Increase Diffie-Hellman key (DHK) exchange to 4096-bit
New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\KeyExchangeAlgorithms\Diffie-Hellman" -Force
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\KeyExchangeAlgorithms\Diffie-Hellman" -Force -Name ServerMinKeyBitLength -Type "DWORD" -Value 0x00001000
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\KeyExchangeAlgorithms\Diffie-Hellman" -Force -Name ClientMinKeyBitLength -Type "DWORD" -Value 0x00001000