# Get the SQLlogin# The variable SYSTEM_USER contains the name of the SQLloginfor the current sessionSQL>SELECT SYSTEM_USER;# Database user we mapped toSQL>SELECTUSER_NAME();# If we are memeber of roleSQL>SELECTIS_SRVROLEMEMBER('public');# Windows userSQL>SELECTsuser_name();
What Can We Do
SQL>SELECT entity_name, permission_name FROM fn_my_permissions(NULL, 'SERVER');
Accounts
# List usersSQL>SELECTnameFROMmaster..syslogins;# Admin userSQL>SELECTnameFROMmaster..syslogins WHERE sysadmin ='1';
System Information
SQL>select @@version;# Current databaseSQL>SELECTDB_NAME();# List databasesSQL>SELECTnameFROMmaster..sysdatabases;# Query servernameSQL>SELECT @@servername;# Enumerate SQLServer 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.