Skip to main content

MSSQL Protocol

Impacket’s TDS (Tabular Data Stream) implementation provides comprehensive support for connecting to and interacting with Microsoft SQL Server, including authentication, query execution, and advanced features.

Overview

The TDS protocol implementation is located in impacket/tds.py and includes:
  • Authentication - Windows authentication (NTLM/Kerberos), SQL authentication
  • Query execution - Execute SQL queries and stored procedures
  • Multiple result sets - Handle complex query results
  • Encryption - TLS encryption for secure connections

TDS Protocol

TDS (Tabular Data Stream) is Microsoft’s application-level protocol for SQL Server communication. Impacket implements TDS 7.0+ for compatibility with modern SQL Server versions.

Connection and Authentication

Basic Connection

From tds.py:1-100:

SQL Authentication

Windows Authentication (NTLM)

Kerberos Authentication

Query Execution

Execute Query

Multiple Queries

Parameterized Queries

Information Gathering

Enumerate Databases

Enumerate Tables

Enumerate Users and Logins

Check Privileges

Advanced Features

xp_cmdshell Execution

xp_cmdshell allows OS command execution and requires sysadmin privileges. Use responsibly and only on systems you’re authorized to test.

File Operations

Linked Servers

SQL Server Agent Jobs

TDS Protocol Details

Packet Types

From tds.py:117-127:

Encryption

TDS supports TLS encryption for secure communication. Encryption is negotiated during the pre-login phase.

Security Testing

Bruteforce Authentication

Enumerate SPNs

Error Handling

Always handle SQL exceptions properly to avoid crashes and information disclosure.

Complete Example: SQL Server Client

Port Discovery

SQL Server Browser (UDP 1434)

From tds.py:70-76:
  • Kerberos - Kerberos authentication for SQL
  • LDAP - Finding SQL Servers in AD

References

  • Source: impacket/tds.py
  • [MS-TDS]: Tabular Data Stream Protocol
  • [MC-SQLR]: SQL Server Resolution Protocol