HTB | Archetype | Write-Up

Summary:
This article guides users through completing the Archetype machine challenge on Hack The Box. We exploit vulnerabilities on a Microsoft SQL Server by enumerating SMB shares, finding clear text credentials, and using Impacket to authenticate and gain an authorized connection. We then escalate privileges and download Netcat to establish a reverse shell, grab the user flag, and eventually use Impacket's psexec tool to gain admin access and retrieve the root flag before terminating the connection.
Machine Name: Archetype | Difficulty: Easy | OS: Windows
The aim of this walkthrough is to provide help with the Archetype machine on the Hack The Box website. Please note that no flags are directly provided here. Moreover, be aware that this is only one of the many ways to solve the challenges.
It belongs to a series of tutorials that aim to help out complete beginners with finishing the Starting Point TIER 2 challenges.
Setup
There are a couple of ways to connect to the target machine. The one we will be using throughout this walkthrough is via the provided pwnbox.
Once our connection is taken care of, we spawn the target machine.
Additionally - even though not required - it is possible to set a local variable (only available in the current shell) containing our target host's IP address. Once set, we can easily access it by prepending a $ to our variable name.
┌─[htb-bluewalle@htb-pwdysfiide]─[~/Desktop]
└──╼ $rhost=<target-hosts-ip>
┌─[htb-bluewalle@htb-pwdysfiide]─[~/Desktop]
└──╼ $ echo $rhost
<target-hosts-ip>
┌─[htb-bluewalle@htb-pwdysfiide]─[~/Desktop]
└──╼ $
We could use the unset command to remove it after we no longer need it.
┌─[✗]─[htb-bluewalle@htb-pwdysfiide]─[~/Desktop]
└──╼ $unset rhost
┌─[htb-bluewalle@htb-pwdysfiide]─[~/Desktop]
└──╼ $
Task | 1
Question: Which TCP port is hosting a database server?
We start our recon with a quick connection check.
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$ ping $rhost -c 4
PING 10.129.63.163 (10.129.63.163) 56(84) bytes of data.
64 bytes from 10.129.63.163: icmp_seq=1 ttl=127 time=12.0 ms
64 bytes from 10.129.63.163: icmp_seq=2 ttl=127 time=11.4 ms
64 bytes from 10.129.63.163: icmp_seq=3 ttl=127 time=11.7 ms
64 bytes from 10.129.63.163: icmp_seq=4 ttl=127 time=11.4 ms
--- 10.129.63.163 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 11.352/11.636/12.018/0.265 ms
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$
Then we follow up on it with scanning the top 1000 tcp ports(version and script scan).
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$ nmap -sC -sV $rhost
Starting Nmap 7.93 ( https://nmap.org ) at 2023-05-11 14:33 BST
Nmap scan report for 10.129.63.163
Host is up (0.057s latency).
Not shown: 996 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
445/tcp open microsoft-ds Windows Server 2019 Standard 17763 microsoft-ds
1433/tcp open ms-sql-s Microsoft SQL Server 2017 14.00.1000.00; RTM
|_ssl-date: 2023-05-11T13:33:22+00:00; +1s from scanner time.
|_ms-sql-ntlm-info: ERROR: Script execution failed (use -d to debug)
| ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback
| Not valid before: 2023-05-11T13:25:34
|_Not valid after: 2053-05-11T13:25:34
|_ms-sql-info: ERROR: Script execution failed (use -d to debug)
Service Info: OSs: Windows, Windows Server 2008 R2 - 2012; CPE: cpe:/o:microsoft:windows
Host script results:
|_clock-skew: mean: 1h45m01s, deviation: 3h30m00s, median: 0s
| smb-os-discovery:
| OS: Windows Server 2019 Standard 17763 (Windows Server 2019 Standard 6.3)
| Computer name: Archetype
| NetBIOS computer name: ARCHETYPE\x00
| Workgroup: WORKGROUP\x00
|_ System time: 2023-05-11T06:33:14-07:00
| smb2-security-mode:
| 311:
|_ Message signing enabled but not required
| smb2-time:
| date: 2023-05-11T13:33:16
|_ start_date: N/A
| smb-security-mode:
| account_used: guest
| authentication_level: user
| challenge_response: supported
|_ message_signing: disabled (dangerous, but default)
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 16.32 seconds
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$
Four ports are reported to be open on our target. Additionally, there are some other interesting pieces of information to take note of:
- OS:Microsoft Windows
- sql server running on tcp port 1433
- guest login is enabled for port 445 (smb)
Let us capitalize on this information.
1433
Task | 2
Question: What is the name of the non-Administrative share available over SMB?
Using the guest username (guest-access) and listing the shares available on smb will directs us toward the backups share.
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$ smbclient -U guest -L $rhost
Password for [WORKGROUP\guest]:
Sharename Type Comment
--------- ---- -------
ADMIN$ Disk Remote Admin
backups Disk
C$ Disk Default share
IPC$ IPC Remote IPC
SMB1 disabled -- no workgroup available
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$
backups
Task | 3
Question: What is the password identified in the file on the SMB share?
Accessing the share and listing it's contents brings us to the - prod.dtsConfig - file.
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$ smbclient -U guest \\\\$rhost\\backups
Password for [WORKGROUP\guest]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Mon Jan 20 12:20:57 2020
.. D 0 Mon Jan 20 12:20:57 2020
prod.dtsConfig AR 609 Mon Jan 20 12:23:02 2020
5056511 blocks of size 4096. 2531250 blocks available
smb: \> get prod.dtsConfig
getting file \prod.dtsConfig of size 609 as prod.dtsConfig (12.1 KiloBytes/sec) (average 12.1 KiloBytes/sec)
smb: \> exit
After the download is finished, opening it on our local machine will bring us a nice surprise.
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$ cat prod.dtsConfig
<DTSConfiguration>
<DTSConfigurationHeading>
<DTSConfigurationFileInfo GeneratedBy="..." GeneratedFromPackageName="..." GeneratedFromPackageID="..." GeneratedDate="20.1.2019 10:01:34"/>
</DTSConfigurationHeading>
<Configuration ConfiguredType="Property" Path="\Package.Connections[Destination].Properties[ConnectionString]" ValueType="String">
<ConfiguredValue>Data Source=.;Password=M3g4c0rp123;User ID=ARCHETYPE\sql_svc;Initial Catalog=Catalog;Provider=SQLNCLI10.1;Persist Security Info=True;Auto Translate=False;</ConfiguredValue>
</Configuration>
</DTSConfiguration>
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$
Even though it looks like some configuration file, there are some potential credentials hidden there.
| potential credentials | |
|---|---|
| host | ARCHETYPE |
| username | sql_svc |
| password | M3g4c0rp123 |
But since proper recon is always the key, we make sure to check out the other shares too, even if they do not look that interesting at first sight.
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$ smbclient -U guest \\\\$rhost\\ADMIN$
Password for [WORKGROUP\guest]:
tree connect failed: NT_STATUS_ACCESS_DENIED
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$ smbclient -U guest \\\\$rhost\\IPC$
Password for [WORKGROUP\guest]:
Try "help" to get a list of possible commands.
smb: \> ls
NT_STATUS_NO_SUCH_FILE listing \*
smb: \> exit
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$
We were right, nothing interesting there. But still, it never hurts to check.
M3g4c0rp123
Task | 4
Question: What script from Impacket collection can be used in order to establish an authenticated connection to a Microsoft SQL Server?
Once we have Impacket installed, using the tab-autocomplete feature can help us out.
─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$ impacket-
impacket-addcomputer impacket-lookupsid impacket-rpcmap
impacket-atexec impacket-mimikatz impacket-sambaPipe
impacket-dcomexec impacket-mqtt_check impacket-samrdump
impacket-dpapi impacket-mssqlclient impacket-secretsdump
impacket-esentutl impacket-mssqlinstance impacket-services
impacket-exchanger impacket-netview impacket-smbclient
impacket-findDelegation impacket-nmapAnswerMachine impacket-smbexec
impacket-GetADUsers impacket-ntfs-read impacket-smbrelayx
impacket-getArch impacket-ntlmrelayx impacket-smbserver
impacket-GetNPUsers impacket-ping impacket-sniff
impacket-getPac impacket-ping6 impacket-sniffer
impacket-getST impacket-psexec impacket-split
impacket-getTGT impacket-raiseChild impacket-ticketConverter
impacket-GetUserSPNs impacket-rdp_check impacket-ticketer
impacket-goldenPac impacket-reg impacket-wmiexec
impacket-karmaSMB impacket-registry-read impacket-wmipersist
impacket-kintercept impacket-rpcdump impacket-wmiquery
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$ impacket-
Therefore, it will come down to these noteworthy fellows:
- impacket-mssqlclient
- impacket-mssqlinstance
Checking them both out should make our choice quite easy.
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$ impacket-mssqlclient --help
Impacket v0.10.1.dev1+20230316.112532.f0ac44bd - Copyright 2022 Fortra
usage: mssqlclient.py [-h] [-port PORT] [-db DB] [-windows-auth] [-debug] [-file FILE]
[-hashes LMHASH:NTHASH] [-no-pass] [-k] [-aesKey hex key]
[-dc-ip ip address]
target
TDS client implementation (SSL supported).
positional arguments:
target [[domain/]username[:password]@]<targetName or address>
optional arguments:
-h, --help show this help message and exit
-port PORT target MSSQL port (default 1433)
-db DB MSSQL database instance (default None)
-windows-auth whether or not to use Windows Authentication (default False)
-debug Turn DEBUG output ON
-file FILE input file with commands to execute in the SQL shell
authentication:
-hashes LMHASH:NTHASH
NTLM hashes, format is LMHASH:NTHASH
-no-pass don't ask for password (useful for -k)
-k Use Kerberos authentication. Grabs credentials from ccache file
(KRB5CCNAME) based on target parameters. If valid credentials cannot
be found, it will use the ones specified in the command line
-aesKey hex key AES key to use for Kerberos Authentication (128 or 256 bits)
-dc-ip ip address IP Address of the domain controller. If ommited it use the domain
part (FQDN) specified in the target parameter
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [★]$impacket-mssqlinstance --help
Impacket v0.10.1.dev1+20230316.112532.f0ac44bd - Copyright 2022 Fortra
usage: mssqlinstance.py [-h] [-timeout TIMEOUT] host
Asks the remote host for its running MSSQL Instances.
positional arguments:
host target host
optional arguments:
-h, --help show this help message and exit
-timeout TIMEOUT timeout to wait for an answer
┌─[eu-starting-point-vip-1-dhcp]─[10.10.14.46]─[htb-bluewalle@htb-9swjmh1jnx]─[~/archetype]
└──╼ [