Documentation
¶
Index ¶
- Constants
- func GetInstancePort(server, instance string, timeout time.Duration) (int, error)
- func ParseTokens(data []byte, columns []ColumnInfo) ([]Token, []ColumnInfo, error)
- type Client
- func (c *Client) Close() error
- func (c *Client) Connect(address string) error
- func (c *Client) CurrentDB() string
- func (c *Client) GetColumns() []ColumnInfo
- func (c *Client) GetConn() net.Conn
- func (c *Client) GetPacketSize() int
- func (c *Client) KerberosLogin(database, username, password, domain string, hashes, aesKey, kdcHost string) error
- func (c *Client) Login(database, username, password, domain string, hashes string, windowsAuth bool) error
- func (c *Client) RecvTDS() (*TDSPacket, error)
- func (c *Client) RelayDisableTLSAfterLogin()
- func (c *Client) RelayInit() error
- func (c *Client) RelaySendAuth(ntlmType3 []byte) error
- func (c *Client) RelaySendNegotiate(ntlmType1 []byte) ([]byte, error)
- func (c *Client) SQLQuery(query string) ([]map[string]interface{}, error)
- func (c *Client) SendTDS(packetType uint8, data []byte) error
- type ColMetaDataToken
- type ColumnInfo
- type DoneToken
- type EnvChangeToken
- type ErrorToken
- type InfoToken
- type LoginAckToken
- type LoginPacket
- type PreLoginOption
- type PreLoginPacket
- type ReturnStatusToken
- type RowToken
- type SQLRInstance
- type SSPIToken
- type TDSPacket
- type Token
Constants ¶
const ( SQLRPort = 1434 SQLRClntBcastEx = 0x02 SQLRClntUcastEx = 0x03 SQLRClntUcastInst = 0x04 SQLRClntUcastDAC = 0x0f )
MC-SQLR Constants (SQL Server Resolution Protocol)
const ( TDSSQLBatch = 1 TDSPreTDSLogin = 2 TDSRPC = 3 TDSTabular = 4 TDSAttention = 6 TDSBulkLoadData = 7 TDSTransaction = 14 TDSLogin7 = 16 TDSSSPI = 17 TDSPreLogin = 18 )
TDS Packet Types
const ( TDSStatusNormal = 0 TDSStatusEOM = 1 TDSStatusResetConnection = 8 TDSStatusResetSkiptrans = 16 )
TDS Status
const ( TDSEncryptOff = 0 TDSEncryptOn = 1 TDSEncryptNotSup = 2 TDSEncryptReq = 3 )
TDS Encryption
const ( TDSIntegratedSecurityOn = 0x80 TDSInitLangFatal = 0x01 TDSODBCOn = 0x02 )
Option Flags
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
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
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
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 ¶
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 (*Client) GetColumns ¶
func (c *Client) GetColumns() []ColumnInfo
GetColumns returns the current column metadata
func (*Client) GetPacketSize ¶
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) 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 ¶
RelayInit performs the PRELOGIN handshake and sets up TLS, preparing the connection for NTLM relay. Call this after Connect().
func (*Client) RelaySendAuth ¶
RelaySendAuth sends the NTLM Type3 authenticate message as a TDS_SSPI packet, and checks for a successful login acknowledgment.
func (*Client) RelaySendNegotiate ¶
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.
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 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
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 ¶
PreLoginOption represents a prelogin option
type PreLoginPacket ¶
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 ¶
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
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