-
Notifications
You must be signed in to change notification settings - Fork 15
/
Client-Checker.ps1
1889 lines (1665 loc) · 79.2 KB
/
Client-Checker.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
<#
This is such an awesome script - not
Better run twice, 1x as admin because some shit can not be queried without (e.g. BitLocker status) and 1x as low priv user to check things like software installable as low priv user or access to systemtools like registry etc.
Green = good
Red = Not good
Purple = possibly not good
Author: @LuemmelSec
License: BSD 3-Clause
#>
$results = @()
$elevated = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
function Client-Checker{
Write-host "##########################################################################################" -ForegroundColor DarkGray
Write-host "####################################################################+=####################" -ForegroundColor DarkGray
Write-host "#################################################################*######**################" -ForegroundColor DarkGray
Write-host "################################################################*=######++################" -ForegroundColor DarkGray
Write-host "####################################################################**####################" -ForegroundColor DarkGray
Write-host "###%%%%%%%%%%###########%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%###########+=####################" -ForegroundColor DarkGray
Write-host "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@#+======================#%###############################" -ForegroundColor DarkGray
Write-host "%%%**********%%%%%%%%%%%*******#" -ForegroundColor DarkRed -NoNewline; Write-Host "@::::::::::--::-=::::::::-@###############################" -ForegroundColor DarkGray
Write-host "+++++++++++++++++++++++++++++++*" -ForegroundColor Red -NoNewline; Write-Host "@::::=-::::::::=+=:::-:::-@%#%%###########################" -ForegroundColor DarkGray
Write-host "+++----------=++++++++++-------+" -ForegroundColor DarkYellow -NoNewline; Write-Host "@:::::::::::::+****=:-:::-@@%**%%#########################" -ForegroundColor DarkGray
Write-host "------------------------+++++--=" -ForegroundColor Yellow -NoNewline; Write-Host "@:::::::::--::%+===**=++++#====@@#########################" -ForegroundColor DarkGray
Write-host "----------------------=#*" -ForegroundColor Green -NoNewline; Write-Host "++*@##%@:::::--::::::%+=====+++++=====@@#########################" -ForegroundColor DarkGray
Write-host "----------------------+##" -ForegroundColor Blue -NoNewline; Write-Host "*****#%@:::-::::::-*@+===:=+======:-+==*@########################" -ForegroundColor DarkGray
Write-host "-------------------------++++@%%" -ForegroundColor DarkBlue -NoNewline; Write-Host "@:::-:::::::=@+===*%%-==*#-*%%-=*@########################" -ForegroundColor DarkGray
Write-host "-------------------------------+" -ForegroundColor Magenta -NoNewline; Write-Host "@::::-:::=-:=@+---=++-=++=-*+=--+@########################" -ForegroundColor DarkGray
Write-host "---==========-----------======#%" -ForegroundColor DarkMagenta -NoNewline; Write-Host "@::::-:::::::-#+=-=#@%%@@%%@#-=%%#########################" -ForegroundColor DarkGray
Write-host "++++++++++++++++++++++++++++#####@#++++++++++++%@*************@###########################" -ForegroundColor DarkGray
Write-host "+++##########*++++++++++####@+=+%%@%**%@%%%%%%%%@**%@%@#**@%##############################" -ForegroundColor DarkGray
Write-host "############################%%%%###%%%%%#########%%%%##%%%%###############################" -ForegroundColor DarkGray
Write-host "##########################################################################################" -ForegroundColor DarkGray
Write-host "##########################################################################################" -ForegroundColor DarkGray
Write-host "##################################### Client-Checker #####################################" -ForegroundColor DarkGray
Write-host "##################################### by @LuemmelSec #####################################" -ForegroundColor DarkGray
Write-host "############################ Automated Client Security Checks ############################" -ForegroundColor DarkGray
Write-host "##########################################################################################" -ForegroundColor DarkGray
Write-host ""
Write-Host "Stuff marked in green is good" -ForegroundColor Green
Write-Host "Stuff marked in magenta is a 'might be' finding" -ForegroundColor Magenta
Write-Host "Stuff marked in red is bad stuff" -ForegroundColor Red
Write-Host "Stuff marked yellow are errors" -ForegroundColor Yellow
Write-Host ""
Write-Host "If you happen to use PwnDoc or PwnDoc-ng, you can use my templates alongside this tool:"
Write-Host "https://github.com/LuemmelSec/PwnDoc-Vulns/blob/main/SystemSecurity.yml"
Write-Host ""
########### Preflight Checks ###########
# Check if we run in elevated context so all checks can be done
if($elevated -eq $true){
Write-Host "Local Admin: " -ForegroundColor white -NoNewline; Write-Host $elevated -ForegroundColor Green
Write-Host "We have superpowers. All checks should go okay." -ForegroundColor DarkGray
Write-Host ""
}
else{
Write-Host "Local Admin: " -ForegroundColor white -NoNewline; Write-Host $elevated -ForegroundColor Red
Write-Host "You don't have super powers. Some checks might fail!" -ForegroundColor DarkGray
Write-Host ""
}
# Check if all needed PS modules are installed that we need for the tests
# Array of module names to check
Write-Host "Checking for installed PowerShell modules..."
$moduleNames = @("ActiveDirectory", "BitLocker")
# Check if modules are installed
$missingModules = @()
$installedModules = @()
foreach ($moduleName in $moduleNames) {
if (Get-Module -ListAvailable -Name $moduleName) {
$installedModules += $moduleName
Write-Host "The '$moduleName' module is installed." -ForegroundColor Green
} else {
$missingModules += $moduleName
Write-Host "The '$moduleName' module is not installed." -ForegroundColor Red
}
}
# Prompt to install missing modules
if ($missingModules.Count -gt 0) {
$installModules = Read-Host "Do you want to install the missing modules? (Y/N)"
if ($installModules -eq "Y" -or $installModules -eq "y") {
foreach ($module in $missingModules) {
Write-Host "Installing module '$module'..."
Install-Module -Name $module -Scope CurrentUser
}
}
}
########### Beginning of the actual checks ###########
# Domain Password Policy checks
Write-Host ""
Write-Host "##############################################"
Write-Host "# Now checking Default Domain Password stuff #"
Write-Host "##############################################"
Write-Host "References: https://learn.microsoft.com/en-us/microsoft-365/admin/misc/password-policy-recommendations?view=o365-worldwide" -ForegroundColor DarkGray
Write-Host "References: https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/account-lockout-duration" -ForegroundColor DarkGray
Write-Host "References: https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/account-lockout-threshold" -ForegroundColor DarkGray
Write-Host "References: https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/store-passwords-using-reversible-encryption" -ForegroundColor DarkGray
Write-Host ""
try {
$defaultPolicy = Get-ADDefaultDomainPasswordPolicy
if ($defaultPolicy.ComplexityEnabled -eq $false){
Write-Host "Complexity Enabled: $false" -ForegroundColor Red
$pwpolicy_complexity = 2
}
else {
Write-Host "Complexity Enabled: $true" -ForegroundColor Green
$pwpolicy_complexity = 0
}
if ($defaultPolicy.lockoutduration.TotalMinutes -gt 14){
Write-Host "Lockout Duration: $($defaultPolicy.lockoutduration.TotalMinutes)" -ForegroundColor Green
$pwpolicy_lockoutduration = 0
}
elseif ($defaultPolicy.lockoutduration.TotalMinutes -eq 0) {
Write-Host "Lockout Duration: Will never lock" -ForegroundColor Red
$pwpolicy_lockoutduration = 2
}
else {
Write-Host "Lockout Duration: $($defaultPolicy.lockoutduration.TotalMinutes)" -ForegroundColor Magenta
$pwpolicy_lockoutduration = 1
}
if ($defaultPolicy.lockoutthreshold -eq 0) {
Write-Host "Lockout Threshold: Will never lock" -ForegroundColor Red
$pwpolicy_lockoutthreshold = 2
}
elseif ($defaultPolicy.lockoutthreshold -lt 11){
Write-Host "Lockout Threshold: $($defaultPolicy.lockoutthreshold)" -ForegroundColor Green
$pwpolicy_lockoutthreshold = 0
}
else {
Write-Host "Lockout Threshold: $($defaultPolicy.lockoutthreshold)" -ForegroundColor Magenta
$pwpolicy_lockoutthreshold = 1
}
if ($defaultPolicy.MinPasswordLength -lt 12){
Write-Host "Min Password Length: $($defaultPolicy.MinPasswordLength)" -ForegroundColor Red
$pwpolicy_pwlength = 2
}
else {
Write-Host "Min Password Length: $($defaultPolicy.MinPasswordLength)" -ForegroundColor Green
$pwpolicy_pwlength = 0
}
if ($defaultPolicy.ReversibleEncryptionEnabled -eq $true){
Write-Host "Reversible Encryption Enabled: $true" -ForegroundColor Red
$pwpolicy_revenc = 2
}
else {
Write-Host "Reversible Encryption Enabled: $false" -ForegroundColor Green
$pwpolicy_revenc = 0
}
Write-Host "Lockout Duration: $($defaultPolicy.LockoutDuration)" -ForegroundColor DarkGray
Write-Host "Lockout Observation Window: $($defaultPolicy.LockoutObservationWindow)" -ForegroundColor DarkGray
}
catch {
Write-Host "Failed to query domain information. Check if the domain is accessible." -ForegroundColor Yellow
$pwpolicy_error = 1
}
# Run As PPL checks
Write-host ""
Write-host "#####################################"
Write-host "# Now checking LSA Protection stuff #"
Write-host "#####################################"
Write-host "References: https://itm4n.github.io/lsass-runasppl/" -ForegroundColor DarkGray
Write-host "References: https://learn.microsoft.com/en-us/windows-server/security/credentials-protection-and-management/configuring-additional-lsa-protection" -ForegroundColor DarkGray
Write-host ""
try {
$value = Get-ItemPropertyvalue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -Name "RunAsPPL" -ErrorAction Stop
if ($value -eq 1) {
Write-Host "RunAsPPL: Enabled with UEFI Lock" -ForegroundColor Green
$RunAsPPL = 0
}
if ($value -eq 2) {
Write-Host "RunAsPPL: Enabled without UEFI Lock" -ForegroundColor Green
$RunAsPPL = 0
}
elseif ($value -eq 0) {
Write-Host "RunAsPPL: Disabled" -ForegroundColor Red
$RunAsPPL = 2
}
else {
Write-Host "RunAsPPL: Error (probably regkey doesn't exist - hence disabled)" -ForegroundColor Magenta
$RunAsPPL = 1
}
}
catch {
Write-Host "RunAsPPL: Error (probably regkey doesn't exist - hence disabled)" -ForegroundColor Magenta
$RunAsPPL = 1
}
<# Deprecated due to WDAC checks. According to MS Device Guard is no longer used: https://learn.microsoft.com/en-us/windows/security/threat-protection/device-guard/introduction-to-device-guard-virtualization-based-security-and-windows-defender-application-control
# Device Guard checks
Write-host ""
Write-host "###################################"
Write-host "# Now checking Device Guard stuff #"
Write-host "###################################"
Write-host "References: https://techcommunity.microsoft.com/t5/iis-support-blog/windows-10-device-guard-and-credential-guard-demystified/ba-p/376419" -ForegroundColor DarkGray
Write-host "References: https://learn.microsoft.com/en-us/windows/security/threat-protection/device-guard/introduction-to-device-guard-virtualization-based-security-and-windows-defender-application-control" -ForegroundColor DarkGray
Write-host ""
$computerInfo = Get-ComputerInfo
$DeviceGuardStatus = $computerInfo.DeviceGuardSmartStatus
if ($DeviceGuardStatus -eq "Running") {
Write-Host "Device Guard is enabled." -ForegroundColor Green
} else {
Write-Host "Device Guard is not enabled." -ForegroundColor Red
} #>
# WDAC checks
Write-host ""
Write-host "###########################"
Write-host "# Now checking WDAC stuff #"
Write-host "###########################"
Write-host "References: https://learn.microsoft.com/en-us/windows/security/threat-protection/device-guard/introduction-to-device-guard-virtualization-based-security-and-windows-defender-application-control" -ForegroundColor DarkGray
Write-host "References: https://learn.microsoft.com/en-us/answers/questions/536416/checking-microsoft-defender-application-control-is" -ForegroundColor DarkGray
Write-host "References: https://www.stigviewer.com/stig/windows_paw/2017-11-21/finding/V-78163" -ForegroundColor DarkGray
Write-host "References: https://www.stigviewer.com/stig/windows_paw/2017-11-21/finding/V-78157" -ForegroundColor DarkGray
Write-host ""
$deviceGuard = Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard
$CodeIntegrityPolicyEnforcementStatus = $deviceGuard.CodeIntegrityPolicyEnforcementStatus
$UsermodeCodeIntegrityPolicyEnforcementStatus = $deviceGuard.UsermodeCodeIntegrityPolicyEnforcementStatus
if ($CodeIntegrityPolicyEnforcementStatus -eq 2) {
Write-Host "Code Integrity Policy Enforcement is enabled." -ForegroundColor Green
$wdac_codeintegrity = 0
}
elseif ($CodeIntegrityPolicyEnforcementStatus -eq 0) {
Write-Host "Code Integrity Policy Enforcement is disabled." -ForegroundColor Red
$wdac_codeintegrity = 2
}
elseif ($CodeIntegrityPolicyEnforcementStatus -eq 1) {
Write-Host "Code Integrity Policy Enforcement is set to observe." -ForegroundColor Magenta
$wdac_codeintegrity = 1
}
else {
Write-Host "Code Integrity Policy Enforcement status is unknown." -ForegroundColor Red
$wdac_codeintegrity = 2
}
if ($UsermodeCodeIntegrityPolicyEnforcementStatus -eq 2) {
Write-Host "Usermode Code Integrity Policy Enforcement is enabled." -ForegroundColor Green
$wdac_usercodeintegrity = 0
}
elseif ($UsermodeCodeIntegrityPolicyEnforcementStatus -eq 0) {
Write-Host "Usermode Code Integrity Policy Enforcement is disabled." -ForegroundColor Red
$wdac_usercodeintegrity = 2
}
elseif ($UsermodeCodeIntegrityPolicyEnforcementStatus -eq 1) {
Write-Host "Usermode Code Integrity Policy Enforcement is set to observe." -ForegroundColor Magenta
$wdac_usercodeintegrity = 1
}
else {
Write-Host "Usermode Code Integrity Policy Enforcement status is unknown." -ForegroundColor Red
$wdac_usercodeintegrity = 2
}
# AppLocker checks
Write-host ""
Write-host "#################################"
Write-host "# Now checking AppLocker stuff #"
Write-host "################################"
Write-host "References: https://learn.microsoft.com/de-de/windows/security/threat-protection/windows-defender-application-control/applocker/applocker-overview" -ForegroundColor DarkGray
Write-host ""
$appLockerService = Get-Service -Name AppIDSvc
if ($appLockerService.Status -eq "Running") {
Write-Host "AppLocker is running." -ForegroundColor Green
$applocker = 0
} else {
Write-Host "AppLocker is not running." -ForegroundColor Red
$applocker = 2
}
# UAC checks
Write-host ""
Write-host "##################################"
Write-host "# Now checking if UAC is enabled #"
Write-host "##################################"
Write-host "References: https://learn.microsoft.com/en-us/windows/security/application-security/application-control/user-account-control/how-it-works" -ForegroundColor DarkGray
Write-host ""
$uacStatus = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "EnableLUA"
if ($uacStatus.EnableLUA -eq 1) {
Write-Host "UAC is enabled." -ForegroundColor Green
$uac = 0
} else {
Write-Host "UAC is disabled." -ForegroundColor Red
$uac = 2
}
# Guest Account check
Write-host ""
Write-host "############################################"
Write-host "# Now checking if Guest Account is enabled #"
Write-host "############################################"
Write-host "References: https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/accounts-guest-account-status" -ForegroundColor DarkGray
Write-host ""
# Get local user accounts
$guestAccount = Get-CimInstance -ClassName Win32_UserAccount | Where-Object {
$_.SID -match "-501" # The local Guest Account always has RID 501
}
# Check if the Guest account exists
if ($guestAccount) {
# Check if the Guest account is enabled
if ($guestAccount.Disabled -eq $false) {
Write-Host "Guest account enabled" -ForegroundColor Red
$guestacc = 2
} else {
Write-Host "Guest account disabled" -ForegroundColor Green
$guestacc = 0
}
} else {
Write-Host "Guest account not found" -ForegroundColor Yellow
$guestacc = 3
}
# System Tools as Low Priv User check
# We only want to check if not ran as admin
if($elevated -eq $false){
Write-host ""
Write-host "#######################################################"
Write-host "# Now checking if Low Priv User can run System Tools #"
Write-host "#######################################################"
Write-host "References: " -ForegroundColor DarkGray
Write-host ""
Write-host "We are now trying to open several system tools with our low priv user. Please do only close them manually if they do not autoclose after the test." -ForegroundColor yellow
Write-host "You may observe error messages when programs were run with UAC, which is absolutely normal, and can be ignored." -ForegroundColor yellow
Write-host "You need to answer the questions in this PowerShell window!!!" -ForegroundColor yellow
$response = Read-Host "ARE YOU READY FOR THE TESTS???? (y/n)(Choosing n will skip the tests)"
if ($response -eq 'y') {
# Check if can run registry
$registrySuccess = $null
try {
$registrySuccess = Start-Process 'regedit.exe' -PassThru
$response = Read-Host "Was the registry editor started successfully? (y/n)"
if ($response -eq 'y') {
Write-Host "Normal user can run regedit" -ForegroundColor Red
$stregedit = 2
} else {
Write-Host "Normal user cannot run regedit" -ForegroundColor Green
$stregedit = 0
}
} catch {
Write-Host "An error occured" -ForegroundColor yellow
$stregedit = 3
} finally {
if ($registrySuccess) {
Stop-Process -Id $registrySuccess.Id -Force
}
}
# Check if can run cmd
$cmdSuccess = $null
try {
$cmdSuccess = Start-Process 'cmd.exe' -PassThru
$response = Read-Host "Was the command prompt started successfully? (y/n)"
if ($response -eq 'y') {
Write-Host "Normal user can run cmd" -ForegroundColor Red
$stcmd = 2
} else {
Write-Host "Normal user cannot run cmd" -ForegroundColor Green
$stcmd = 0
}
} catch {
Write-Host "An error occured" -ForegroundColor yellow
$stcmd = 3
} finally {
if ($cmdSuccess) {
Stop-Process -Id $cmdSuccess.Id -Force
}
}
# Check if can run PowerShell
$powershellSuccess = $null
try {
$powershellSuccess = Start-Process 'powershell.exe' -PassThru
$response = Read-Host "Was PowerShell started successfully? (y/n)"
if ($response -eq 'y') {
Write-Host "Normal user can run PowerShell" -ForegroundColor Red
$stpowershell = 2
} else {
Write-Host "Normal user cannot run PowerShell" -ForegroundColor Green
$stpowershell = 0
}
} catch {
Write-Host "An error occured" -ForegroundColor yellow
$stpowershell = 3
} finally {
if ($powershellSuccess) {
Stop-Process -Id $powershellSuccess.Id -Force
}
}
}
elseif ($response -eq 'n') {
Write-Host "Okay, we will skip those" -ForegroundColor Red
}
else {
Write-Host "God dammit, only y or n!!!" -ForegroundColor yellow
}
}
# Always install elevated active?
Write-host ""
Write-host "######################################################"
Write-host "# Now checking if Always Install Elevated is enabled #"
Write-host "######################################################"
Write-host "References: https://learn.microsoft.com/en-us/windows/win32/msi/alwaysinstallelevated" -ForegroundColor DarkGray
Write-host "References: https://pentestlab.blog/2017/02/28/always-install-elevated/" -ForegroundColor DarkGray
Write-host ""
$keysToCheck = @(
"Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer",
"Registry::HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Installer"
)
$enabled = $false
foreach ($keyPath in $keysToCheck) {
$alwaysInstallElevated = Get-ItemProperty -Path $keyPath -Name "AlwaysInstallElevated" -ErrorAction SilentlyContinue
if ($alwaysInstallElevated -ne $null) {
if ($alwaysInstallElevated.AlwaysInstallElevated -eq 1) {
$enabled = $true
break # Exit the loop if enabled in any of the keys
}
}
}
if ($enabled) {
Write-Host "Always install elevated is active." -ForegroundColor Red
$aie = 2
} else {
Write-Host "Always install elevated is not active." -ForegroundColor Green
$aie = 0
}
# Credential Guard checks
Write-host ""
Write-host "#######################################"
Write-host "# Now checking Credential Guard stuff #"
Write-host "#######################################"
Write-host "References: https://itm4n.github.io/credential-guard-bypass/" -ForegroundColor DarkGray
Write-host "References: https://learn.microsoft.com/en-us/windows/security/identity-protection/credential-guard/credential-guard-manage" -ForegroundColor DarkGray
Write-host ""
$credentialGuardEnabled = (Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard).SecurityServicesRunning
if ($credentialGuardEnabled -eq 1) {
Write-Host "Credential Guard is enabled." -ForegroundColor Green
$credguard = 0
} else {
Write-Host "Credential Guard is not enabled." -ForegroundColor red
$credguard = 2
}
# Co-Installer checks
Write-host ""
Write-host "###################################"
Write-host "# Now checking Co-installer stuff #"
Write-host "###################################"
Write-host "References: https://learn.microsoft.com/en-us/windows-hardware/drivers/install/registering-a-device-specific-co-installer" -ForegroundColor DarkGray
Write-host "References: https://www.bleepingcomputer.com/news/microsoft/how-to-block-windows-plug-and-play-auto-installing-insecure-apps" -ForegroundColor DarkGray
Write-host "References: https://www.scip.ch/en/?labs.20211209" -ForegroundColor DarkGray
Write-host ""
try {
$value = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Device Installer" -Name "DisableCoInstallers" -ErrorAction Stop
if ($value -eq 1) {
Write-Host "Allow installation of Co-installers: Disabled" -ForegroundColor Green
$coinstaller = 0
}
elseif ($value -eq 0) {
Write-Host "Allow installation of Co-installers: Enabled" -ForegroundColor Red
$coinstaller = 2
}
}
catch {
Write-Host "Allow installation of Co-installers: Error (probably regkey doesn't exist - hence enabled)" -ForegroundColor Red
$coinstaller = 2
}
# DMA protection related stuff
Write-host ""
Write-host "#####################################"
Write-host "# Now checking DMA Protection stuff #"
Write-host "#####################################"
Write-host "References: https://www.synacktiv.com/en/publications/practical-dma-attack-on-windows-10.html" -ForegroundColor DarkGray
Write-host "References: https://www.scip.ch/?labs.20211209" -ForegroundColor DarkGray
Write-host "References: https://learn.microsoft.com/en-us/windows/client-management/mdm/policy-csp-dataprotection" -ForegroundColor DarkGray
Write-host ""
try {
$value = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DeviceLock" -Name "AllowDirectMemoryAccess" -ErrorAction Stop
if ($value -eq 1) {
Write-Host "AllowDirectMemoryAccess: Enabled" -ForegroundColor Red
$dma_access = 2
}
elseif ($value -eq 0) {
Write-Host "AllowDirectMemoryAccess: Disabled" -ForegroundColor Green
$dma_access = 0
}
else {
Write-Host "AllowDirectMemoryAccess: Error (probably regkey doesn't exist - hence enabled)" -ForegroundColor Magenta
$dma_access = 1
}
}
catch {
Write-Host "AllowDirectMemoryAccess: Error (probably regkey doesn't exist - hence enabled)" -ForegroundColor Magenta
$dma_access = 1
}
try {
$value = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard" -Name "EnableVirtualizationBasedSecurity" -ErrorAction Stop
if ($value -eq 1) {
Write-Host "EnableVirtualizationBasedSecurity: Enabled" -ForegroundColor Green
$dma_vbs = 0
}
elseif ($value -eq 0) {
Write-Host "EnableVirtualizationBasedSecurity: Disabled" -ForegroundColor Red
$dma_vbs = 2
}
else {
Write-Host "EnableVirtualizationBasedSecurity: Error (probably regkey doesn't exist - hence disabled)" -ForegroundColor Magenta
$dma_vbs = 1
}
}
catch {
Write-Host "EnableVirtualizationBasedSecurity: Error (probably regkey doesn't exist - hence disabled)" -ForegroundColor Magenta
$dma_vbs = 1
}
try {
$value = Get-ItemPropertyValue -Path Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity" -Name "Enabled" -ErrorAction Stop
if ($value -eq 1) {
Write-Host "HypervisorEnforcedCodeIntegrity: Enabled" -ForegroundColor Green
$dma_heci = 0
}
elseif ($value -eq 0) {
Write-Host "HypervisorEnforcedCodeIntegrity: Disabled" -ForegroundColor Red
$dma_heci = 2
}
else {
Write-Host "HypervisorEnforcedCodeIntegrity: Error (probably regkey doesn't exist - hence disabled)" -ForegroundColor Magenta
$dma_heci = 1
}
}
catch {
Write-Host "HypervisorEnforcedCodeIntegrity: Error (probably regkey doesn't exist - hence disabled)" -ForegroundColor Magenta
$dma_heci = 1
}
try {
$value = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity" -Name "LockConfiguration" -ErrorAction Stop
if ($value -eq 1) {
Write-Host "HypervisorEnforcedCodeIntegrity Config Locked: Enabled" -ForegroundColor Green
$dma_heci_locked = 0
}
elseif ($value -eq 0) {
Write-Host "HypervisorEnforcedCodeIntegrity Config Locked: Disabled" -ForegroundColor Red
$dma_heci_locked = 2
}
else {
Write-Host "HypervisorEnforcedCodeIntegrity Config Locked: Error (probably regkey doesn't exist - hence disabled)" -ForegroundColor Magenta
$dma_heci_locked = 1
}
}
catch {
Write-Host "HypervisorEnforcedCodeIntegrity Config Locked: Error (probably regkey doesn't exist - hence disabled)" -ForegroundColor Magenta
$dma_heci_locked = 1
}
# BitLocker status
Write-host ""
Write-host "###################################"
Write-host "# Now checking BitLocker settings #"
Write-host "# If TPM only > possibly insecure #"
Write-host "###################################"
Write-host "References: https://learn.microsoft.com/en-us/powershell/module/bitlocker/add-bitlockerkeyprotector?view=windowsserver2022-ps" -ForegroundColor DarkGray
Write-host "References: https://luemmelsec.github.io/Go-away-BitLocker-you-are-drunk/" -ForegroundColor DarkGray
Write-host ""
$volumes = $null
$bl_greenCount = 0
$bl_magentaCount = 0
$bl_redCount = 0
$bl_yellowCount = 0
try {
$volumes = Get-BitLockerVolume -ErrorAction Stop
foreach ($volume in $volumes) {
$volumeLabel = $volume.MountPoint
$bitLockerStatus = $volume.ProtectionStatus
$keyProtectorType = $volume.KeyProtector.KeyProtectorType
if ($bitLockerStatus -eq "On") {
Write-Host "BitLocker on volume $volumeLabel - enabled" -ForegroundColor Green
$bl_greenCount++
if ($keyProtectorType -like "*ExternalKey*") {
Write-Host "Protection of key material on volume $volumeLabel - possibly insecure" -ForegroundColor Magenta
$bl_magentaCount++
}
elseif ($keyProtectorType -like "*key*" -or $keyProtectorType -like "*pin*") {
Write-Host "Protection of key material on volume $volumeLabel - okay" -ForegroundColor Green
$bl_greenCount++
}
else {
Write-Host "Protection of key material on volume $volumeLabel - possibly insecure" -ForegroundColor Magenta
$bl_magentaCount++
}
}
else {
Write-Host "BitLocker on volume $volumeLabel - disabled" -ForegroundColor Red
$bl_redCount++
}
}
} catch {
$errorMessage = $_.Exception.Message
if ($errorMessage -like "*Access Denied*") {
Write-Host "Could not query the information with current rights." -ForegroundColor Yellow
$bl_yellowCount++
} else {
Write-Host "An error occurred: $errorMessage" -ForegroundColor Red
$bl_redCount++
}
}
# Secure Boot enabled?
Write-host ""
Write-host "#####################################"
Write-host "# Now checking Secure Boot settings #"
Write-host "#####################################"
Write-host "References: https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/oem-secure-boot" -ForegroundColor DarkGray
Write-host ""
try {
$value = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecureBoot\State" -Name "UEFISecureBootEnabled" -ErrorAction Stop
if ($value.UEFISecureBootEnabled -eq 1) {
Write-Host "Secure Boot is enabled" -ForegroundColor Green
$secureboot = 0
}
elseif ($value.UEFISecureBootEnabled -eq 0) {
Write-Host "Secure Boot is disabled" -ForegroundColor Red
$secureboot = 2
}
}
catch {
Write-Host "Secure Boot settings: Error (probably regkey doesn't exist - hence disabled)" -ForegroundColor Red
$secureboot = 2
}
# Can the Users group write to SYSTEM PATH folders > Hijacking possibilities?
Write-host ""
Write-host "###########################################################"
Write-host "# Now checking ACLs on folders from `$PATH System variable #"
Write-host "###########################################################"
Write-host "References: https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/dll-hijacking/writable-sys-path-+dll-hijacking-privesc" -ForegroundColor DarkGray
Write-host ""
$spa_greenCount = 0
$spa_redCount = 0
$env:Path -split ';' | ForEach-Object {
$folder = $_
if (Test-Path -Path $folder) {
$acl = Get-Acl -Path $folder
$usersGroup = New-Object System.Security.Principal.NTAccount("BUILTIN", "Users")
$usersAccess = $acl.Access | Where-Object { $_.IdentityReference -eq $usersGroup -and $_.FileSystemRights -band [System.Security.AccessControl.FileSystemRights]::Write }
if ($usersAccess -ne $null) {
Write-Host "Members of the Users Group can write to folder: $folder" -ForegroundColor Red
$spa_redCount++
} else {
Write-Host "Members of the Users Group cannot write to folder: $folder" - -ForegroundColor Green
$spa_greenCount++
}
} else {
Write-Host "Folder does not exist: $folder"
}
}
# Do we have unqoted service paths? > Hijacking possibilities?
Write-host ""
Write-host "###########################################"
Write-host "# Now checking for unquoted service paths #"
Write-host "###########################################"
Write-host "References: https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/dll-hijacking/writable-sys-path-+dll-hijacking-privesc" -ForegroundColor DarkGray
Write-Host "References: https://github.com/itm4n/PrivescCheck/tree/master" -ForegroundColor DarkGray
Write-host ""
$uqsp_redcount = 0
$services = Get-CimInstance -Class Win32_Service -Property Name, DisplayName, PathName, StartMode |
Where-Object {
$_.PathName -notlike "C:\Windows*" -and
$_.PathName -notlike '"*"*' -and
$_.PathName -ne $null
}
foreach ($service in $services) {
$serviceName = $service.Name
$path = $service.PathName
$displayName = $service.DisplayName
$startMode = $service.StartMode
Write-Host "Service Name: $($serviceName)" -ForegroundColor Red
Write-Host "Path: $($path)" -ForegroundColor Red
Write-Host "Display Name: $($displayName)" -ForegroundColor Red
Write-Host "Start Mode: $($startMode)" -ForegroundColor Red
Write-Host "" -ForegroundColor Red
$uqsp_redcount++
}
# Check if WSUS is fetching updates over HTTP instaed of HTTPS?
Write-host ""
Write-host "##############################"
Write-host "# Now checking WSUS settings #"
Write-host "##############################"
Write-host "References: https://www.gosecure.net/blog/2020/09/03/wsus-attacks-part-1-introducing-pywsus/" -ForegroundColor DarkGray
Write-host ""
try {
$wsusPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
if (Test-Path -Path $wsusPath) {
$wsusConfiguration = Get-ItemProperty -Path $wsusPath -Name "WUServer"
$wsusServerUrl = $wsusConfiguration.WUServer
if ($wsusServerUrl -match "^http://") {
Write-Host "WSUS updates are fetched over HTTP." -ForegroundColor Red
$wsus = 2
} else {
Write-Host "WSUS updates are not fetched over HTTP." -ForegroundColor Green
$wsus = 0
}
} else {
Write-Host "WSUS is not configured." -ForegroundColor Green
$wsus = 0
}
} catch {
Write-Host "An error occurred while checking the WSUS configuration."
$wsus = 3
}
# PowerShell related checks
Write-host ""
Write-host "####################################"
Write-host "# Now checking PowerShell settings #"
Write-host "####################################"
Write-host "References: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.3" -ForegroundColor DarkGray
Write-host ""
# Check if PowerShell v2 can be run
$psVersion2Enabled = $false
$psInfo = New-Object System.Diagnostics.ProcessStartInfo
$psInfo.FileName = 'powershell.exe'
$psInfo.Arguments = '-Version 2 -NoExit -Command "exit"'
$psInfo.RedirectStandardOutput = $true
$psInfo.RedirectStandardError = $true
$psInfo.UseShellExecute = $false
$psInfo.CreateNoWindow = $true
$psProcess = New-Object System.Diagnostics.Process
$psProcess.StartInfo = $psInfo
try {
[void]$psProcess.Start()
[void]$psProcess.WaitForExit()
if ($psProcess.ExitCode -eq 0) {
$psVersion2Enabled = $true
}
} finally {
[void]$psProcess.Dispose()
}
if ($psVersion2Enabled) {
Write-Host "PowerShell v2 can be run." -ForegroundColor Red
$ps_v2 = 2
} else {
Write-Host "PowerShell v2 cannot be run." -ForegroundColor Green
$ps_v2 = 0
}
# Check the execution policy
$executionPolicy = Get-ExecutionPolicy
if ($executionPolicy -eq "AllSigned") {
Write-Host "Execution Policy is $executionPolicy" -ForegroundColor Green
$ps_ep = 0
} elseif ($executionPolicy -eq "Unrestricted" -or $executionPolicy -eq "Bypass") {
Write-Host "Execution Policy is $executionPolicy" -ForegroundColor Red
$ps_ep = 2
} else {
Write-Host "Execution Policy is $executionPolicy" -ForegroundColor Magenta
$ps_ep = 1
}
# Check the language mode
$languageMode = $ExecutionContext.SessionState.LanguageMode
if ($languageMode -eq "FullLanguage") {
Write-Host "Language Mode is $languageMode" -ForegroundColor Red
$ps_lm = 2
} else {
Write-Host "Language Mode is $languageMode" -ForegroundColor Green
$ps_lm = 0
}
# IPv6 settings
Write-host ""
Write-host "##############################"
Write-host "# Now checking IPv6 settings #"
Write-host "##############################"
Write-host "References: https://blog.fox-it.com/2018/01/11/mitm6-compromising-ipv4-networks-via-ipv6/" -ForegroundColor DarkGray
Write-host "References: https://www.blackhillsinfosec.com/mitm6-strikes-again-the-dark-side-of-ipv6/" -ForegroundColor DarkGray
Write-host ""
$adapterStatus = Get-NetAdapterBinding | Where-Object {$_.ComponentID -eq "ms_tcpip6"} | Select-Object -Property Name, Enabled
$adapterStatus | ForEach-Object {
$adapterName = $_.Name
if (-not $_.Enabled) {
Write-Host "IPv6 is disabled on Adapter $adapterName." -ForegroundColor Green
$ipv6 = 0
} else {
Write-Host "IPv6 is enabled on Adapter $adapterName." -ForegroundColor Red
$ipv6 = 2
}
}
# NetBIOS Name Resolution,LLMNR and mDNS checks
Write-host ""
Write-host "################################################"
Write-host "# Now checking NetBIOS / LLMNR / mDNS settings #"
Write-host "################################################"
Write-host "References: https://luemmelsec.github.io/Relaying-101/" -ForegroundColor DarkGray
Write-host ""
# Check if LLMNR is enabled or disabled
$dnsClientKey = "HKLM:\Software\Policies\Microsoft\Windows NT\DNSClient"
try {
$llmnrValue = (Get-ItemProperty -Path $dnsClientKey -Name "EnableMulticast" -ErrorAction Stop).EnableMulticast
if ($llmnrValue -eq 0) {
Write-Host "LLMNR status: disabled" -ForegroundColor Green
$llmnr = 0
} elseif ($llmnrValue -eq 1) {
Write-Host "LLMNR status: enabled" -ForegroundColor Red
$llmnr = 2
}
} catch {
Write-Host "LLMNR status: reg key not found - hence enabled" -ForegroundColor Red
$llmnr = 2
}
# Check if mDNS is enabled or disabled
$mDNSParametersKey = "HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters"
try {
$mdnsValue = (Get-ItemProperty -Path $mDNSParametersKey -Name "EnableMDNS" -ErrorAction Stop).EnableMDNS
if ($mdnsValue -eq 0) {
Write-Host "mDNS status: disabled" -ForegroundColor Green
$mdns= 0
} elseif ($mdnsValue -eq 1) {
Write-Host "mDNS status: enabled" -ForegroundColor Red
$mdns = 2
}
} catch {
Write-Host "mDNS status: reg key not found - hence enabled" -ForegroundColor Red
$mdns = 2
}
# Check if NetBIOS is enabled for each network adapter
$netbtInterfacePath = "HKLM:\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces"
$adapterKeys = Get-ChildItem -Path $netbtInterfacePath -ErrorAction SilentlyContinue
$netbiosEnabled = $false
$enabledAdapters = @()
foreach ($adapterKey in $adapterKeys) {
$adapterName = $adapterKey.PSChildName
if ($adapterName -like "Tcpip_*") {
$adapterName = $adapterName -replace "^Tcpip_", ""
$netbiosOptions = (Get-ItemProperty -Path "$netbtInterfacePath\$($adapterKey.PSChildName)" -Name "NetbiosOptions" -ErrorAction SilentlyContinue).NetbiosOptions
if ($netbiosOptions -eq 1 -or $netbiosOptions -eq 0) {
$netbiosEnabled = $true
$enabledAdapters += $adapterName
}
}
}
if ($netbiosEnabled) {
Write-Host "NetBIOS status: Enabled on at least one network adapter" -ForegroundColor Red
$netbios = 2
Write-Host ""
foreach ($adapter in $enabledAdapters) {
$adapterInstance = Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration | Where-Object { $_.SettingID -like "*$adapter*" }
Write-Host $adapterInstance.Description -ForegroundColor Red
}
}
else {
Write-Host "NetBIOS status: Not enabled on any network adapter" -ForegroundColor Green
$netbios = 0
}
# SMB Checks
Write-host ""
Write-host "####################################"
Write-host "# Now checking SMB Server settings #"
Write-host "####################################"
Write-host "References: https://luemmelsec.github.io/Relaying-101/" -ForegroundColor DarkGray
Write-host "References: https://techcommunity.microsoft.com/t5/storage-at-microsoft/configure-smb-signing-with-confidence/ba-p/2418102" -ForegroundColor DarkGray
Write-host ""
$smbConfig = Get-SmbServerConfiguration
# Check SMB1 settings
if ($smbConfig.EnableSMB1Protocol) {
Write-Host "SMB version 1 is used. No Signing available here!!!" -ForegroundColor Red
$smb_v1 = 2
} else {
Write-Host "SMB version 1 is not used" -ForegroundColor Green
$smb_v1 = 0
}
# Check SMB Signing settings
if ($smbConfig.RequireSecuritySignature) {
Write-Host "SMB signing is enabled for SMB2 and newer" -ForegroundColor Green
$smb_sig = 0
} else {
Write-Host "SMB signing is disabled for SMB2 and newer" -ForegroundColor Red
$smb_sig = 2
}
# Firewall Checks
Write-host ""
Write-host "##################################"
Write-host "# Now checking Firewall settings #"
Write-host "##################################"
Write-host "References: https://learn.microsoft.com/en-us/windows/security/operating-system-security/network-security/windows-firewall/best-practices-configuring" -ForegroundColor DarkGray
Write-host ""
try {
$firewallProfile = Get-NetFirewallProfile -Profile Domain, Public, Private -ErrorAction Stop
if ($firewallProfile.Enabled) {
Write-Host "Windows Firewall is enabled." -ForegroundColor Magenta
Write-Host "Firewall Rules (check them for dangerous stuff):" -ForegroundColor Magenta
# Get all Firewall rules
$firewallRules = Get-NetFirewallRule 2>&1
if ($firewallRules -match "Access is denied") {
Write-Host "Could not query the information with current rights." -ForegroundColor Yellow
$firewall = 3
}
elseif ($firewallRules) {
$ruleTable = @()
$firewall = 1
foreach ($rule in $firewallRules) {
$ruleName = $rule.Name
# The ports are not stored directly in the rules but in the associated Port Filter set
$portFilters = Get-NetFirewallPortFilter -AssociatedNetFirewallRule $rule -ErrorAction SilentlyContinue
$localAddresses = @()
$remoteAddresses = @()
# Local and remote addresses are not directly stored in the rule but in the associated Address Filter set
$addressFilters = Get-NetFirewallAddressFilter -AssociatedNetFirewallRule $rule -ErrorAction SilentlyContinue
foreach ($addressFilter in $addressFilters) {
if ($addressFilter.LocalAddress -ne "*") {
$localAddresses += $addressFilter.LocalAddress
}
if ($addressFilter.RemoteAddress -ne "*") {
$remoteAddresses += $addressFilter.RemoteAddress
}
}
$localAddress = if ($localAddresses) { $localAddresses -join ', ' } else { "N/A" }
$remoteAddress = if ($remoteAddresses) { $remoteAddresses -join ', ' } else { "N/A" }
$ruleEntry = [PSCustomObject]@{
"Rule Name" = $rule.DisplayName