PORT 1433/tcp - Microsoft SQL Server
Introduction
Microsoft SQL Server is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applicationsโwhich may run either on the same computer or on another computer across a network.
RCE With Credentials
sqsh
In MSSQL there is a procedure called xp_cmdshell that receives a command from Windows, executes it and return the result as rows of text. Although the most common case is that the user of the application does not have permissions to execute the xp_cmdshell procedure because is disabled by default, it has been seen on several occasions that, due to a misconfiguration, it does have permissions to enable it.
We need to configure xp_cmdshell
.
Once configured we can execute commands with sqsh
or crackmapexec
.
crackmapexec
We can execute code in a easier way with crackmapexec.
SQL Injection in MSSQL
To understand the vulnerability visit the following page link.
SQL InjectionSome SQLi payloads are the following (supposing that the original query return two values):
We can also append commands on the query and execute commands with the procedure xp_cmdshell.
LFI or File Download to RCE
If we are able to download any file of the system and has the MSSQL port open, we can retrieved the sa hash.
We need to download a copy of the master.mdf file located on:
Since the file is running we can not read it, so we need to find a backup. Some backups are available here:
Once downloaded we can dump the hashes with XPN script.
Note: The code fails while trying to load OrcaMDF dlls, see the following pull request to fix it.
File changed:
We just need to import the module and extract the hashes.
We can crack it with Hashcat (mode 1731).
Once obtained the credentials we can execute code with crackmapexec
or sqsh
.
References
Last updated
Was this helpful?