authentication-delegation

Kerberos delegation allows for an account to impersonate another Active Directory account. The impersonating account needs to have the Trust_To_Authenticate_For_Delegation (T2A4D) set. If the flag is set, the impersonating account can request a token on behalf of another user without the target user's password.

When T2A4D is set, the impersonating account can request a forwardable token which allows the impersonating account to use the token for other services.

To be able to set the Trusted_To_Authenticate_For_Delegation flag and set ms-DS-AllowedToDelegate service, the controlling account must have SeEnableDelegationPrivilege.

To be able to use a user account for impersonating another user, the impersonating user needs to have the permissions SeTcbPrivilege and SeImpersonate.

  • This is usually reserved for the SYSTEM user

If you can create a computer account and set the Trusted_To_Authenticate_For_Delegation along with the ms-DS-AllowedToDelegate, you can use that account to escalate privileges.

Types of Delegation

Unconstrained Delegation

This was the initial answer to the problem in (available in Windows 2000) of allowing a service to authenticate as another user to another server. However, after being quickly abused, Microsoft came up with the later version, Constrained Delegation, which we will talk about later. When a user authenticates to the impersonating service, the user's TGT is included with the TGS. The impersonating service then extracts the TGT and uses it to request TGS for the target service.

Unconstrained delegation allows a user with TrustedForDelegation set to impersonate any user that does not have NOT_DELEGATED set to any service. This causes what is now a very obvious vulnerability if that service ever gets take over.

Finding

Get-ADCOmputer -Filter {TruststedForDelegation -eq $True -and primarygrupid -eq 515} -Properties TrustedForDelegation,ServicePrincipalName,Description,TrustedToAuthForDelegation,msDS-AllowedToDelegateTo,PrincipalsAllowedToDelegateToAccount

or

Get-ADComputer -LDAPFilter "(userAccountControl:1.2.840.113556.1.4.803:=524288)"

Abusing

Constrained Delegation & Protocol Transition

User Uses Kerberos Authentication

This delegation requires the user to get the Ticket Granting Service (TGS) ticket to access the impersonating service using the S4U2Proxy Kerberos add-on. The impersonating service will then use that TGS to authenticate to another service on the user's behalf. The ticket given to the impersonating service needs to have the FORWARDABLE flag set. This flag will never get set for any user with USER_NOT_DELEGATED set to true or for members in the "Protected Users" group.

Constrained delegation became available in Windows 2003.

User Uses Any Protocol Other Than Kerberos

The issue with unconstrained delegation is that it limits users to authenticate using only Kerberos. When this is not possible, a service may still need to act on behalf of another user. To solve this issue Microsoft came up with the S4U2Self and TrustedToAuthForDelegation (T2A4D). If a user authenticates to an impersonating service with T2A4D using any protocol other than Kerberos, the impersonating service will user S4U2Self to request a TGS from an authentication service which it will then present using S4U2Proxy.

This is only possible when the T2A4U flag is set for a specific service account that will use S4U2Self.

Abusing

Resource Based Constrained Delegation

This type of delegation allows for the delegation settings to be set on the resource service instead of the impersonating account. The delegation is implemented on the resource service through the msDS-AllowedToActOnBehalfOfOtherIdentity property. This property is is stored as binary bytes.

Abusing

Requirements

Steps

If you do not have access to a user with these permissions all is not lost. You may be able to create one out of thin air. Check to see if the domain has the ms-DS-MachineAccountQuota set.

There is not an easy way to query to see if a particular user has the ability to create any more machine accounts. To determine if the user can create another account, the attribute of ms-DS-CreatorSID is referenced on all machine accounts to see if the the user has created the max amount yet or not. So since the quota is determined dynamically and is not stored as an attribute of the user account, you will have to query all machine accounts and filter out only the ms-DS-CreatorSID that you are interested in.

This is not the only attack that can be done. You could consider a DCSync Attack. You can also attack this remotely and get code execution with Impacket tools.

Using getST.py,smbexec.py, ticketConverter.py,

PowerMad uses LDAP to create the new account instead of using New-ADComputer. From my testing, it seems like New-ADComputer will not work to create a machine account if the user only has the ability from the ms-DS-MachineAccountQuota attribute.

Script

This is an old script used to identify Kerberos delegation and highlight potential issues. This script came from here

References

  • https://labs.withsecure.com/publications/trust-years-to-earn-seconds-to-break

  • https://medium.com/r3d-buck3t/attacking-kerberos-constrained-delegations-4a0eddc5bb13

  • https://www.itprotoday.com/active-directory/most-confusing-dialog-box-active-directory

  • https://shenaniganslabs.io/2019/01/28/Wagging-the-Dog.html

  • https://blog.harmj0y.net/activedirectory/s4u2pwnage/

  • https://blog.harmj0y.net/redteaming/another-word-on-delegation/

  • https://blog.netwrix.com/2021/11/30/what-is-kerberos-delegation-an-overview-of-kerberos-delegation/

Last updated

Was this helpful?