-
Notifications
You must be signed in to change notification settings - Fork 148
/
analyze-ad.go
1767 lines (1605 loc) · 65.4 KB
/
analyze-ad.go
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
package analyze
import (
"encoding/binary"
"sort"
"strconv"
"strings"
"time"
"github.com/gofrs/uuid"
"github.com/lkarlslund/adalanche/modules/engine"
"github.com/lkarlslund/adalanche/modules/integrations/activedirectory"
"github.com/lkarlslund/adalanche/modules/ui"
"github.com/lkarlslund/adalanche/modules/util"
"github.com/lkarlslund/adalanche/modules/windowssecurity"
)
// Interesting permissions on AD
var (
ResetPwd, _ = uuid.FromString("{00299570-246d-11d0-a768-00aa006e0529}")
DSReplicationGetChanges = uuid.UUID{0x11, 0x31, 0xf6, 0xaa, 0x9c, 0x07, 0x11, 0xd1, 0xf7, 0x9f, 0x00, 0xc0, 0x4f, 0xc2, 0xdc, 0xd2}
DSReplicationGetChangesAll = uuid.UUID{0x11, 0x31, 0xf6, 0xad, 0x9c, 0x07, 0x11, 0xd1, 0xf7, 0x9f, 0x00, 0xc0, 0x4f, 0xc2, 0xdc, 0xd2}
DSReplicationSyncronize = uuid.UUID{0x11, 0x31, 0xf6, 0xab, 0x9c, 0x07, 0x11, 0xd1, 0xf7, 0x9f, 0x00, 0xc0, 0x4f, 0xc2, 0xdc, 0xd2}
DSReplicationGetChangesInFilteredSet, _ = uuid.FromString("{89e95b76-444d-4c62-991a-0facbeda640c}")
AttributeMember = uuid.UUID{0xbf, 0x96, 0x79, 0xc0, 0x0d, 0xe6, 0x11, 0xd0, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2}
AttributeSetGroupMembership, _ = uuid.FromString("{BC0AC240-79A9-11D0-9020-00C04FC2D4CF}")
AttributeSIDHistory = uuid.UUID{0x17, 0xeb, 0x42, 0x78, 0xd1, 0x67, 0x11, 0xd0, 0xb0, 0x02, 0x00, 0x00, 0xf8, 0x03, 0x67, 0xc1}
AttributeAllowedToActOnBehalfOfOtherIdentity, _ = uuid.FromString("{3F78C3E5-F79A-46BD-A0B8-9D18116DDC79}")
AttributeMSDSGroupMSAMembership = uuid.UUID{0x88, 0x8e, 0xed, 0xd6, 0xce, 0x04, 0xdf, 0x40, 0xb4, 0x62, 0xb8, 0xa5, 0x0e, 0x41, 0xba, 0x38}
AttributeGPLink, _ = uuid.FromString("{F30E3BBE-9FF0-11D1-B603-0000F80367C1}")
AttributeMSDSKeyCredentialLink, _ = uuid.FromString("{5B47D60F-6090-40B2-9F37-2A4DE88F3063}")
AttributeSecurityGUIDGUID, _ = uuid.FromString("{bf967924-0de6-11d0-a285-00aa003049e2}")
AttributeAltSecurityIdentitiesGUID, _ = uuid.FromString("{00FBF30C-91FE-11D1-AEBC-0000F80367C1}")
AttributeProfilePathGUID, _ = uuid.FromString("{bf967a05-0de6-11d0-a285-00aa003049e2}")
AttributeScriptPathGUID, _ = uuid.FromString("{bf9679a8-0de6-11d0-a285-00aa003049e2}")
AttributeMSDSManagedPasswordId, _ = uuid.FromString("{0e78295a-c6d3-0a40-b491-d62251ffa0a6}")
AttributeUserAccountControlGUID, _ = uuid.FromString("{bf967a68-0de6-11d0-a285-00aa003049e2}")
AttributePwdLastSetGUID, _ = uuid.FromString("{bf967a0a-0de6-11d0-a285-00aa003049e2}")
ExtendedRightCertificateEnroll, _ = uuid.FromString("{0e10c968-78fb-11d2-90d4-00c04f79dc55}")
ExtendedRightCertificateAutoEnroll, _ = uuid.FromString("{a05b8cc2-17bc-4802-a710-e7c15ab866a2}")
ValidateWriteSelfMembership, _ = uuid.FromString("{bf9679c0-0de6-11d0-a285-00aa003049e2}")
ValidateWriteSPN, _ = uuid.FromString("{f3a64788-5306-11d1-a9c5-0000f80367c1}")
ObjectGuidUser, _ = uuid.FromString("{bf967aba-0de6-11d0-a285-00aa003049e2")
ObjectGuidComputer, _ = uuid.FromString("{bf967a86-0de6-11d0-a285-00aa003049e2")
ObjectGuidGroup, _ = uuid.FromString("{bf967a9c-0de6-11d0-a285-00aa003049e2")
ObjectGuidDomain, _ = uuid.FromString("{19195a5a-6da0-11d0-afd3-00c04fd930c9")
ObjectGuidDNSZone, _ = uuid.FromString("{e0fa1e8b-9b45-11d0-afdd-00c04fd930c9")
ObjectGuidDNSNode, _ = uuid.FromString("{e0fa1e8c-9b45-11d0-afdd-00c04fd930c9")
ObjectGuidGPO, _ = uuid.FromString("{f30e3bc2-9ff0-11d1-b603-0000f80367c1")
ObjectGuidOU, _ = uuid.FromString("{bf967aa5-0de6-11d0-a285-00aa003049e2")
ObjectGuidAttributeSchema, _ = uuid.FromString("{BF967A80-0DE6-11D0-A285-00AA003049E2}")
AdministratorsSID, _ = windowssecurity.ParseStringSID("S-1-5-32-544")
BackupOperatorsSID, _ = windowssecurity.ParseStringSID("S-1-5-32-551")
PrintOperatorsSID, _ = windowssecurity.ParseStringSID("S-1-5-32-550")
ServerOperatorsSID, _ = windowssecurity.ParseStringSID("S-1-5-32-549")
EnterpriseDomainControllers, _ = windowssecurity.ParseStringSID("S-1-5-9")
GPLinkCache = engine.NewAttribute("gpLinkCache")
EdgePublishesCertificateTemplate = engine.NewEdge("PublishCertTmpl").Tag("Informative").RegisterProbabilityCalculator(activedirectory.NotAChance)
NetBIOSName = engine.NewAttribute("nETBIOSName")
NCName = engine.NewAttribute("nCName")
DNSRoot = engine.NewAttribute("dnsRoot")
ObjectTypeMachine = engine.NewObjectType("Machine", "Machine")
DomainJoinedSID = engine.NewAttribute("domainJoinedSid").Merge()
DnsHostName = engine.NewAttribute("dnsHostName")
EdgeAuthenticatesAs = engine.NewEdge("AuthenticatesAs")
EdgeMachineAccount = engine.NewEdge("MachineAccount").RegisterProbabilityCalculator(func(source, target *engine.Object) engine.Probability {
return -1 // Just informative
}).Describe("Indicates this is the domain joined computer account belonging to the machine")
)
var warnedgpos = make(map[string]struct{})
func init() {
engine.AddMergeApprover("Only merge Machine objects with other Machine objects", func(a, b *engine.Object) (*engine.Object, error) {
if a.Type() == ObjectTypeMachine && b.Type() != ObjectTypeMachine {
return nil, engine.ErrDontMerge
} else if b.Type() == ObjectTypeMachine && a.Type() != ObjectTypeMachine {
return nil, engine.ErrDontMerge
}
return nil, nil
})
Loader.AddProcessor(func(ao *engine.Objects) {
// Find LAPS or return
var lapsGUID uuid.UUID
if lapsobjects, found := ao.FindMulti(engine.Name, engine.AttributeValueString("ms-Mcs-AdmPwd")); found {
lapsobjects.Iterate(func(lapsobject *engine.Object) bool {
if lapsobject.HasAttrValue(engine.ObjectClass, engine.AttributeValueString("attributeSchema")) {
if objectGUID, ok := lapsobject.OneAttrRaw(activedirectory.SchemaIDGUID).(uuid.UUID); ok {
ui.Debug().Msg("Detected LAPS schema extension GUID")
lapsGUID = objectGUID
return false // break
} else {
ui.Error().Msgf("Could not read LAPS schema extension GUID from %v", lapsobject.DN())
}
}
return true
})
}
if lapsGUID.IsNil() {
ui.Debug().Msg("Microsoft LAPS not detected, skipping tests for this")
return
}
ao.Iterate(func(o *engine.Object) bool {
// Only for computers
if o.Type() != engine.ObjectTypeComputer {
return true
}
// ... that has LAPS installed
if !o.HasAttr(activedirectory.MSmcsAdmPwdExpirationTime) {
return true
}
// Analyze ACL
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
// Link to the machine object
machinesid := o.SID()
if machinesid.IsBlank() {
ui.Fatal().Msgf("Computer account %v has no objectSID", o.DN())
}
machine, found := ao.Find(DomainJoinedSID, engine.AttributeValueSID(machinesid))
if !found {
ui.Error().Msgf("Could not locate machine for domain SID %v", machinesid)
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_CONTROL_ACCESS, lapsGUID, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(machine, activedirectory.EdgeReadLAPSPassword)
}
}
return true
})
}, "Reading local admin passwords via LAPS", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
if o.Type() != engine.ObjectTypeContainer || o.OneAttrString(engine.Name) != "Machine" {
return true
}
// Only for computers, you can't really pwn users this way
p, hasparent := ao.DistinguishedParent(o)
if !hasparent || p.Type() != engine.ObjectTypeGroupPolicyContainer {
return true
}
p.EdgeTo(o, activedirectory.PartOfGPO)
return true
})
}, "Machine configurations that are part of a GPO", engine.BeforeMergeHigh)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
if o.Type() != engine.ObjectTypeContainer || o.OneAttrString(engine.Name) != "User" {
return true
}
// Only for users, you can't really pwn users this way
p, hasparent := ao.DistinguishedParent(o)
if !hasparent || p.Type() != engine.ObjectTypeGroupPolicyContainer {
return true
}
p.EdgeTo(o, activedirectory.PartOfGPO)
return true
})
}, "User configurations that are part of a GPO", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// It's a group
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for _, acl := range sd.DACL.Entries {
if acl.Type == engine.ACETYPE_ACCESS_DENIED || acl.Type == engine.ACETYPE_ACCESS_DENIED_OBJECT {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeACLContainsDeny) // Not a probability of success, this is just an indicator
}
}
return true
})
}, "Indicator for possible false positives, as the ACL contains DENY entries", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
// https://www.alsid.com/crb_article/kerberos-delegation/
// --- Citation bloc --- This is generally true, but an exception exists: positioning a Deny for the OWNER RIGHTS SID (S-1-3-4) in an object’s ACE removes the owner’s implicit control of this object’s DACL. ---------------------
aclhasdeny := false
for _, ace := range sd.DACL.Entries {
if ace.Type == engine.ACETYPE_ACCESS_DENIED && ace.SID == windowssecurity.OwnerSID {
aclhasdeny = true
}
}
if !sd.Owner.IsNull() && !aclhasdeny {
ao.FindOrAddAdjacentSID(sd.Owner, o).EdgeTo(o, activedirectory.EdgeOwns)
}
return true
})
}, "Indicator that someone owns an object", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_GENERIC_ALL, uuid.Nil, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeGenericAll)
}
}
return true
})
}, "Indicator that someone has full permissions on an object", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_GENERIC_WRITE, uuid.Nil, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWriteAll)
}
}
return true
})
}, "Indicator that someone can write to all attributes and do all validated writes on an object", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY, uuid.Nil, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWritePropertyAll)
}
}
return true
})
}, "Indicator that someone can write to all attributes of an object", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY_EXTENDED, uuid.Nil, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWriteExtendedAll)
}
}
return true
})
}, "Indicator that someone do all validated writes on an object", engine.BeforeMergeFinal)
// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/c79a383c-2b3f-4655-abe7-dcbb7ce0cfbe IMPORTANT
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_WRITE_OWNER, uuid.Nil, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeTakeOwnership)
}
}
return true
})
}, "Indicator that someone is allowed to take ownership of an object", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_WRITE_DACL, uuid.Nil, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWriteDACL)
}
}
return true
})
}, "Indicator that someone can change permissions on an object", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
sd, err := o.SecurityDescriptor()
if o.Type() != engine.ObjectTypeAttributeSchema {
return true
}
// FIXME - check for SYSTEM ATTRIBUTES - these can NEVER be changed
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY, AttributeSecurityGUIDGUID, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWriteAttributeSecurityGUID) // Experimental, I've never run into this misconfiguration
}
}
return true
})
}, `Allows an attacker to modify the attribute security set of an attribute, promoting it to a weaker attribute set (experimental/wrong)`, engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only users, computers and service accounts
if o.Type() != engine.ObjectTypeUser && o.Type() != engine.ObjectTypeComputer {
return true
}
// Check who can reset the password
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_CONTROL_ACCESS, ResetPwd, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeResetPassword)
}
}
return true
})
}, "Indicator that a group or user can reset the password of an account", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only managed service accounts
if o.Type() != engine.ObjectTypeManagedServiceAccount && o.Type() != engine.ObjectTypeGroupManagedServiceAccount {
return true
}
// Check who can reset the password
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_READ_PROPERTY, AttributeMSDSManagedPasswordId, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeReadPasswordId)
}
}
return true
})
}, "Indicator that a group or user can read the msDS-ManagedPasswordId for use in MGSA Golden attack", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
authusers := FindWellKnown(ao, windowssecurity.AuthenticatedUsersSID)
if authusers == nil {
ui.Error().Msgf("Could not locate Authenticated Users")
return
}
ao.Iterate(func(o *engine.Object) bool {
// Only computers and users
if o.Type() != engine.ObjectTypeUser {
return true
}
if o.Attr(activedirectory.ServicePrincipalName).Len() > 0 {
o.SetValues(engine.MetaHasSPN, engine.AttributeValueInt(1))
authusers.EdgeTo(o, activedirectory.EdgeHasSPN)
}
return true
})
}, "Indicator that a user has a ServicePrincipalName and an authenticated user can Kerberoast it", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
everyone := FindWellKnown(ao, windowssecurity.EveryoneSID)
if everyone == nil {
ui.Error().Msgf("Could not locate Everyone")
return
}
ao.Iterate(func(o *engine.Object) bool {
// Only users
if o.Type() != engine.ObjectTypeUser {
return true
}
if uac, ok := o.AttrInt(activedirectory.UserAccountControl); ok && uac&engine.UAC_DONT_REQ_PREAUTH != 0 {
everyone.EdgeTo(o, activedirectory.EdgeDontReqPreauth)
}
return true
})
}, "Indicator that a user has \"don't require preauth\" and can be kerberoasted", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only users
if o.Type() != engine.ObjectTypeUser {
return true
}
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY, ValidateWriteSPN, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWriteSPN)
}
}
return true
})
}, "Indicator that a user can change the ServicePrincipalName attribute, and then Kerberoast the account", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only computers and users
if o.Type() != engine.ObjectTypeUser {
return true
}
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY_EXTENDED, ValidateWriteSPN, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWriteValidatedSPN)
}
}
return true
})
}, "Indicator that a user can change the ServicePrincipalName attribute (validate write), and then Kerberoast the account", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only computers
if o.Type() != engine.ObjectTypeComputer {
return true
}
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY, AttributeAllowedToActOnBehalfOfOtherIdentity, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWriteAllowedToAct) // Success rate?
}
}
return true
})
}, `Modify the msDS-AllowedToActOnBehalfOfOtherIdentity on a computer to enable any SPN enabled user to impersonate anyone else`, engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only for groups
if o.Type() != engine.ObjectTypeGroup {
return true
}
// It's a group
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY, AttributeMember, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeAddMember)
}
}
return true
})
}, "Permission to add a member to a group", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only for groups
if o.Type() != engine.ObjectTypeGroup {
return true
}
// It's a group
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY, AttributeSetGroupMembership, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeAddMemberGroupAttr)
}
}
return true
})
}, "Permission to add a member to a group (via attribute set)", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only for groups
if o.Type() != engine.ObjectTypeGroup {
return true
}
// It's a group
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY_EXTENDED, ValidateWriteSelfMembership, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeAddSelfMember)
}
}
return true
})
}, "Permission to add yourself to a group", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
o.Attr(activedirectory.MSDSGroupMSAMembership).Iterate(func(msads engine.AttributeValue) bool {
sd, err := engine.ParseSecurityDescriptor([]byte(msads.String()))
if err == nil {
for _, acl := range sd.DACL.Entries {
if acl.Type == engine.ACETYPE_ACCESS_ALLOWED {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeReadMSAPassword)
}
}
}
return true
})
return true
})
}, "Allows someone to read a password of a managed service account", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only for users
if o.Type() != engine.ObjectTypeUser {
return true
}
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY, AttributeAltSecurityIdentitiesGUID, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWriteAltSecurityIdentities)
}
}
return true
})
}, "Allows an attacker to define a certificate that can be used to authenticate as the user", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only for users
if o.Type() != engine.ObjectTypeUser {
return true
}
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY, AttributeProfilePathGUID, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWriteProfilePath)
}
}
return true
})
}, "Change user profile path (allows an attacker to trigger a user auth against an attacker controlled UNC path)", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only for users
if o.Type() != engine.ObjectTypeUser {
return true
}
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY, AttributeScriptPathGUID, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWriteScriptPath)
}
}
return true
})
}, "Change user script path (allows an attacker to trigger a user auth against an attacker controlled UNC path)", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
o.Attr(activedirectory.MSDSHostServiceAccount).Iterate(func(dn engine.AttributeValue) bool {
if targetmsa, found := ao.Find(engine.DistinguishedName, dn); found {
o.EdgeTo(targetmsa, activedirectory.EdgeHasMSA)
}
return true
})
return true
})
}, "Indicates that the object has a service account in use", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
// Only for groups
if o.Type() != engine.ObjectTypeUser && o.Type() != engine.ObjectTypeComputer {
return true
}
// It's a group
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_WRITE_PROPERTY, AttributeMSDSKeyCredentialLink, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeWriteKeyCredentialLink)
}
}
return true
})
}, "Allows you to write your own cert to keyCredentialLink, and then auth as that user (no password reset needed)", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
o.Attr(activedirectory.SIDHistory).Iterate(func(sidval engine.AttributeValue) bool {
if sid, ok := sidval.Raw().(windowssecurity.SID); ok {
target := ao.FindOrAddAdjacentSID(sid, o)
o.EdgeTo(target, activedirectory.EdgeSIDHistoryEquality)
}
return true
})
return true
})
}, "Indicates that object has a SID History attribute pointing to the other object, making them the 'same' permission wise", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_CONTROL_ACCESS, uuid.Nil, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeAllExtendedRights)
}
}
return true
})
}, "Indicates that you have all extended rights", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
if o.Type() != engine.ObjectTypePKIEnrollmentService {
return true
}
o.Attr(engine.A("certificateTemplates")).Iterate(func(val engine.AttributeValue) bool {
templates, _ := ao.FindMulti(engine.Name, val)
templates.Iterate(func(template *engine.Object) bool {
if template.Type() == engine.ObjectTypeCertificateTemplate {
o.EdgeTo(template, EdgePublishesCertificateTemplate)
}
return true
})
return true
})
return true
})
}, "Certificate service publishes Certificate Template", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
if o.Type() != engine.ObjectTypeCertificateTemplate {
return true
}
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-crtd/211ab1e3-bad6-416d-9d56-8480b42617a4
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_CONTROL_ACCESS, ExtendedRightCertificateEnroll, ao) ||
sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_VOODOO_BIT, uuid.Nil, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeCertificateEnroll)
}
}
return true
})
}, "Permission to enroll into a certificate template", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
if o.Type() != engine.ObjectTypeCertificateTemplate {
return true
}
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-crtd/211ab1e3-bad6-416d-9d56-8480b42617a4
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_CONTROL_ACCESS, ExtendedRightCertificateAutoEnroll, ao) ||
sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_VOODOO_BIT, uuid.Nil, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeCertificateAutoEnroll)
}
}
return true
})
}, "Permission to auto-enroll into a certificate template", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_VOODOO_BIT, uuid.Nil, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeVoodooBit)
}
}
return true
})
}, "Has the Voodoo Bit set", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
ao.Iterate(func(o *engine.Object) bool {
if o.Type() != engine.ObjectTypeDomainDNS {
return true
}
if !o.HasAttr(activedirectory.SystemFlags) {
return true
}
sd, err := o.SecurityDescriptor()
if err != nil {
return true
}
for index, acl := range sd.DACL.Entries {
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_CONTROL_ACCESS, DSReplicationSyncronize, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeDSReplicationSyncronize)
}
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_CONTROL_ACCESS, DSReplicationGetChanges, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeDSReplicationGetChanges)
}
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_CONTROL_ACCESS, DSReplicationGetChangesAll, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeDSReplicationGetChangesAll)
}
if sd.DACL.IsObjectClassAccessAllowed(index, o, engine.RIGHT_DS_CONTROL_ACCESS, DSReplicationGetChangesInFilteredSet, ao) {
ao.FindOrAddAdjacentSID(acl.SID, o).EdgeTo(o, activedirectory.EdgeDSReplicationGetChangesInFilteredSet)
}
}
// Add the DCsync combination flag
o.Edges(engine.In).Range(func(target *engine.Object, edge engine.EdgeBitmap) bool {
if edge.IsSet(activedirectory.EdgeDSReplicationGetChanges) && edge.IsSet(activedirectory.EdgeDSReplicationGetChangesAll) {
// DCsync attack WOT WOT
target.EdgeTo(o, activedirectory.EdgeDCsync)
}
return true
})
return true
})
}, "Permissions on DomainDNS objects leading to DCsync attacks", engine.BeforeMergeFinal)
Loader.AddProcessor(func(ao *engine.Objects) {
// Ensure everyone has a family
ao.Iterate(func(computeraccount *engine.Object) bool {
if computeraccount.Type() != engine.ObjectTypeComputer {
return true
}
sid := computeraccount.OneAttr(engine.ObjectSid)
if sid == nil {
ui.Error().Msgf("Computer account without SID: %v", computeraccount.DN())
return true
}
machine, _ := ao.FindOrAdd(
DomainJoinedSID, sid,
engine.IgnoreBlanks,
engine.Name, computeraccount.Attr(engine.Name),
activedirectory.ObjectCategorySimple, "Machine",
DnsHostName, computeraccount.Attr(DnsHostName),
)
// ui.Debug().Msgf("Added machine for SID %v", sid.String())
machine.EdgeTo(computeraccount, EdgeAuthenticatesAs)
machine.EdgeTo(computeraccount, EdgeMachineAccount)
machine.ChildOf(computeraccount)
return true
})
},
"creating Machine objects (representing the machine running the OS)",
engine.BeforeMerge)
Loader.AddProcessor(func(ao *engine.Objects) {
// Ensure everyone has a family
ao.Iterate(func(o *engine.Object) bool {
potentialorphan := o
for {
if potentialorphan.Parent() != nil {
return true
}
if potentialorphan == ao.Root() {
return true
}
if parent, found := ao.DistinguishedParent(potentialorphan); found {
potentialorphan.ChildOf(parent)
return true
}
dn := potentialorphan.DN()
if potentialorphan.Type() == engine.ObjectTypeDomainDNS && len(dn) > 3 && strings.EqualFold("dc=", dn[:3]) {
// Top of some AD we think, hook to top of browsable tree
o.ChildOf(ao.Root())
return true
}
// Create a synthetic parent
parentdn := util.ParentDistinguishedName(potentialorphan.DN())
if parentdn == "" {
return true
}
ui.Debug().Msgf("AD object %v (%v) has no parent :-( - creating synthetic object", o.Label(), o.DN())
newparent := ao.AddNew(
engine.DistinguishedName, parentdn,
engine.Description, "Synthetic parent object",
)
potentialorphan.ChildOf(newparent)
potentialorphan = newparent // loop, to ensure new objects also have parents
}
})
},
"applying parent/child relationships",
engine.BeforeMergeHigh)
Loader.AddProcessor(func(ao *engine.Objects) {
type domaininfo struct {
suffix string
name string
}
var domains []domaininfo
results, found := ao.FindMulti(engine.ObjectClass, engine.AttributeValueString("crossRef"))
if !found {
ui.Error().Msg("No domainDNS object found, can't apply DownLevelLogonName to objects")
return
}
results.Iterate(func(o *engine.Object) bool {
// Store domain -> netbios name in array for later
dn := o.OneAttrString(NCName)
netbiosname := o.OneAttrString(NetBIOSName)
if dn == "" || netbiosname == "" {
// Some crossref objects have no NCName or NetBIOSName, skip them
return true // continue
}
domains = append(domains, domaininfo{
suffix: dn,
name: netbiosname,
})
return true
})
if len(domains) == 0 {
ui.Error().Msg("No NCName to NetBIOSName mapping found, can't apply DownLevelLogonName to objects")
return
}
// Sort the domains so we match on longest first
sort.Slice(domains, func(i, j int) bool {
// Less is More - so we sort in reverse order
return len(domains[i].suffix) > len(domains[j].suffix)
})
// Apply DownLevelLogonName to relevant objects
ao.Iterate(func(o *engine.Object) bool {
if !o.HasAttr(engine.SAMAccountName) {
return true
}
dn := o.DN()
for _, domaininfo := range domains {
if strings.HasSuffix(dn, domaininfo.suffix) {
o.SetValues(engine.DownLevelLogonName, engine.AttributeValueString(domaininfo.name+"\\"+o.OneAttrString(engine.SAMAccountName)))
break
}
}
return true
})
ao.DropIndex(engine.DownLevelLogonName)
},
"applying DownLevelLogonName attribute",
engine.BeforeMergeLow)
Loader.AddProcessor(func(ao *engine.Objects) {
// Add domain part attribute from distinguished name to objects
ao.Iterate(func(o *engine.Object) bool {
// Only objects with a DistinguishedName
if o.DN() == "" {
return true
}
if o.HasAttr(engine.DomainContext) {
return true
}
parts := strings.Split(o.DN(), ",")
lastpart := -1
for i := len(parts) - 1; i >= 0; i-- {
part := parts[i]
if len(part) < 3 || !strings.EqualFold("dc=", part[:3]) {
break
}
if strings.EqualFold("DC=ForestDNSZones", part) || strings.EqualFold("DC=DomainDNSZones", part) {
break
}
lastpart = i
}
if lastpart != -1 {
o.SetValues(engine.DomainContext, engine.AttributeValueString(strings.Join(parts[lastpart:], ",")))
}
return true
})
},
"applying domain part attribute",
engine.BeforeMergeLow)
Loader.AddProcessor(func(ao *engine.Objects) {
// Find all the AdminSDHolder containers
ao.Filter(func(o *engine.Object) bool {
return strings.HasPrefix(o.OneAttrString(engine.DistinguishedName), "CN=AdminSDHolder,CN=System,")
}).Iterate(func(adminsdholder *engine.Object) bool {
// We found it - so we know it can change ACLs of some objects
domaincontext := adminsdholder.OneAttrString(engine.DomainContext)
// Are some groups excluded?
excluded_mask := 0
// Find dsHeuristics, this defines groups EXCLUDED From AdminSDHolder application
// https://social.technet.microsoft.com/wiki/contents/articles/22331.adminsdholder-protected-groups-and-security-descriptor-propagator.aspx#What_is_a_protected_group
if ds, found := ao.Find(engine.DistinguishedName, engine.AttributeValueString("CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,"+domaincontext)); found {
excluded := ds.OneAttrString(activedirectory.DsHeuristics)
if len(excluded) >= 16 {
excluded_mask = strings.Index("0123456789ABCDEF", strings.ToUpper(string(excluded[15])))
}
}
ao.Filter(func(o *engine.Object) bool {
// Check if object is a group
if o.Type() != engine.ObjectTypeGroup {
return false
}
// Only this "local" AD (for multi domain analysis)
if o.OneAttrString(engine.DomainContext) != domaincontext {
return false
}
return true
}).Iterate(func(o *engine.Object) bool {
grpsid := o.SID()
if grpsid.IsNull() {
return true
}
switch grpsid.RID() {
case DOMAIN_USER_RID_ADMIN:
case DOMAIN_USER_RID_KRBTGT:
case DOMAIN_GROUP_RID_ADMINS:
case DOMAIN_GROUP_RID_CONTROLLERS:
case DOMAIN_GROUP_RID_SCHEMA_ADMINS:
case DOMAIN_GROUP_RID_ENTERPRISE_ADMINS:
case DOMAIN_GROUP_RID_READONLY_CONTROLLERS:
case DOMAIN_ALIAS_RID_ADMINS:
case DOMAIN_ALIAS_RID_ACCOUNT_OPS:
if excluded_mask&1 != 0 {
return true
}
case DOMAIN_ALIAS_RID_SYSTEM_OPS:
if excluded_mask&2 != 0 {
return true
}