2017-11-21 12:47:55 +00:00
|
|
|
package mysql
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
2017-11-21 12:52:45 +00:00
|
|
|
"git.loafle.net/overflow/overflow_discovery/service/matcher"
|
2017-11-21 12:47:55 +00:00
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMySql(t *testing.T) {
|
|
|
|
|
|
|
|
m := NewMySqlMatcher()
|
|
|
|
|
|
|
|
/*
|
|
|
|
192.168.1.103:3306 - normal
|
|
|
|
192.168.1.105:8306 - ssl
|
|
|
|
192.168.1.203:3306 - mysql with error code
|
|
|
|
*/
|
|
|
|
conn, _ := net.Dial("tcp", "192.168.1.15:33068")
|
|
|
|
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
bytes := make([]byte, 1024)
|
|
|
|
n, _ := conn.Read(bytes)
|
2017-11-21 12:52:45 +00:00
|
|
|
p := matcher.NewPacket(bytes, n)
|
2017-11-21 12:47:55 +00:00
|
|
|
|
|
|
|
if m.Match(0, p, nil) {
|
|
|
|
t.Log(m.ServiceName())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Error("MySQL not found")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCassandraTLS(t *testing.T) {
|
|
|
|
|
|
|
|
m := NewMySqlMatcher()
|
|
|
|
|
|
|
|
conn, err := tls.Dial(
|
|
|
|
"tcp",
|
|
|
|
"192.168.1.105:8306",
|
|
|
|
&tls.Config{
|
|
|
|
InsecureSkipVerify: true,
|
|
|
|
ServerName: "192.168.1.105",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
for i := 0; i < m.PacketCount(); i++ {
|
|
|
|
|
|
|
|
pack := m.Packet(i)
|
|
|
|
conn.Write(pack.Buffer)
|
|
|
|
bytes := make([]byte, 1024)
|
|
|
|
n, _ := conn.Read(bytes)
|
2017-11-21 12:52:45 +00:00
|
|
|
p := matcher.NewPacket(bytes, n)
|
2017-11-21 12:47:55 +00:00
|
|
|
|
|
|
|
if m.Match(i, p, nil) {
|
|
|
|
t.Log(m.ServiceName())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Error("MySQL not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|