2017-12-14 07:38:48 +00:00
|
|
|
package postgresql
|
2017-12-04 07:27:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
cnsm "git.loafle.net/commons_go/network_service_matcher"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPG(t *testing.T) {
|
|
|
|
m := NewPostgreSQLMatcher()
|
|
|
|
|
|
|
|
conn, err := net.Dial("tcp", "192.168.1.106:5432") //107
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
p := cnsm.NewPacket(bytes, n)
|
|
|
|
|
|
|
|
if m.Match(i, p, nil) {
|
|
|
|
t.Log("PostgreSQL found")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Error("PostgreSQL not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSqlTLS(t *testing.T) {
|
|
|
|
conn, err := tls.Dial(
|
|
|
|
"tcp",
|
|
|
|
"192.168.1.107:5432",
|
|
|
|
&tls.Config{
|
|
|
|
InsecureSkipVerify: true,
|
|
|
|
ServerName: "192.168.1.107",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
m := NewPostgreSQLMatcher()
|
|
|
|
for i := 0; i < m.PacketCount(); i++ {
|
|
|
|
|
|
|
|
pack := m.Packet(i)
|
|
|
|
conn.Write(pack.Buffer)
|
|
|
|
bytes := make([]byte, 1024)
|
|
|
|
n, _ := conn.Read(bytes)
|
|
|
|
p := cnsm.NewPacket(bytes, n)
|
|
|
|
|
|
|
|
if m.Match(i, p, nil) {
|
|
|
|
t.Log("PostgreSQL found")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Error("PostgreSQL not found")
|
|
|
|
}
|
|
|
|
}
|