tds

package
v0.0.0-...-7085336 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SQLRPort          = 1434
	SQLRClntBcastEx   = 0x02
	SQLRClntUcastEx   = 0x03
	SQLRClntUcastInst = 0x04
	SQLRClntUcastDAC  = 0x0f
)

MC-SQLR Constants (SQL Server Resolution Protocol)

View Source
const (
	TDSSQLBatch     = 1
	TDSPreTDSLogin  = 2
	TDSRPC          = 3
	TDSTabular      = 4
	TDSAttention    = 6
	TDSBulkLoadData = 7
	TDSTransaction  = 14
	TDSLogin7       = 16
	TDSSSPI         = 17
	TDSPreLogin     = 18
)

TDS Packet Types

View Source
const (
	TDSStatusNormal          = 0
	TDSStatusEOM             = 1
	TDSStatusResetConnection = 8
	TDSStatusResetSkiptrans  = 16
)

TDS Status

View Source
const (
	TDSEncryptOff    = 0
	TDSEncryptOn     = 1
	TDSEncryptNotSup = 2
	TDSEncryptReq    = 3
)

TDS Encryption

View Source
const (
	TDSIntegratedSecurityOn = 0x80
	TDSInitLangFatal        = 0x01
	TDSODBCOn               = 0x02
)

Option Flags

View Source
const (
	TDSAltMetadataToken  = 0x88
	TDSAltRowToken       = 0xD3
	TDSColMetadataToken  = 0x81
	TDSColInfoToken      = 0xA5
	TDSDoneToken         = 0xFD
	TDSDoneProcToken     = 0xFE
	TDSDoneInProcToken   = 0xFF
	TDSEnvChangeToken    = 0xE3
	TDSErrorToken        = 0xAA
	TDSInfoToken         = 0xAB
	TDSLoginAckToken     = 0xAD
	TDSNBCRowToken       = 0xD2
	TDSOffsetToken       = 0x78
	TDSOrderToken        = 0xA9
	TDSReturnStatusToken = 0x79
	TDSReturnValueToken  = 0xAC
	TDSRowToken          = 0xD1
	TDSSSPIToken         = 0xED
	TDSTabNameToken      = 0xA4
)

Token Types

View Source
const (
	TDSEnvChangeDatabase    = 1
	TDSEnvChangeLanguage    = 2
	TDSEnvChangeCharset     = 3
	TDSEnvChangePacketSize  = 4
	TDSEnvChangeUnicode     = 5
	TDSEnvChangeUnicodeDS   = 6
	TDSEnvChangeCollation   = 7
	TDSEnvChangeTransStart  = 8
	TDSEnvChangeTransCommit = 9
	TDSEnvChangeRollback    = 10
	TDSEnvChangeDTC         = 11
)

ENVCHANGE Types

View Source
const (
	TDSNullType     = 0x1F
	TDSInt1Type     = 0x30
	TDSBitType      = 0x32
	TDSInt2Type     = 0x34
	TDSInt4Type     = 0x38
	TDSDateTim4Type = 0x3A
	TDSFlt4Type     = 0x3B
	TDSMoneyType    = 0x3C
	TDSDateTimeType = 0x3D
	TDSFlt8Type     = 0x3E
	TDSMoney4Type   = 0x7A
	TDSInt8Type     = 0x7F
)

Column Types - Fixed Length

View Source
const (
	TDSGuidType            = 0x24
	TDSIntNType            = 0x26
	TDSDecimalType         = 0x37
	TDSNumericType         = 0x3F
	TDSBitNType            = 0x68
	TDSDecimalNType        = 0x6A
	TDSNumericNType        = 0x6C
	TDSFltNType            = 0x6D
	TDSMoneyNType          = 0x6E
	TDSDateTimNType        = 0x6F
	TDSDateNType           = 0x28
	TDSTimeNType           = 0x29
	TDSDateTime2NType      = 0x2A
	TDSDateTimeOffsetNType = 0x2B
	TDSCharType            = 0x2F
	TDSVarCharType         = 0x27
	TDSBinaryType          = 0x2D
	TDSVarBinaryType       = 0x25
	TDSBigVarBinType       = 0xA5
	TDSBigVarChrType       = 0xA7
	TDSBigBinaryType       = 0xAD
	TDSBigCharType         = 0xAF
	TDSNVarCharType        = 0xE7
	TDSNCharType           = 0xEF
	TDSXMLType             = 0xF1
	TDSUDTType             = 0xF0
	TDSTextType            = 0x23
	TDSImageType           = 0x22
	TDSNTextType           = 0x63
	TDSSSVariantType       = 0x62
)

