-
Notifications
You must be signed in to change notification settings - Fork 120
/
grouper.psm1
1879 lines (1652 loc) · 83.6 KB
/
grouper.psm1
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
# Grouper - Get-GPOReport XML Parser
<#
.SYNOPSIS
Consumes a Get-GPOReport XML formatted report and outputs potentially vulnerable settings.
.DESCRIPTION
Consumes a Get-GPOReport XML formatted report and outputs potentially vulnerable settings.
GPP cpassword decryption function stolen shamelessly from @harmj0y
Lots of assist from @sysop_host
.EXAMPLE
So first you need to generate a report on a machine with the Group Policy PS module installed. Do that like this:
"Get-GPOReport -All -ReportType XML -Path C:\temp\gporeport.xml"
Then import this module and:
"Invoke-AuditGPOReport -Path C:\temp\gporeport.xml"
-hideDisabled or else by default we just filter out policy objects that aren't enabled or linked anywhere.
-Level (1, 2, or 3) - adjusts whether to show everything (1) or only interesting (2) or only definitely vulnerable (3) settings. Defaults to 2.
-lazyMode (without -Path) will run the initial generation of the GPOReport for you but will need to be running as a domain user on a domain-joined machine.
-blurb will provide a little extra description on why you should care about what you're seeing and what you might want to do with it.
.NOTES
Author : Mike Loss - [email protected]
#>
# Some arrays of group names that are 'interesting', either because they are canonically 'low-priv' and huge numbers of accounts will be in them
# or because they are high-priv enough that members are very likely to have privileged access to a host, whole domain or a number of hosts.
# TODO ADD TO THIS LIST
$intPrivLocalGroups = @()
$intPrivLocalGroups += "Administrators"
$intPrivLocalGroups += "Backup Operators"
$intPrivLocalGroups += "Hyper-V Administrators"
$intPrivLocalGroups += "Power Users"
$intPrivLocalGroups += "Print Operators"
$intPrivLocalGroups += "Remote Desktop Users"
$intPrivLocalGroups += "Remote Management Users"
# TODO ADD TO THIS LIST?
$intLowPrivDomGroups = @()
$intLowPrivDomGroups += "Domain Users"
$intLowPrivDomGroups += "Authenticated Users"
$intLowPrivDomGroups += "Everyone"
# TODO ADD TO THIS LIST?
$intLowPrivLocalGroups = @()
$intLowPrivLocalGroups += "Users"
$intLowPrivLocalGroups += "Everyone"
$intLowPrivLocalGroups += "Authenticated Users"
# TODO ADD TO THIS LIST?
$intLowPrivGroups = @()
$intLowPrivGroups += "Domain Users"
$intLowPrivGroups += "Authenticated Users"
$intLowPrivGroups += "Everyone"
$intLowPrivGroups += "Users"
# TODO ADD TO THIS LIST?
$intPrivDomGroups = @()
$intPrivDomGroups += "Domain Admins"
$intPrivDomGroups += "Administrators"
$intPrivDomGroups += "DNS Admins"
$intPrivDomGroups += "Backup Operators"
$intPrivDomGroups += "Enterprise Admins"
$intPrivDomGroups += "Schema Admins"
$intPrivDomGroups += "Server Operators"
$intPrivDomGroups += "Account Operators"
# THIS ONE IS FINE
$intRights = @()
$intRights += "SeTrustedCredManAccessPrivilege"
$intRights += "SeTcbPrivilege"
$intRights += "SeMachineAccountPrivilege"
$intRights += "SeBackupPrivilege"
$intRights += "SeCreateTokenPrivilege"
$intRights += "SeAssignPrimaryTokenPrivilege"
$intRights += "SeRestorePrivilege"
$intRights += "SeDebugPrivilege"
$intRights += "SeTakeOwnershipPrivilege"
$intRights += "SeCreateGlobalPrivilege"
$intRights += "SeLoadDriverPrivilege"
$intRights += "SeRemoteInteractiveLogonRight"
$boringTrustees = @()
$boringTrustees += "BUILTIN\Administrators"
$boringTrustees += "NT AUTHORITY\SYSTEM"
# The blurbs for each check displayed if you run with -blurb enabled.
$blurbs = @{}
$blurbs.Add("Get-GPOEnvVars", "Environment variables being set. Might find something dumb like an API key or a VM.")
$blurbs.Add("Get-GPORegSettings", "A bunch more 'misc' security settings, including all the MS Office settings around macros etc.")
$blurbs.Add("Get-GPOShortcuts", "Creates shortcuts which could provide useful intel on internal applications. Alternatively, if you can modify the target of a shortcut you might be able to replace it with /nasty.")
$blurbs.Add("Get-GPOPerms", "These are the permissions on the Group Policy Object itself. If you have modify rights here, you can take over any user or computer that the policy applies to.")
$blurbs.Add("Get-GPOUsers", "Entries in here add, change, or remove local users from hosts. If you see a password in here that's probably bad.")
$blurbs.Add("Get-GPOGroups", "These entries make changes to local groups on the hosts. If someone has been added to a highly privileged group that might be useful to you?")
$blurbs.Add("Get-GPOUserRights", "This is where you'll see users and groups being assigned interesting privileges on hosts. Google the name of the right being assigned if you wanna know what it does.")
$blurbs.Add("Get-GPOSchedTasks", "These are scheduled tasks being pushed to hosts. Sometimes they have credentials and stuff in them?")
$blurbs.Add("Get-GPOMSIInstallation", "These are MSI files that are being installed via group policy. If you can replace one of them with something nasty you could probably do something evil?")
$blurbs.Add("Get-GPOScripts", "These are startup and shutdown scripts, that kind of thing. If you can edit one you can probably have a nice time?")
$blurbs.Add("Get-GPOFileUpdate", "These are all changes being made to files on the target system, either adding new ones, removing existing ones, or updating existing ones. If you can modify the source files you o have a nice time, depending on the file type, if it ever gets executed, etc.")
$blurbs.Add("Get-GPOFilePerms", "These entries modify file permissions on the target host's file system. Could be useful for identifying privesc vulns, that kind of thing.")
$blurbs.Add("Get-GPOSecurityOptions", "A lot of these are kind of 'misc' security settings, you'll need to google individual items to understand what each means. If you want Grouper to provide more detail, I eagerly ll request.")
$blurbs.Add("Get-GPORegKeys", "These are reg keys that are being pushed to target hosts. If they show up in -Level 3 or 2 they're worth a closer look as they probably contain credentials. If you think this ore detail... I eagerly await your pull request.")
$blurbs.Add("Get-GPONetworkShares", "Defines file shares that should be created on target hosts. Handy recon data basically.")
$blurbs.Add("Get-GPOFWSettings", "Windows Firewall settings. Might be useful for identifying why a payload isn't working, or which servers are hosting what apps if that's otherwise difficult.")
$blurbs.Add("Get-GPOIniFiles", "Ini files are an old timey way of doing Windows app configs. You might find some creds in here?")
$blurbs.Add("Get-GPOAccountSettings", "These are all the settings that define stuff like password policy, some options for how passwords are stored, that kind of thing.")
#____________________ GPO Check functions _______________
# There's a whole pile of these functions. Each one consumes a single <GPO> object from a Get-GPOReport XML report,
# then depending on the -Level parameter it should output interesting/vulnerable/any policy it can process.
# The rule of thumb for whether a check function should exist at all is "Does this class of policy have any possible settings with security impact?"
# The rule of thumb for whether a setting is "Vulnerable" enough for Level 3 is "If it is likely to result in large numbers of users or the current user
# being able to get a shell or an RDP session on a host".
# The rule of thumb for whether a setting is "Interesting" enough for Level 2 is "if it could meet the criteria for Level 3 but Grouper can't tell
# whether it does without user intervention."
# At the moment Level 1 is pretty much just showing all the settings that Grouper can parse, but in the future it should filter out settings that
# have been configured 'securely', where there is a clear best-practice option.
Function Get-GPOUsers {
[cmdletbinding()]
# Consumes a single <GPO> object from a Get-GPOReport XML report.
######
# Description: Checks for changes made to local users.
# Level 3: Only show instances where a password has been set, i.e. GPP Passwords.
# Level 2: All users and all changes.
# Level 1: All users and all changes.
######
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
$GPOisinteresting = $false
$GPOisvulnerable = $false
# Grab an array of the settings we're interested in from the GPO.
$settingsUsers = ($polXml.ExtensionData.Extension.LocalUsersAndGroups.User | Sort-Object GPOSettingOrder)
# Check if there's actually anything in the array.
if ($settingsUsers) {
$output = @{}
# Iterate over array of settings, writing out only those we care about.
foreach ($setting in $settingsUsers) {
#see if we have any stored encrypted passwords
$cpasswordcrypt = $setting.properties.cpassword
if ($cpasswordcrypt) {
$GPOisvulnerable = $true
# decrypt it with harmj0y's function
$cpasswordclear = Get-DecryptedCpassword -Cpassword $cpasswordcrypt
}
#if so, or if we're showing boring, show the rest of the setting
if (($cpasswordcrypt) -Or ($level -le 2)) {
$GPOisinteresting = $true
$output = @{}
$output.Add("Name", $setting.Name)
$output.Add("New Name", $setting.properties.NewName)
$output.Add("Description", $setting.properties.Description)
$output.Add("changeLogon", $setting.properties.changeLogon)
$output.Add("noChange", $setting.properties.noChange)
$output.Add("neverExpires", $setting.properties.neverExpires)
$output.Add("Disabled", $setting.properties.acctDisabled)
$output.Add("UserName", $setting.properties.userName)
$output.Add("Password", $($cpasswordclear, "Password Not Set" -ne $null)[0])
Write-NoEmpties -output $output
}
}
}
if ($GPOisinteresting) {
$Global:GPOsWithIntSettings += 1
}
if ($GPOisvulnerable) {
$Global:GPOsWithVulnSettings += 1
}
}
Function Get-GPOGroups {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for changes made to local groups.
# Level 3: If Domain Users, Everyone, Authenticated Users get added to 'interesting groups'.
# Level 2: Show changes to groups that grant meaningful security-relevant access.
# Level 1: All groups and all changes.
######
$GPOIsInteresting = $false
$GPOIsVulnerable = $false
$settingsGroups = ($polXml.ExtensionData.Extension.LocalUsersAndGroups.Group | Sort-Object GPOSettingOrder)
if ($settingsGroups) {
foreach ($setting in $settingsGroups) {
$settingIsInteresting = $false
$settingIsVulnerable = $false
$groupIsInteresting = $false
# check if the group being modified is one of the high-priv local groups array,
$groupName = $setting.properties.groupName
if ($intPrivLocalGroups -Contains $groupName) {
$GPOIsInteresting = $true
$settingIsInteresting = $true
$groupIsInteresting = $true
}
# if it's in that array AND a member being modified is a low-priv domain group, we flag the setting as vulnerable.
$groupmembers = $setting.properties.members.member
foreach ($groupmember in $groupmembers) {
$groupMemberName = $groupmember.name
foreach ($lowPrivDomGroup in $intLowPrivDomGroups) {
if (($groupMemberName -match $lowPrivDomGroup) -And ($groupIsInteresting)){
$settingIsVulnerable = $true
$GPOIsVulnerable = $true
}
}
}
if ((($settingIsVulnerable) -And ($level -le 3)) -Or (($settingIsInteresting) -And ($level -le 2)) -Or ($level -eq 1)) {
$output = @{}
$output.Add("Name", $setting.Name)
$output.Add("NewName", $setting.properties.NewName)
$output.Add("Description", $setting.properties.Description)
$output.Add("Group Name", $groupName)
Write-NoEmpties -output $output
foreach ($member in $setting.properties.members.member) {
$output = @{}
$output.Add("Name", $member.name)
$output.Add("Action", $member.action)
$output.Add("UserName", $member.userName)
Write-NoEmpties -output $output
}
}
}
}
if ($GPOisinteresting) {
$Global:GPOsWithIntSettings += 1
}
if ($GPOIsVulnerable) {
$Global:GPOsWithVulnSettings += 1
}
}
Function Get-GPOUserRights {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for user rights granted to users and groups.
# Level 3: Only show "Interesting" rights, i.e. those that can be used for local privilege escalation or remote access,
# and only if they've been assigned to Domain Users, Authenticated Users, or Everyone.
# Level 2: Only show "Interesting" rights, i.e. those that can be used for local privilege escalation or remote access.
# Level 1: All non-default.
######
$GPOIsInteresting = $false
$GPOIsVulnerable = $false
$uraSettings = ($polXml.Computer.ExtensionData.Extension.UserRightsAssignment)
$uraSettings = ($uraSettings | ? {$_}) #Strips null elements from array - nfi why I was getting so many of these.
if ($uraSettings) {
foreach ($setting in $uraSettings) {
$settingIsInteresting = $false
$settingIsVulnerable = $false
$rightIsInteresting = $false
$userRight = $setting.Name
$members = @()
foreach ($member in $setting.Member) {
$members += ($member.Name.Innertext)
}
# if the right being assigned is in our array of interesting rights, the setting is interesting.
if ($intRights -contains $userRight) {
$GPOisinteresting = $true
$settingIsInteresting = $true
$rightIsInteresting = $true
}
# then we construct an array of trustees being granted the right, so we can see if they are in any of our interesting low priv groups.
if ($rightIsInteresting) {
foreach ($lowPrivGroup in $intLowPrivGroups) {
foreach ($member in $members) {
if ($member -match $lowPrivGroup) {
$GPOIsVulnerable = $true
$settingIsVulnerable = $true
}
}
}
}
if ((($settingIsVulnerable) -And ($level -le 3)) -Or (($settingIsInteresting) -And ($level -le 2)) -Or ($level -eq 1)) {
$output = @{}
$output.Add("Right", $userRight)
$output.Add("Members", $members -join ',')
Write-NoEmpties -output $output
}
}
}
if ($GPOisinteresting) {
$Global:GPOsWithIntSettings += 1
}
if ($GPOIsVulnerable) {
$Global:GPOsWithVulnSettings += 1
}
}
Function Get-GPOSchedTasks {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for scheduled tasks being configured on a host.
# Level 3: Only show instances where a password has been set.
# Level 2: TODO If a password has been set or the thing being run is non-local or there are arguments set.
# Level 1: All scheduled tasks.
######
$GPOisinteresting = $false
$GPOisvulnerable = $false
$tasktypes = @()
$tasktypes += $polXml.ExtensionData.Extension.ScheduledTasks.Task
$tasktypes += $polXml.ExtensionData.Extension.ScheduledTasks.ImmediateTask
$tasktypes += $polXml.ExtensionData.Extension.ScheduledTasks.TaskV2
$settingsSchedTasks = $tasktypes | Sort-Object GPOSettingOrder
if ($settingsSchedTasks) {
foreach ($setting in $settingsSchedTasks) {
#see if we have any stored encrypted passwords
$cpasswordcrypt = $setting.properties.cpassword
if ($cpasswordcrypt) {
$GPOisvulnerable = $true
$GPOisinteresting = $true
# decrypt it with harmj0y's function
$cpasswordclear = Get-DecryptedCpassword -Cpassword $cpasswordcrypt
}
#see if any arguments have been set
$taskArgs = $setting.Properties.args
if ($taskArgs) {
$GPOisinteresting = $true
}
#if so, or if we're showing everything, or if there are args and we're at level 2, show the setting.
if ((($cpasswordcrypt) -And ($level -le 3)) -Or ($level -le 2)) {
$output = @{}
$output.Add("Name", $setting.Properties.name)
$output.Add("runAs", $setting.Properties.runAs)
$output.Add("Password", $($cpasswordclear, "Password Not Set" -ne $null)[0])
$output.Add("Action", $setting.Properties.action)
$output.Add("appName", $setting.Properties.appName)
$output.Add("args", $setting.Properties.args)
$output.Add("startIn", $setting.Properties.startIn)
Write-NoEmpties -output $output
if ($setting.Properties.Triggers) {
foreach ($trigger in $setting.Properties.Triggers) {
$output = @{}
$output.Add("type", $trigger.Trigger.type)
$output.Add("startHour", $trigger.Trigger.startHour)
$output.Add("startMinutes", $trigger.Trigger.startMinutes)
Write-NoEmpties -output $output
}
}
}
}
}
if ($GPOisinteresting) {
$Global:GPOsWithIntSettings += 1
}
if ($GPOisvulnerable) {
$Global:GPOsWithVulnSettings += 1
}
}
Function Get-GPOMSIInstallation {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for MSI installers being used to install software.
# Level 3: TODO Only show instances where the file is writable by the current user or 'Everyone' or 'Domain Users' or 'Authenticated Users'.
# Level 2: All MSI installations.
# Level 1: All MSI installations.
######
$MSIInstallation = ($polXml.ExtensionData.Extension.MsiApplication | Sort-Object GPOSettingOrder)
if ($MSIInstallation) {
$GPOisinteresting = $true
$GPOisvulnerable = $false
foreach ($setting in $MSIInstallation) {
$output = @{}
$MSIPath = $setting.Path
$output.Add("Name", $setting.Name)
$output.Add("Path", $MSIPath)
if ($Global:onlineChecks) {
if ($MSIPath.StartsWith("\\")) {
$ACLData = Find-IntACL -Path $MSIPath
$output.Add("Owner",$ACLData["Owner"])
if ($ACLData["Vulnerable"] -eq "True") {
$settingIsVulnerable = $true
$GPOisvulnerable = $true
$output.Add("[!]", "Source file writable by current user!")
}
$MSIPathAccess = $ACLData["Trustees"]
}
}
if (($level -le 2) -Or (($level -le 3) -And ($settingisVulnerable))) {
Write-NoEmpties -output $output
""
if ($MSIPathAccess) {
Write-Title -Text "Permissions on source file:" -DividerChar "-"
Write-Output $MSIPathAccess
""
}
}
}
}
if ($GPOisinteresting) {
$Global:GPOsWithIntSettings += 1
}
if ($GPOisvulnerable) {
$Global:GPOsWithVulnSettings += 1
}
}
Function Get-GPOScripts {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for startup/shutdown/logon/logoff scripts.
# Level 3: TODO Only show instances where the file is writable by the current user or 'Everyone' or 'Domain Users' or 'Authenticated Users'.
# Level 2: All scripts.
# Level 1: All scripts.
######
$settingsScripts = ($polXml.ExtensionData.Extension.Script | Sort-Object GPOSettingOrder)
if ($settingsScripts) {
$GPOisinteresting = $true
$GPOisvulnerable = $false
foreach ($setting in $settingsScripts) {
$commandPath = $setting.Command
$output = @{}
$output.Add("Command", $commandPath)
$output.Add("Type", $setting.Type)
$output.Add("Parameters", $setting.Parameters)
$settingIsVulnerable = $false
if ($Global:onlineChecks) {
if ($commandPath.StartsWith("\\")) {
$ACLData = Find-IntACL -Path $commandPath
$output.Add("Owner",$ACLData["Owner"])
if ($ACLData["Vulnerable"] -eq "True") {
$settingIsVulnerable = $true
$GPOisvulnerable = $true
$output.Add("[!]", "Source file writable by current user!")
}
$commandPathAccess = $ACLData["Trustees"]
}
}
if (($level -le 2) -Or (($level -le 3) -And ($settingisVulnerable))) {
Write-NoEmpties -output $output
""
if ($commandPathAccess) {
Write-Title -Text "Permissions on source file:" -DividerChar "-"
Write-Output $commandPathAccess
""
}
}
}
}
if ($GPOisinteresting) {
$Global:GPOsWithIntSettings += 1
}
if ($GPOisvulnerable) {
$Global:GPOsWithVulnSettings += 1
}
}
Function Get-GPOFileUpdate {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for files being copied/updated/whatever.
# Level 3: TODO Only show instances where the 'fromPath' file is writable by the current user or 'Everyone' or 'Domain Users' or 'Authenticated Users'.
# Level 2: All File Updates where FromPath is a network share
# Level 1: All File Updates.
######
$settingsFiles = ($polXml.ExtensionData.Extension.FilesSettings | Sort-Object GPOSettingOrder)
if ($settingsFiles) {
$GPOisinteresting = $true
$GPOisvulnerable = $false
foreach ($setting in $settingsFiles.File) {
$fromPath = $setting.Properties.fromPath
$targetPath = $setting.Properties.targetPath
$output = @{}
$output.Add("Name", $setting.name)
$output.Add("Action", $setting.Properties.action)
$output.Add("fromPath", $fromPath)
$output.Add("targetPath", $targetPath)
$settingIsVulnerable = $false
if ($Global:onlineChecks) {
if ($fromPath.StartsWith("\\")) {
$ACLData = Find-IntACL -Path $fromPath
$output.Add("Owner",$ACLData["Owner"])
if ($ACLData["Vulnerable"] -eq "True") {
$settingIsVulnerable = $true
$GPOisvulnerable = $true
$output.Add("[!]", "Source file writable by current user!")
}
$fromPathAccess = $ACLData["Trustees"]
}
}
if (($level -le 2) -Or (($level -le 3) -And ($settingisVulnerable))) {
Write-NoEmpties -output $output
""
if ($fromPathAccess) {
Write-Title -Text "Permissions on source file:" -DividerChar "-"
Write-Output $fromPathAccess
""
}
}
}
}
if ($GPOisinteresting) {
$Global:GPOsWithIntSettings += 1
}
if ($GPOisvulnerable) {
$Global:GPOsWithVulnSettings += 1
}
}
Function Get-GPOFilePerms {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for changes to local file permissions.
# Level 3: TODO Only show instances where the file is writable by the current user or 'Everyone' or 'Domain Users' or 'Authenticated Users'.
# Level 2: TODO Also show instances where any user/group other than the usual default Domain/Enterprise Admins has 'Full Control'.
# Level 1: All file permission changes.
######
$settingsFilePerms = ($polXml.Computer.ExtensionData.Extension.File | Sort-Object GPOSettingOrder)
if ($settingsFilePerms) {
foreach ($setting in $settingsFilePerms) {
if ($level -eq 1) {
$output = @{}
$output.Add("Path", $setting.Path)
$output.Add("SDDL", $setting.SecurityDescriptor.SDDL.innertext)
Write-NoEmpties -output $output
}
}
}
}
Function Get-GPOSecurityOptions {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for potentially vulnerable "Security Options" settings.
# Level 3: TODO.
# Level 2: Show everything that matches $intKeyNames or $intSysAccPolName.
# Level 1: All settings.
######
$GPOisinteresting = $false
$settingsSecurityOptions = ($polXml.Computer.ExtensionData.Extension.SecurityOptions | Sort-Object GPOSettingOrder)
if ($settingsSecurityOptions) {
if ($level -le 2) {
$intKeyNameBools = @{}
$intKeyNameBools.Add("MACHINE\System\CurrentControlSet\Control\Lsa\DisableDomainCreds", "false")
$intKeyNameBools.Add("MACHINE\System\CurrentControlSet\Control\Lsa\EveryoneIncludesAnonymous", "true")
$intKeyNameBools.Add("MACHINE\System\CurrentControlSet\Control\Lsa\LimitBlankPasswordUse", "false")
$intKeyNameBools.Add("MACHINE\System\CurrentControlSet\Control\Lsa\NoLMHash", "false")
$intKeyNameBools.Add("MACHINE\System\CurrentControlSet\Control\Lsa\RestrictAnonymous", "false")
$intKeyNameBools.Add("MACHINE\System\CurrentControlSet\Control\Lsa\RestrictAnonymousSAM", "false")
$intKeyNameBools.Add("MACHINE\System\CurrentControlSet\Control\Lsa\SubmitControl", "true")
$intKeyNameBools.Add("MACHINE\System\CurrentControlSet\Control\Lsa\UseMachineId", "true")
$intKeyNameBools.Add("MACHINE\System\CurrentControlSet\Control\Print\Providers\LanMan Print Services\Servers\AddPrinterDrivers", "false")
$intKeyNameLists = @()
$intKeyNameLists += "MACHINE\System\CurrentControlSet\Control\SecurePipeServers\Winreg\AllowedExactPaths\Machine"
$intKeyNameLists += "MACHINE\System\CurrentControlSet\Control\SecurePipeServers\Winreg\AllowedPaths\Machine"
$intKeyNameLists += "MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\NullSessionPipes"
$intKeyNameLists += "MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\NullSessionShares"
$intKeyNameLists += "MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\RestrictNullSessAccess"
$intSysAccPolBools = @{}
$intSysAccPolBools.Add("EnableGuestAccount", 1)
$intSysAccPolBools.Add("EnableAdminAccount", 1)
$intSysAccPolBools.Add("LSAAnonymousNameLookup", 1)
$intSysAccPolStrings = @{}
$intSysAccPolStrings.Add("NewAdministratorName", "")
$intSysAccPolStrings.Add("NewGuestName", "")
foreach ($setting in $settingsSecurityOptions) {
#Check if it's a registry based option
if ($setting.KeyName) {
$keyname = $setting.KeyName
$output = @{}
$values = @{}
$foundit = 0
if ($foundit -eq 0) {
if ($intKeyNameLists -contains $keyname) {
$GPOisinteresting = $true
$foundit = 1
$output.Add("Name", $setting.Display.Name)
$output.Add("KeyName", $setting.KeyName)
$dispstrings = $setting.Display.DisplayStrings.Value
#here we have to iterate over the list of values
$i = 0
foreach ($dispstring in $dispstrings) {
$values.Add("Path/Pipe$i", $dispstring)
$i += 1
}
Write-NoEmpties -output $output
Write-NoEmpties -output $values
}
}
if ($foundit -eq 0) {
foreach ($intKeyNameBool in $intKeyNamesBools) {
if (($keyNameBool.ContainsKey($keyname)) -And ($keyNameBool.ContainsValue($setting.Display.DisplayBoolean))) {
$GPOIsInteresting =1
$foundit = 1
$output.Add("Name", $setting.Display.Name)
$output.Add("KeyName", $setting.KeyName)
$values.Add("DisplayBoolean", $setting.Display.Displayboolean)
Write-NoEmpties -output $output
Write-NoEmpties -output $values
}
}
}
}
# or a 'system access policy name'
elseif ($setting.SystemAccessPolicyName) {
$output = @{}
foreach ($SAP in $intSysAccPolBools) {
if (($SAP.ContainsKey($setting.SystemAccessPolicyName)) -And ($SAP.ContainsValue($setting.SettingNumber))) {
$output.Add("Name", $setting.SystemAccessPolicyName)
$output.Add("SettingNumber",$setting.SettingNumber)
$GPOisinteresting = $true
Write-NoEmpties -output $output
}
}
foreach ($SAP in $intSysAccPolStrings) {
if ($SAP.ContainsKey($setting.SystemAccessPolicyName)) {
$output.Add("Name", $setting.SystemAccessPolicyName)
$output.Add("SettingString",$setting.SettingString)
$GPOisinteresting = $true
Write-NoEmpties -output $output
}
}
}
}
}
}
if ($GPOisinteresting) {
$Global:GPOsWithIntSettings += 1
}
}
Function Get-GPORegKeys {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for registry keys being set that may contain sensitive information.
# Level 3: Any key that matches '$intKeys'.
# Level 2: TODO Also show instances containing the strings 'pass', 'pwd', 'cred', or 'vnc'.
# Level 1: All Registry Keys
######
$GPOisinteresting = $false
$GPOisvulnerable = $false
$settingsRegKeys = ($polXml.ExtensionData.Extension.RegistrySettings.Registry | Sort-Object GPOSettingOrder)
$vulnKeys = @()
$vulnKeys += "Software\Network Associates\ePolicy Orchestrator"
$vulnKeys += "SOFTWARE\FileZilla Server"
$vulnKeys += "SOFTWARE\Wow6432Node\FileZilla Server"
$vulnKeys += "Software\Wow6432Node\McAfee\DesktopProtection - McAfee VSE"
$vulnKeys += "Software\McAfee\DesktopProtection - McAfee VSE"
$vulnKeys += "Software\ORL\WinVNC3"
$vulnKeys += "Software\ORL\WinVNC3\Default"
$vulnKeys += "Software\ORL\WinVNC\Default"
$vulnKeys += "Software\RealVNC\WinVNC4"
$vulnKeys += "Software\RealVNC\Default"
$vulnKeys += "Software\TightVNC\Server"
$vulnKeys += "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$intWords = @()
$intWords += "vnc"
$intWords += "vpn"
$intWords += "pwd"
$intWords += "cred"
$intWords += "key"
$intWords += "pass"
if ($settingsRegKeys) {
foreach ($setting in $settingsRegKeys) {
$settingkey = $setting.Properties.key
$settingisInteresting = $false
$settingIsVulnerable = $false
if ($vulnKeys -Contains $settingkey) {
$GPOisvulnerable = $true
$settingIsVulnerable = $true
}
foreach ($intWord in $intWords) {
# if either key or value include our interesting words as a substring, mark the setting as interesting
if (($settingkey -match $intWord) -Or ($settingValue -match $intWord)) {
$GPOisinteresting = $true
$settingisInteresting = $true
}
}
# if setting matches any of our criteria for printing (combined interest level + output level)
if ((($settingisVulnerable) -And ($level -le 3)) -Or (($settingisInteresting) -And ($level -le 2)) -Or ($level -eq 1)) {
$output = @{}
$output.Add("Key", $settingkey)
$output.Add("Action", $setting.Properties.action)
$output.Add("Hive", $setting.Properties.hive)
$output.Add("Name", $setting.Properties.name)
$output.Add("Value", $setting.Properties.value)
Write-NoEmpties -output $output
}
}
}
# update the global counters
if ($GPOisivulnerable) {
$Global:GPOsWithVulnSettings += 1
}
if ($GPOisinteresting) {
$Global:GPOsWithIntSettings += 1
}
}
Function Get-GPOFolderRedirection {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for user Folder redirections.
# Level 3: TODO Only show instances where DestPath is writable by the current user or 'Everyone' or 'Domain Users' or 'Authenticated Users'.
# Level 2: TODO Also show instances where any user/group other than the usual default Domain/Enterprise Admins has 'Full Control'.
# Level 1: All Folder Redirection.
######
$settingsFolderRedirection = ($polXml.User.ExtensionData.Extension.Folder | Sort-Object GPOSettingOrder)
if ($settingsFolderRedirection) {
foreach ($setting in $settingsFolderRedirection) {
if ($level -eq 1) {
$output = @{}
$output.Add("DestPath", $setting.Location.DestinationPath)
$output.Add("Target Group", $setting.Location.SecurityGroup.Name.innertext)
$output.Add("Target SID", $setting.Location.SecurityGroup.SID.innertext)
$output.Add("ID", $setting.Id)
Write-NoEmpties -output $output
}
}
}
}
Function Get-GPOAccountSettings {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for Account Settings.
# Level 3: TODO
# Level 2: If it matches our list of interesting settings - undecided if i want to include weak password policy here.
# Level 1: All Account Settings.
######
$settingsAccount = ($polXml.Computer.ExtensionData.Extension.Account | Sort-Object GPOSettingOrder)
$GPOisinteresting = $false
$intAccSettingBools = @{}
$intAccSettingBools.Add("ClearTextPassword","true")
if ($settingsAccount) {
foreach ($setting in $settingsAccount) {
$settingName = $setting.Name
$settingisInteresting = $false
foreach ($intAccSetting in $intAccSettingBools) {
if (($intAccSetting.ContainsKey($settingName)) -And ($intAccSetting.containsValue($setting.SettingBoolean))) {
$settingisInteresting = $true
$GPOisinteresting = $true
}
}
if (($level -eq 1) -Or (($settingisInteresting) -And ($level -le 2))) {
$output = @{}
$output.Add("Name", $settingName)
if ($setting.SettingBoolean) {
$output.Add("SettingBoolean", $setting.SettingBoolean)
}
if ($setting.SettingNumber) {
$output.Add("SettingNumber", $setting.SettingNumber)
}
$output.Add("Type", $setting.Type)
Write-NoEmpties -output $output
}
}
}
# update the global counters
if ($GPOisinteresting) {
$Global:GPOsWithIntSettings += 1
}
}
Function Get-GPOFolders {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for creation/renaming of local folders
# Level 3: TODO
# Level 2: TODO Need to generate a list of 'interesting' settings.
# Level 1: All folders changes.
######
$settingsFolders = ($polXml.ExtensionData.Extension.Folders.Folder | Sort-Object GPOSettingOrder)
if ($settingsFolders) {
foreach ($setting in $settingsFolders) {
if ($level -eq 1) {
$output = @{}
$output.Add("Name", $setting.name)
$output.Add("Action", $setting.Properties.action)
$output.Add("Path", $setting.Properties.path)
Write-NoEmpties -output $output
}
}
}
}
Function Get-GPONetworkShares {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for Network Shares being created on hosts.
# Level 3: TODO
# Level 2: All Network Shares.
# Level 1: All Network Shares.
######
$GPOisinteresting = $false
$settingsNetShares = ($polXml.Computer.ExtensionData.Extension.NetworkShares.Netshare | Sort-Object GPOSettingOrder)
if ($settingsNetShares) {
foreach ($setting in $settingsNetShares) {
if ($level -le 2) {
$GPOisinteresting = $true
$output = @{}
$output.Add("Name", $setting.name)
$output.Add("Action", $setting.Properties.action)
$output.Add("PropName", $setting.Properties.name)
$output.Add("Path", $setting.Properties.path)
$output.Add("Comment", $setting.Properties.comment)
Write-NoEmpties -output $output
}
}
}
if ($GPOisinteresting) {
$Global:GPOsWithIntSettings += 1
}
}
Function Get-GPOFWSettings {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Xml.XmlElement]$polXML,
[Parameter(Mandatory=$true)][ValidateSet(1,2,3)][int]$level
)
######
# Description: Checks for changes to Firewall Rules.
# Level 3: TODO
# Level 2: TODO
# Level 1: Show all Firewall settings
######
if ($level -le 2) {
if ($polXml.Computer.ExtensionData.Extension.PrivateProfile.EnableFirewall -ne $null) {
$output = [ordered]@{}
$output.Add("Firewall Profile","PrivateProfile")
$output.Add("DefaultInboundAction",$polXml.Computer.ExtensionData.Extension.PrivateProfile.DefaultInboundAction.Value)
$output.Add("DefaultOutboundAction",$polXml.Computer.ExtensionData.Extension.PrivateProfile.DefaultOutboundAction.Value)
$output.Add("EnableFirewall",$polXml.Computer.ExtensionData.Extension.PrivateProfile.EnableFirewall.Value)
Write-NoEmpties -output $output
""
}
if ($polXml.Computer.ExtensionData.Extension.PublicProfile.EnableFirewall -ne $null) {
$output = [ordered]@{}
$output.Add("Firewall Profile","PublicProfile")
$output.Add("DefaultInboundAction",$polXml.Computer.ExtensionData.Extension.PublicProfile.DefaultInboundAction.Value)
$output.Add("DefaultOutboundAction",$polXml.Computer.ExtensionData.Extension.PublicProfile.DefaultOutboundAction.Value)
$output.Add("EnableFirewall",$polXml.Computer.ExtensionData.Extension.PublicProfile.EnableFirewall.Value)
Write-NoEmpties -output $output
""
}