Skip to content

Impacket checkMSSQLStatus.py

Back to the Category Index / Back to the Command Index

Compares SQL Server login responses to determine whether TLS channel binding is required.

ItemDetails
Implementationexamples/checkMSSQLStatus.py
CategoryMSSQL / Exchange / MQTT
Size154 lines
DistributionInstalled as a script through scripts=examples/*.py in setup.py

Check python examples/checkMSSQLStatus.py -h for the current option definitions.

ArgumentDescription
target[[domain/]username[:password]@]<targetName or address>
-portMSSQL port (default: 1433).
-debugEnable debug logging.
-tsAdd timestamps to log output.
-hashesNTLM hashes.
-no-passSkip the password prompt (useful with -k).
-kUse Kerberos authentication with the ccache specified by KRB5CCNAME.
-aesKey128- or 256-bit AES key for Kerberos.
-dc-ipDomain controller IP address.
-target-ipTarget IP address, overriding name resolution for the target.

The command performs TDS pre-login and establishes a TLS connection according to the server’s encryption settings. It constructs logins with correct, missing, and invalid channel bindings, then compares server responses to determine the policy. The target parser resolves SQL/Windows authentication and connection options.

MSSQL channel binding ties the TLS channel to the Windows/NTLM authentication performed over it. The client creates channel-binding data from the server certificate and includes it in the NTLM authenticate message’s AV pair/MIC calculation. If the server is configured to validate CBT, it can reject values taken from a different TLS channel or omitted entirely.

_new_conn() creates a fresh TCP/TLS session from TDS pre-login for each attempt, because reusing one session would prevent independent comparison of CBT conditions. It reads the pre-login encryption negotiation, wraps the socket in TLS when needed, and sends login tokens with valid, invalid, or missing bindings.

The result depends on differences between conditions, not just whether one login succeeds. Incorrect credentials, SQL-only login support, or a failed TLS certificate check or handshake prevent a CBT policy determination. Preserve TDS error tokens and disconnects to distinguish enforced, unenforced, and indeterminate results.

SymbolLocationEntry Point for Tracing Behavior
MSQLCBTCheck24__init__(), run()
ModuleMain Names Used
impacketversion
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.tdsMSSQL, TDS_ENCRYPT_OFF, TDS_ENCRYPT_REQ

Output, Side Effects, and Required Privileges

Section titled “Output, Side Effects, and Required Privileges”
  • Primarily queries and authentication attempts. Repeated runs can affect audit logs, account lockouts, and target load.
  • On failure, use protocol status to determine whether name resolution, connection, authentication, service state, or permissions stopped the operation.

This command depends on impacket.tds.MSSQL, TDS encryption constants, and TLS/NTLM helpers. MSQLCBTCheck._new_conn() isolates state for each attempt, while _login() / run() compare the results. Do not reuse TLS or session state between attempts.

  • Syntax: python -m py_compile examples/checkMSSQLStatus.py
  • CLI: python examples/checkMSSQLStatus.py -h
  • Related test: tests/misc/test_tds.py