Column Types - Variable Length

Variables

This section is empty.

Functions

func GetInstancePort

func GetInstancePort(server, instance string, timeout time.Duration) (int, error)

GetInstancePort queries for a specific instance's port

func ParseTokens

func ParseTokens(data []byte, columns []ColumnInfo) ([]Token, []ColumnInfo, error)

ParseTokens parses all tokens from TDS response data

Types

type Client

type Client struct {

	// Relay raw packet capture (for SOCKS plugin replay)
	RelayRawChallenge  []byte // Full raw TDS SSPI challenge response
	RelayRawAuthAnswer []byte // Full raw TDS LOGIN_ACK response
	// contains filtered or unexported fields
}

Client represents a TDS/MSSQL client

func NewClient

func NewClient(address string, port int, remoteName string) *Client

NewClient creates a new TDS client

func (*Client) Close

func (c *Client) Close() error

Close closes the connection

func (*Client) Connect

func (c *Client) Connect(address string) error

Connect establishes a TCP connection to the SQL server

func (*Client) CurrentDB

func (c *Client) CurrentDB() string

CurrentDB returns the current database name

func (*Client) GetColumns

func (c *Client) GetColumns() []ColumnInfo

GetColumns returns the current column metadata

func (*Client) GetConn

func (c *Client) GetConn() net.Conn

GetConn returns the underlying TCP connection (for SOCKS tunneling).

func (*Client) GetPacketSize

func (c *Client) GetPacketSize() int

GetPacketSize returns the TDS packet size for framing.

func (*Client) KerberosLogin

func (c *Client) KerberosLogin(database, username, password, domain string, hashes, aesKey, kdcHost string) error

KerberosLogin authenticates with Kerberos

func (*Client) Login

func (c *Client) Login(database, username, password, domain string, hashes string, windowsAuth bool) error

Login authenticates with SQL Server using SQL or Windows authentication

func (*Client) RecvTDS

func (c *Client) RecvTDS() (*TDSPacket, error)

RecvTDS is a public wrapper around recvTDS for SOCKS plugin use.

func (*Client) RelayDisableTLSAfterLogin

func (c *Client) RelayDisableTLSAfterLogin()

RelayDisableTLSAfterLogin is a no-op — TLS is now disabled inside RelaySendNegotiate after sending LOGIN7 (matching Impacket behavior).

func (*Client) RelayInit

func (c *Client) RelayInit() error

RelayInit performs the PRELOGIN handshake and sets up TLS, preparing the connection for NTLM relay. Call this after Connect().

func (*Client) RelaySendAuth

func (c *Client) RelaySendAuth(ntlmType3 []byte) error

RelaySendAuth sends the NTLM Type3 authenticate message as a TDS_SSPI packet, and checks for a successful login acknowledgment.

func (*Client) RelaySendNegotiate

func (c *Client) RelaySendNegotiate(ntlmType1 []byte) ([]byte, error)

RelaySendNegotiate builds a LOGIN7 packet with the given NTLM Type1 as SSPI, sends it, and returns the NTLM Type2 challenge from the server's SSPI response.

func (*Client) SQLQuery

func (c *Client) SQLQuery(query string) ([]map[string]interface{}, error)

SQLQuery executes a SQL query and returns results

func (*Client) SendTDS

func (c *Client) SendTDS(packetType uint8, data []byte) error

SendTDS is a public wrapper around sendTDS for SOCKS plugin use.

type ColMetaDataToken

type ColMetaDataToken struct {
	Type    uint8
	Columns []ColumnInfo
}

ColMetaDataToken represents TDS_COLMETADATA_TOKEN

func (*ColMetaDataToken) TokenType

func (t *ColMetaDataToken) TokenType() uint8

type ColumnInfo

type ColumnInfo struct {
	UserType uint16
	Flags    uint16
	ColType  uint8
	TypeData interface{}
	Name     string
	Length   int
}

ColumnInfo describes a column

type DoneToken

type DoneToken struct {
	Type         uint8
	Status       uint16
	CurCmd       uint16
	DoneRowCount uint64
}

DoneToken represents TDS_DONE_TOKEN

func (*DoneToken) TokenType

func (t *DoneToken) TokenType() uint8

type EnvChangeToken

type EnvChangeToken struct {
	Type       uint8
	Length     uint16
	ChangeType uint8
	NewValue   string
	OldValue   string
}

