# Get the SQL login# The variable SYSTEM_USER contains the name of the SQL loginfor the current sessionSQL> SELECT SYSTEM_USER;# Database user we mapped toSQL> SELECT USER_NAME();# If we are memeber of roleSQL> SELECT IS_SRVROLEMEMBER('public');# Windows userSQL> SELECT suser_name();
What Can We Do
SQL> SELECT entity_name, permission_name FROM fn_my_permissions(NULL, 'SERVER');
Accounts
# List usersSQL> SELECT name FROM master..syslogins;# Admin userSQL> SELECT name FROM master..syslogins WHERE sysadmin ='1';
System Information
SQL>select @@version;# Current databaseSQL> SELECT DB_NAME();# List databasesSQL> SELECT name FROM master..sysdatabases;# Query servernameSQL> SELECT @@servername;# Enumerate SQL Server linksSQL> SELECT srvname FROM sysservers;
Attacks
UNC Path Injection
We can force the MSSQL server to authenticate with a SMB share we control to capture the NTLM authentication messages and crack it later.