githubEdit

MSSQL (Microsoft SQL) Pentesting

MSSQL is a relational database management system. A default port is 1433.

Enumeration

nmap --script ms-sql-info -p 1433 <target-ip>
nmap --script ms-sql-config -p 1433 <target-ip>
nmap --script ms-sql-empty-password,ms-sql-xp-cmdshell -p 1433 <target-ip>
nmap --script ms-sql-* -p 1433 <target-ip>

# MSDAT: https://github.com/quentinhardy/msdat
# all: Enumerate with all modules
python3 msdat.py all -s example.com
# -D, -U, -P: Use Windows authentication
python3 msdat.py all -s example.com -D domain -U username -P password
# xpdirectory: List directories in system
python3 msdat.py xpdirectory -s manager.htb -D manager -U operator -P operator -d master --list-files 'C:\'
# bulkopen: Read/download files
python3 msdat.py bulkopen -s example.com -D domain -U username -P password -d database --read-file 'C:\Users\Administrator\Desktop\example.txt'

# Metasploit
msfconsole
msf> use admin/mssql/mssql_enum
msf> use admin/mssql/mssql_enum_domain_accounts
msf> use admin/mssql/mssql_enum_sql_logins
msf> use auxiliary/admin/mssql/mssql_findandsampledata
msf> use auxiliary/admin/mssql/mssql_idf
msf> use auxiliary/scanner/mssql/mssql_hashdump
msf> use auxiliary/scanner/mssql/mssql_schemadump

Brute Force Credentials

Password Spraying Attack

If we found the specific user password, we might be able to find another user with the same password.

Connect

Commands

Impersonate Other Users

Reference: HackTricksarrow-up-right

Spawn a Windows Command Shell and Run Commands using Impacket

In MSSQL client, we can exeucte the Windows Shell Commands by enable_xp_cmdshell if the user has the permission.

Enable/Disable a Windows Shell

Commands

We can execute commands the same as Windows Command Prompt.

Privilege Escalation

Get NTLM Hash

MSSQL uses Keberos to authenticate users so we can retrieve the NTLM hash.

1. Start SMB Server and Responder

First we need to start a SMB server and Responder in each terminal.

2. Execute with Metasploit

In msfconsole, select the following module. We need to set the SMBPROXY option to the Responder IP (this ip is displayed when starting Responder in terminal).

When executing, we can see the NTLM hash in the terminal where SMB server is running.

References

Last updated