EnvChangeToken represents a TDS_ENVCHANGE_TOKEN

func (*EnvChangeToken) TokenType

func (t *EnvChangeToken) TokenType() uint8

type ErrorToken

type ErrorToken struct {
	Type       uint8
	Length     uint16
	Number     uint32
	State      uint8
	Class      uint8
	MsgText    string
	ServerName string
	ProcName   string
	LineNumber uint16
}

ErrorToken represents a TDS_ERROR_TOKEN

func (*ErrorToken) TokenType

func (t *ErrorToken) TokenType() uint8

type InfoToken

type InfoToken struct {
	Type       uint8
	Length     uint16
	Number     uint32
	State      uint8
	Class      uint8
	MsgText    string
	ServerName string
	ProcName   string
	LineNumber uint16
}

InfoToken represents a TDS_INFO_TOKEN

func (*InfoToken) TokenType

func (t *InfoToken) TokenType() uint8

type LoginAckToken

type LoginAckToken struct {
	Type       uint8
	Length     uint16
	Interface  uint8
	TDSVersion uint32
	ProgName   string
	MajorVer   uint8
	MinorVer   uint8
	BuildNumHi uint8
	BuildNumLo uint8
}

LoginAckToken represents a TDS_LOGINACK_TOKEN

func (*LoginAckToken) TokenType

func (t *LoginAckToken) TokenType() uint8

type LoginPacket

type LoginPacket struct {
	TDSVersion     uint32
	PacketSize     uint32
	ClientProgVer  uint32
	ClientPID      uint32
	ConnectionID   uint32
	OptionFlags1   uint8
	OptionFlags2   uint8
	TypeFlags      uint8
	OptionFlags3   uint8
	ClientTimeZone int32
	ClientLCID     uint32
	HostName       string
	UserName       string
	Password       string
	AppName        string
	ServerName     string
	CltIntName     string
	Database       string
	SSPI           []byte
	AtchDBFile     string
}

LoginPacket represents a TDS LOGIN7 packet

func (*LoginPacket) Marshal

func (p *LoginPacket) Marshal() []byte

Marshal serializes the login packet

type PreLoginOption

type PreLoginOption struct {
	Token  uint8
	Offset uint16
	Length uint16
}

PreLoginOption represents a prelogin option

type PreLoginPacket

type PreLoginPacket struct {
	Version    []byte
	Encryption uint8
	Instance   string
	ThreadID   uint32
}

PreLoginPacket represents a TDS PRELOGIN packet

func ParsePreLoginResponse

func ParsePreLoginResponse(data []byte) (*PreLoginPacket, error)

ParsePreLoginResponse parses a prelogin response

func (*PreLoginPacket) Marshal

func (p *PreLoginPacket) Marshal() []byte

Marshal serializes the prelogin packet

type ReturnStatusToken

type ReturnStatusToken struct {
	Type  uint8
	Value int32
}

ReturnStatusToken represents TDS_RETURNSTATUS_TOKEN

func (*ReturnStatusToken) TokenType

func (t *ReturnStatusToken) TokenType() uint8

type RowToken

type RowToken struct {
	Type   uint8
	Values []interface{}
}

RowToken represents TDS_ROW_TOKEN

func (*RowToken) TokenType

func (t *RowToken) TokenType() uint8

type SQLRInstance

type SQLRInstance struct {
	ServerName   string
	InstanceName string
	IsClustered  string
	Version      string
	TCP          string
	NamedPipe    string
}

SQLRInstance represents a discovered SQL Server instance

func GetInstances

func GetInstances(server string, timeout time.Duration) ([]SQLRInstance, error)

GetInstances queries the SQL Server Browser service for instances

type SSPIToken

type SSPIToken struct {
	Type uint8
	Data []byte
}

SSPIToken represents TDS_SSPI_TOKEN

func (*SSPIToken) TokenType

func (t *SSPIToken) TokenType() uint8

type TDSPacket

type TDSPacket struct {
	Type     uint8
	Status   uint8
	Length   uint16
	SPID     uint16
	PacketID uint8
	Window   uint8
	Data     []byte
}

TDSPacket represents a TDS protocol packet

func (*TDSPacket) Marshal

func (p *TDSPacket) Marshal() []byte

Marshal serializes the TDS packet

func (*TDSPacket) Unmarshal

func (p *TDSPacket) Unmarshal(data []byte) error

Unmarshal deserializes a TDS packet from bytes

type Token

type Token interface {
	TokenType() uint8
}

Token represents a parsed TDS token

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL