sAMAccountName spoofing
CVE-2021-42278 and CVE-2021-42287
Theory
In November 2021, two vulnerabilities caught the attention of many security researchers as they could allow domain escalation from a standard user.
CVE-2021-42278 - Name impersonation
Computer accounts should have a trailing $
in their name (i.e. sAMAccountName
attribute) but no validation process existed to make sure of it. Abused in combination with CVE-2021-42287, it allowed attackers to impersonate domain controller accounts.
CVE-2021-42287 - KDC bamboozling
When requesting a Service Ticket, presenting a TGT is required first. When the service ticket is asked for is not found by the KDC, the KDC automatically searches again with a trailing $
. What happens is that if a TGT is obtained for bob
, and the bob
user gets removed, using that TGT to request a service ticket for another user to himself (S4U2self) will result in the KDC looking for bob$
in AD. If the domain controller account bob$
exists, then bob
(the user) just obtained a service ticket for bob$
(the domain controller account) as any other user 🤯.
As Elad Shamir said in his article Wagging the Dog, "S4U2Self works for a user marked as sensitive for delegation and a member of the Protected Users group".
Practice
Machine Account
The ability to edit a machine account's sAMAccountName
and servicePrincipalName
attributes is a requirement to the attack chain. The easiest way this can be achieved is by creating a computer account (e.g. by leveraging the MachineAccountQuota domain-level attribute if it's greater than 0). The creator of the new machine account has enough privileges to edit its attributes. Alternatively, taking control over the owner/creator of a computer account should do the job.
The attack can then be conducted as follows.
Clear the controlled machine account
servicePrincipalName
attribute of any value that points to its name (e.g.host/machine.domain.local
,RestrictedKrbHost/machine.domain.local
)Change the controlled machine account
sAMAccountName
to a Domain Controller's name without the trailing$
-> CVE-2021-42278Request a TGT for the controlled machine account
Reset the controlled machine account
sAMAccountName
to its old value (or anything else different than the Domain Controller's name without the trailing$
)Request a service ticket with S4U2self by presenting the TGT obtained before -> CVE-2021-42287
Get access to the domain controller (i.e. DCSync)
Some of the tools and features that allow exploitation of these vulnerabilities are still in development
Impacket's getST: https://github.com/SecureAuthCorp/impacket/pull/1202
Impacket's renameMachine: https://github.com/SecureAuthCorp/impacket/pull/1224
Enumerate
NetExec (Python) can be used to check if the target is vulnerable to NoPac.
Abuse
On UNIX-like systems, the steps mentioned above can be conducted with
krbelayx's (Python) addspn script for the manipulation of the computer's SPNs
Impacket's (Python) scripts (addcomputer, renameMachine, getTGT, getST, secretsdump) for all the other operations
When using Impacket's addcomputer script for the creation of a computer account, the "SAMR" method is used by default (instead of the LDAPS one). At the time of writing (10th of December, 2021), the SAMR method creates the account without SPNs, which allows to skip step #1.
In the screenshot below, the -spn
argument is used in the getST.py
command. The option is to be replaced with -altservice
.
User account
An alternative to using computer accounts is to have enough permissions against a user account (cf. Access Controls abuse) to edit its sAMAccountName
attribute (i.e. WriteProperty
on the attribute, or on the « general information » or « public information » property sets, or GenericWrite
, or GenericAll
).
This attack path also requires knowledge of the user account password or hash (to obtain a TGT), which can be obtained (or set) in many ways (e.g. Targeted Kerberoasting, Shadow Credentials, Forced Password Change).
Appart from the computer account creation and SPNs manipulation, the exploitation steps are the same as with a machine account. If the account has SPNs that point to its name, they will have to be removed for the renaming operation to work.
Resources
Last updated