Acting on your behalf
Sometimes a server needs to reach another service as you: a web app fetching your files from a file server. Active Directory allows this with delegation.
The dangerous kind is unconstrained delegation: a machine trusted this way can act as anyone who connects to it, including a domain admin. One such machine is a key to the directory. You will find one and take the trust away.
The one rule
Warning
Read and change delegation only in your own lab directory. Changing trust settings on a directory that is not yours needs written permission. In the UK, without it, it can break the Computer Misuse Act 1990.
Quick check: the rule
Have a go
Quick check: the rule
3 questionsBy the end of this lesson
Note
I can find accounts trusted for unconstrained delegation and remove the trust safely.
Key words
| Word | What it means | Example |
|---|---|---|
| Delegation | letting a service reach another service as the user | |
| Unconstrained | the machine may act as anyone who connects to it | |
| Constrained | the machine may act as users only toward named services | |
| userAccountControl | a number whose bits are an account's flags | 0x80000 is the delegation bit |
| Domain controller | legitimately trusted for delegation; never a finding |
The cells students fill in are left blank in this preview.
Starter
Have a go
Starter
3 questionsFind unconstrained delegation
The delegation trust is one bit in userAccountControl, value 0x80000 (524288). The audit asks the directory for every account with that bit set, using a bitwise LDAP filter.
Two come back: WEB01$, an ordinary host that should not be trusted this way, and DC01$, the domain controller, which is legitimately trusted. The finding is WEB01$.
Find accounts trusted for unconstrained delegation
sudo ldbsearch -H /var/lib/samba/private/sam.ldb '(userAccountControl:1.2.840.113556.1.4.803:=524288)' sAMAccountNameShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check
Have a go
Check
3 questionsWhy one host is a key to everything
When a user connects to a host trusted for unconstrained delegation, the directory hands that host the user's own ticket-granting ticket. The host keeps it. If a domain admin ever connects, the host now holds their TGT and can act as them anywhere.
That is why WEB01$ matters and DC01$ does not. The domain controller already holds everyone's keys by design, so trusting it changes nothing. An ordinary web server holding a domain admin's ticket is a disaster.
A common mistake
Warning
People see two results and raise two findings. The domain controller is not one. An audit that flags DC01$ as a problem wastes a day and trains people to ignore the report. Know what is meant to be there before you alert on it.
Take the trust away
The right fix is usually constrained delegation, where a host may act as users only toward the few named services it truly needs (msDS-AllowedToDelegateTo). If the host needs no delegation at all, remove the bit.
Here you clear the flag on WEB01$ by setting its userAccountControl back to a plain workstation value, then run the audit again. Only the domain controller remains.
Clear the delegation flag on WEB01$
printf 'dn: CN=WEB01,CN=Computers,DC=ad,DC=college,DC=lab\nchangetype: modify\nreplace: userAccountControl\nuserAccountControl: 4096\n' | sudo ldbmodify -H /var/lib/samba/private/sam.ldbShown here, not run. Press Start lab to type it into your own lab’s terminal.
Run the audit again
sudo ldbsearch -H /var/lib/samba/private/sam.ldb '(userAccountControl:1.2.840.113556.1.4.803:=524288)' sAMAccountNameShown here, not run. Press Start lab to type it into your own lab’s terminal.
What you fixed
WEB01$ no longer holds anyone's keys, and the audit now returns only the domain controller, which is correct. In lesson 6 you will see who the real keys belong to, and how to watch them.
First, the assignment: an audit that reports unconstrained delegation and never counts a domain controller.
Assignment: report risky delegation
The delegation trust is one bit of userAccountControl, the value 524288 (0x80000).
Write two functions.
is_unconstrained(uac) takes an integer userAccountControl and returns True if the 524288 bit is set, otherwise False.
risky(accounts) takes a list of accounts. Each is a dictionary with name (a string), uac (an integer) and is_dc (True if the account is a domain controller). Return a sorted list of the names that are trusted for unconstrained delegation and are not domain controllers, because a domain controller is legitimately trusted and is never a finding.
def is_unconstrained(uac):
return False
def risky(accounts):
return []
Make a free account to save your work and track your progress.
Exit quiz
Have a go