fix mssql login client metadata

This commit is contained in:
ZacharyZcR
2026-05-23 07:17:55 +08:00
parent e0080555b4
commit 0046817c2e
2 changed files with 44 additions and 7 deletions
+5 -7
View File
@@ -9,7 +9,6 @@ import (
"fmt"
"io"
"net"
"os"
"sort"
"time"
"unicode/utf16"
@@ -190,17 +189,16 @@ func mssqlParsePreloginFields(payload []byte) (map[byte][]byte, error) {
}
func mssqlSendLogin7(w io.Writer, host, username, password string) error {
hostname, _ := os.Hostname()
values := []struct {
text string
password bool
}{
{hostname, false},
{"", false},
{username, false},
{password, true},
{"fscan", false},
{host, false},
{"fscan", false},
{"", false},
{"", false},
{"", false},
{"", false},
{"master", false},
{"", false},
@@ -233,7 +231,7 @@ func mssqlSendLogin7(w io.Writer, host, username, password string) error {
put32(tdsVersion74)
put32(tdsDefaultPacketLen)
put32(0)
put32(uint32(os.Getpid()))
put32(0)
put32(0)
body.WriteByte(tdsOptionUseDB | tdsOptionSetLang)
body.WriteByte(tdsOptionODBC)
+39
View File
@@ -0,0 +1,39 @@
//go:build plugin_mssql || !plugin_selective
package services
import (
"bytes"
"encoding/binary"
"os"
"testing"
)
func TestMSSQLLogin7DoesNotExposeClientIdentity(t *testing.T) {
var packet bytes.Buffer
if err := mssqlSendLogin7(&packet, "target-host", "sa", "password"); err != nil {
t.Fatalf("mssqlSendLogin7() error = %v", err)
}
data := packet.Bytes()
if len(data) < 8+20 {
t.Fatalf("login packet too short: %d", len(data))
}
payload := data[8:]
if pid := binary.LittleEndian.Uint32(payload[16:20]); pid != 0 {
t.Fatalf("client pid = %d, want 0", pid)
}
for _, value := range []string{"fscan", "target-host"} {
if bytes.Contains(payload, mssqlUCS2(value)) {
t.Fatalf("login packet contains client-identifying value %q", value)
}
}
if hostname, err := os.Hostname(); err == nil && hostname != "" {
if bytes.Contains(payload, mssqlUCS2(hostname)) {
t.Fatalf("login packet contains local hostname %q", hostname)
}
}
}