1433 - Pentesting MSSQL - Microsoft SQL Server
Basic Information
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 (including the Internet). From wikipedia.
Default port: 1433
1433/tcp open ms-sql-s Microsoft SQL Server 2017 14.00.1000.00; RTMSearch for exploits/scripts/auxiliary modules that can be helpful to find vulnerabilities in this kind of service:
searchsploit "microsoft sql server"
nmap --script-help "*ms* and *sql*"
msf> search mssqlInformation
Default MS-SQL System Tables
master Database : Records all the system-level information for an instance of SQL Server.
msdb Database : Is used by SQL Server Agent for scheduling alerts and jobs.
model Database : Is used as the template for all databases created on the instance of SQL Server. Modifications made to the model database, such as database size, collation, recovery model, and other database options, are applied to any databases created afterwards.
Resource Database : Is a read-only database that contains system objects that are included with SQL Server. System objects are physically persisted in the Resource database, but they logically appear in the sys schema of every database.
tempdb Database : Is a work-space for holding temporary objects or intermediate result sets.
Info Gathering
If you don't know nothing about the service:
If you don't have credentials you can try to guess them. You can use nmap or metasploit. Be careful, you can block accounts if you fail login several times using an existing username.
Metasploit
****Brute force****
Tricks
Execute commands
NTLM Service Hash gathering
You can extract the NTLM hash of the user making the service authenticate against you. You should start a SMB server to capture the hash used in the authentication (impacket-smbserver or responder for example).
Abusing MSSQL trusted Links
****Read this post to find more information about how to abuse this feature
Read files executing scripts (Python and R)
MSSQL could allow you to execute scripts in Python and/or R. These code will be executed by a different user than the one using xp_cmdshell to execute commands.
Example trying to execute a 'R' "Hellow World!" not working:

Example using configured python to perform several actions:
From db_owner to sysadmin
If you have the credentials of a db_owner user, you can become sysadmin and execute commands
Impersonation of other users
IMPERSONATE privilege can lead to privilege escalation in SQL Server.
Using MSSQL for Persistence
https://blog.netspi.com/sql-server-persistence-part-1-startup-stored-procedures/
Having credentials
Mssqlclient.py
You can login into the service using impacket mssqlclient.py
sqsh

Manual
Post Explotation
The user running MSSQL server will have enabled the privilege token SeImpersonatePrivilege. You probably will be able to escalate to Administrator using this token: Juicy-potato
Shodan
port:1433 !HTTP
最后更新于
这有帮助吗?