githubEdit

Microsoft SQL (MSSQL)

Port 1433

1) Nmap Scan

nmap --script ms-sql-info,ms-sql-empty-password,ms-sql-xp-cmdshell,ms-sql-config,ms-sql-ntlm-info,ms-sql-tables,ms-sql-hasdbaccess,ms-sql-dac,ms-sql-dump-hashes --script-args mssql.instance-port=1433,mssql.username=sa,mssql.password=,mssql.instance-name=MSSQLSERVER -sV -p 1433 IP

Enumerate MSSQL database information and configurations

nmap --script ms-sql-info,ms-sql-empty-password,ms-sql-xp-cmdshell,ms-sql-config,ms-sql-ntlm-info,ms-sql-tables,ms-sql-hasdbaccess,ms-sql-dac,ms-sql-dump-hashes --script-args mssql.instance-port=1433,mssql.username=<username>,mssql.password=<password>,mssql.instance-name=<instance_name> -sV -p 1433 IP

2) Netexec

Check MSSQL service and execute a command

netexec mssql -d domain.local -u USERNAME -p PASSWORD -x "whoami" IP

Query databases and list them

netexec mssql -d domain.local -u USERNAME -p PASSWORD -x "SELECT name FROM master.dbo.sysdatabases;" IP

3) Authentication

Linux

sqsh -S IP -U USERNAME -P PASSWORD

Windows

sqsh -S IP -U domain\\USERNAME -P PASSWORD -D DATABASE

4) Exploitation

Enable advanced options and xp_cmdshell for command execution

Test xp_cmdshell to execute system commands

Download and execute a reverse shell

SQL Injection example to execute system commands

Get a hash

5) Impersonation (Windows AD)

Check for users we can impersonate

Perform the Impersonation

Verify Current User and Role

Check Linked Databases

Enable xp_cmdshell

6) Database Usage

List all the databases

List all tables in the current schema

View contents of a specific table

Search for specific data in a table

Insert a new record into a table

Update an existing record in a table

Delete a record from a table

Last updated