overflow_discovery/service/matcher/smb/smb_test.go

44 lines
583 B
Go
Raw Normal View History

2017-11-21 12:47:55 +00:00
package smb
import (
"net"
"testing"
2017-11-21 12:52:45 +00:00
"git.loafle.net/overflow/overflow_discovery/service/matcher"
2017-11-21 12:47:55 +00:00
)
const (
ADDR string = "192.168.1.106:445"
)
func TestSMBMatcher(t *testing.T) {
2017-11-21 12:52:45 +00:00
m := NewMatcher()
2017-11-21 12:47:55 +00:00
conn, err := net.Dial("tcp", ADDR)
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
2017-11-21 12:52:45 +00:00
if m.Match(nil, i, p) {
2017-11-21 12:47:55 +00:00
t.Log("SMB found.")
return
}
t.Error("SMB not found")
}
}