Forest HTB Writeup
Step 1. Reconnaissance & Enumeration
It was found that nmap is taking long time. Therefore used masscan to scan all ports of forest machine.
masscan -e tun0 -p1-65535,U:1-65535 10.10.10.161 --rate=1000
nmap -Pn -n -sC -sV -p<port numbers></port> 10.10.10.151 -oA version_scan
Interesting. An Active Directory forest as the name suggests with one domain HTB? We find the users using one of the below method.
We get the domain users as below.
Step 2. Initial Foothold
Once we have domain users. Let’s give it a shot to GetNPUsers.py
, which attempts to list and get TGTs for users that have the property “Do not require Kerberos preauthentication” set. You can find the nice explaination about impacket here.
From nmap scan we know that there are LDAP, kerberos, and a kpasswd service, in addition to SMB services. This suggests that we just scanned a domain controller. We also have 5985 open, so we can use that to get a shell with evil-winrm eventually.
Step 3. Privilege Escalation
Great, we owned user! Now, let’s get working on root. To do so, I’m going to use a very useful tool in AD and that is a bit hard to understand at first: BloodHound.
This software uses graph theory in order to analyze the relations between AD objects, and find interesting attack paths. It relies on a neo4j SGBD, so you might want to install this utility before using BloodHound. Installation link can be found here.
However, if we launch BloodHound just like that, it won’t help you lots because you first need to give it data to process. I know two ways of doing so:
- There is a BloodHound’s version which is Python based and that connects directly to the target, provided correct credentials, and gathers all needed information: this can be found here. The python based ingestor can be installed with
pip install bloodhound
- There is a separate BloodHound ingestor called SharpHound. It comes in two version: an executable file that can be uploaded to the host then ran, and a Powershell script that we’re going to use right into Evil-WinRM. You can find SharpHound here.
Here I’ll be using the second method. First, I downloaded the script SharpHound.ps1 in a directory called scripts, then I launched an Evil-WinRM session with the following command:
evil-winrm -i 10.10.10.161 -u svc-alfresco -P 5985 -p s3rvice -s "scripts/"
The script is then uploaded and imported using one of the following methods.
After uploading date_bloodhound.zip file to bloodhound we get the domain map needed to get to the administrator.
Now we can use aclpwn or do it manually.
Manual Addition instead of aclpwn
I picked the route of creating a separate user account that I can add to the Exchange Windows Permissions group. I connect with evil-winrm as svc-alfresco to create the following user account and add it to all the required groups:
After that, we can use Impacket’s ntlmrelayx.py
to escalate TestUser’s privileges
Using ACLPWN
If you choose to use aclpwn. Make sure neo4j is running in bakground and you have already imported data to bloodhound.
Dont forget to logout and login after addition of user or user escalation.
Now we can use Impacket’s secretsdump.py
with TestUser’s credentials to dump all the password hasses contained in the NTDS.DIT file on 10.10.10.161.
With the Admin hash obtained through secretsdump.py
, we can use wmiexec.py
to connect as Administrator.
And root flag can be found as below.
Remove the TestUser account.
Note: do not forget to restore the changes you did with aclpwn. When using aclpwn, the utility told us that a restore file has been saved under the name aclpwn-xxx.restore. To use it, we simply use the following command:
Thanks for reading my writeup and thank you to hackthebox.eu and the machine creators.
References: