2018-08-13 07:48:32 +00:00
|
|
|
package sqlserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
2018-08-15 07:17:18 +00:00
|
|
|
osm "git.loafle.net/overflow/service_matcher-go"
|
2018-08-13 07:48:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
192.168.1.106:1433 - normal
|
|
|
|
192.168.1.103:1433 - ssl
|
|
|
|
*/
|
|
|
|
func TestSqlNor(t *testing.T) {
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
conn, err := net.Dial("tcp", "192.168.1.16:11433")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2018-08-13 07:48:32 +00:00
|
|
|
defer conn.Close()
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
matchCtx := osm.NewMatchCtx("192.168.1.16", 11433)
|
|
|
|
|
|
|
|
sqlServerRun(matchCtx, conn, t)
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//func TestSqlTLS(t *testing.T) {
|
|
|
|
// conn, err := tls.Dial(
|
|
|
|
// "tcp",
|
|
|
|
// "192.168.1.103:7680",
|
|
|
|
// &tls.Config{
|
|
|
|
// InsecureSkipVerify: true,
|
|
|
|
// ServerName: "192.168.1.103",
|
|
|
|
// },
|
|
|
|
// )
|
|
|
|
//
|
|
|
|
// if err != nil {
|
|
|
|
// t.Log(err)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// defer conn.Close()
|
|
|
|
//
|
|
|
|
// sqlServerRun(conn, t)
|
|
|
|
//}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func sqlServerRun(matchCtx *osm.MatchCtx, conn net.Conn, t *testing.T) {
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
m := NewMatcher()
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
for i := 0; i < m.PacketCount(matchCtx); i++ {
|
2018-08-13 07:48:32 +00:00
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
pack := m.Packet(matchCtx, i)
|
2018-08-13 07:48:32 +00:00
|
|
|
conn.Write(pack.Buffer)
|
|
|
|
bytes := make([]byte, 1024)
|
|
|
|
n, _ := conn.Read(bytes)
|
2018-08-15 07:17:18 +00:00
|
|
|
p := osm.NewPacket(bytes, n)
|
2018-08-13 07:48:32 +00:00
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
if err := m.Match(matchCtx, i, p); nil != err {
|
2024-05-29 10:40:57 +00:00
|
|
|
t.Log(m.Key(matchCtx))
|
2018-08-13 07:48:32 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Error("SQL Server not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|