Summery

mssqlclient.py in Impacket is a SQL client for interacting with Microsoft SQL Server. It supports authentication, command execution via xp_cmdshell, and exploiting weak configurations for privilege escalation.

SQL Server supports two types of authentication:

  • Windows Authentication - Uses Active Directory or local Windows accounts for authentication.
  • SQL Authentication - Uses SQL Server-specific usernames and passwords stored in the database.

How mssqlclient.py determines authentication types:

  • If a domain (DOMAIN\username) or hostname (HOSTNAME/username) is specified, mssqlclient.py attempts Windows Authentication via NTLM/Kerberos.
  • If only username@IP is provided (e.g., julio@10.129.203.7), mssqlclient.py assumes SQL Authentication and attempts to log in using SQL Server users.

Windows authentication
impacket-mssqlclient INLANEFREIGHT/user@1.3.3.7 -windows-auth

SQL authentication
impacket-mssqlclient -p 1433 user@1.3.3.7

Kerberos TGT authentication(?)
impacket-mssqlclient breach.vl -k -no-pass

Kerberos TGS authentication
KRB5CCNAME=Administrator.ccache mssqlclient.py -no-pass -k BREACHDC.breach.vl

xp_cmdshell
xp_cmdshell is a stored procedure in Microsoft SQL Server that allows SQL Server to execute operating system commands directly from within SQL Server. It enables users to run shell commands or even PowerShell commands from a SQL query interface.

We can try to enable it with mssqlclient.py using the enable_xp_cmdshell command.
If xp_cmdshell is enabled - we can check if it works (and run any type of other commands) by simply executing xp_cmdshell whoami /priv.