Hack The Box: Nest

Jump Ahead: EnumInitial CredsUserRootResources


To solve this machine, we began by enumerating open services – finding only ports 445 and 4386 open. While enumerating SMB, we found credentials for the TempUser user. Using the credentials, we enumerated SMB once again. This time, we found hashed credentials for the c.smith user. Additionally, we found an information disclosure to a hidden share folder, via a Notepad++ config file. Looking at the files in the hidden location, we found what appears to be the code to decrypt the password for c.smith. Next, we took the code and supplied config file to decrypt the password. Using the decrypted password, we were able to use SMB as c.smith, and grab user.txt. Looking at the remote service on port 4386, we learned of a debug feature. To use it, we needed a password, which we were able to retrieve from an Alternate Data Stream (ADS) to a file appearing to be empty. Using the debug feature to navigate the file system, we found encrypted credentials for Administrator, as well as an executable to use in order to decrypt the password. Using the decrypted credentials, we were able to get root.txt.


Like all targets, we begin by enumerating the open ports using nmap – finding ports 445 and 4386 to be open.

$ nmap -p- -Pn -v --min-rate 3000 $RHOST
$ nmap -p 445,4386 -A -Pn -oA scans/nmap/tcp-all-scripts $RHOST

# Nmap 7.80 scan initiated Sat Apr  4 08:01:07 2020 as: nmap -p 445,4386 -A -Pn -oA scans/nmap/tcp-all-scripts
Nmap scan report for
Host is up (0.048s latency).

445/tcp  open  microsoft-ds?
4386/tcp open  unknown
| fingerprint-strings: 
|   DNSStatusRequestTCP, DNSVersionBindReqTCP, Kerberos, LANDesk-RC, LDAPBindReq, LDAPSearchReq, LPDString, NULL, RPCCheck, SMBProgNeg, SSLSessionReq, TLSSessionReq, TerminalServer, TerminalServerCookie, X11Probe: 
|     Reporting Service V1.2
|   FourOhFourRequest, GenericLines, GetRequest, HTTPOptions, RTSPRequest, SIPOptions: 
|     Reporting Service V1.2
|     Unrecognised command
|   Help: 
|     Reporting Service V1.2
|     This service allows users to run queries against databases using the legacy HQK format
|     LIST
|     SETDIR <Directory_Name>
|     RUNQUERY <Query_ID>
|     DEBUG <Password>
|_    HELP <Command>
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :

Host script results:
|_clock-skew: 2m54s
| smb2-security-mode: 
|   2.02: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2020-04-04T13:06:41
|_  start_date: 2020-04-04T12:56:28

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Sat Apr  4 08:04:26 2020 -- 1 IP address (1 host up) scanned in 199.14 seconds

Next, we start to enumerate smb using smbmap – finding anonymous authentication to be enabled.

Initial Credentials

Using smbmap, we learn that 2 shares have anonymous read capability – Data and Users.

$ smbmap -u guest -H $RHOST

Recursively listing the shares, we get usernames, and 2 files that we can retrieve – \Shared\Maintenance\Maintenance Alerts.txt and \Shared\Templates\HR\Welcome Email.txt.

$ smbmap -u guest -H $RHOST -R Users
$ smbmap -u guest -H $RHOST -R Data

Using smbclient.py, we are able to retrieve the files for further examination. Looking at the welcome email, we obtain credentials for TempUser.

Getting User

Using the credentials of TempUser, we enumerate SMB again – this time gaining read-only access to the Secure$ share. Using smbget, we download all the files from each share to our local system for further analysis.

$ smbmap -u TempUSer -p password -H
$ smbget -R -U TempUser smb://
$ smbget -R -U TempUser smb://$
$ smbget -R -U TempUser smb://

Using a recursive grep, we searched for files that may potentially have creds. Doing this, we find what appears to be a base64 encoded/encrypted password for c.smith – located within \IT\Configs\RU Scanner\RU_config.xml. Additionally, we learn of a Notepad++ config file, which we look at further, obtaining information about a shared folder owned by Carl that we couldn’t previously see.

$ grep -RHEi '(user.*|pass.*)' ./
$ cat '/IT/Configs/RU Scanner/RU_config.xml'
$ cat '/IT/Configs/NotepadPlusPlus/config.xml'

Using smbget, we download those files as well.

$ smbget -U TempUser -R smb://$/IT/Carl

Looking at Carl‘s files, it appears that we now have the source code for RU Scanner. Within it, looks like a function capable of decrypting the creds for c.smith that we previously found in \IT\Configs\RU Scanner\RU_config.xml. To decrypt the password, we will need to open the RUScanner project in Visual Studio (as denoted by the RUScanner.sln file in the project root). Once opened in Visual Studio, we check the main method, seeing that it requires the configuration file to be in the same path. Additionally, we edit the code to print the decrypted password to the console. Lastly, we built the solution and run it – obtaining the password for c.smith.

Using smbmap, we are able to validate the credentials, as well as get read-only access to Carl’s user directory. Using smbget to download the files, we get access to user.txt.

Getting Root

Looking at the HQK Reporting folder in c.smith‘s home directory, we see several files. The HQK_Config_Backup.xml file contains information about the service running on port 4386. Using telnet to connect to this service, we run help to see what commands we can run. We see there is a debug command, which we learn will provide additional functionality once we run it with the correct password. We tried to run it with previous passwords we’ve found, however, none appear to be correct.

Remembering the Debug Mode Password.txt file in the HQK Reporting directory, we look at it, but we see that it’s empty. Given the remote machine is Windows based, we make the assumption that the file may contain an Alternate Data Stream (ADS). Because ADSs are a feature of the NTFS file system, we can’t extract the ADS on our Kali system. Using smbclient, we can use the allinfo command to get the name of the ADS, then download it. Doing so, we read the file, getting the debug password.

Enabling the debug mode on the remote service, we gain 3 new commands – service, session, and showquery. Making use of the setdir and showquery commands, we are able to get encrypted credentials for Administrator in C:\Program Files\HQK\LDAP\Ldap.conf.

In the same directory, we see an executable named HqkLdap.exe that we previously downloaded from c.smith/HQK Reporting/AD Integration Module on the Users share. Given previous paths forward, we make the assumption that this executable decrypts the password. To decrypt the password, we save the executable and Ldap.conf file on our Windows machine in the same directory. Using dnspy to decompile/debug the application, we navigate to MainModule and set a breakpoint on line 53.

Line 30 shows a check for HqkDbImport.exe, but we don’t have it, so we create an empty file with that name in the local directory. Now, we run the program until it hits the break point. In the locals window, we open the ldapSearchSettings array, and got the password. Using the password with the username, we can use psexec to get access to the machine, and get root.txt.

Thank you for taking the time to read my write-up. I am interested in other ways this machine has been solved. Feel free to reach out to me and we can discuss it. Thanks!