service_matcher-go/pop/pop_test.go

88 lines
1.5 KiB
Go
Raw Normal View History

2018-08-13 07:48:32 +00:00
package pop
import (
"crypto/tls"
"fmt"
2018-08-15 07:17:18 +00:00
osm "git.loafle.net/overflow/service_matcher-go"
2018-08-13 07:48:32 +00:00
"net"
"testing"
)
func TestPopTLS(t *testing.T) {
2018-09-03 13:36:57 +00:00
conn, err := tls.Dial(
2018-08-13 07:48:32 +00:00
"tcp",
"192.168.1.15:995",
&tls.Config{
InsecureSkipVerify: true,
ServerName: "192.168.1.15",
},
)
2018-09-03 13:36:57 +00:00
if err != nil {
t.Errorf("ERR %s", err)
}
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.15", 995)
pop3Run(matchCtx, conn, t)
2018-08-13 07:48:32 +00:00
}
func TestPopNor(t *testing.T) {
2018-09-03 13:36:57 +00:00
conn, err := net.Dial("tcp", "192.168.1.15:110")
if err != nil {
t.Errorf("ERR %s", err)
}
defer conn.Close()
2018-08-13 07:48:32 +00:00
2018-09-03 13:36:57 +00:00
matchCtx := osm.NewMatchCtx("192.168.1.15", 110)
2018-08-13 07:48:32 +00:00
2018-09-03 13:36:57 +00:00
pop3Run(matchCtx, conn, t)
2018-08-13 07:48:32 +00:00
}
2018-09-03 13:36:57 +00:00
func pop3Run(matchCtx *osm.MatchCtx, conn net.Conn, t *testing.T) {
2018-08-13 07:48:32 +00:00
2018-09-03 13:36:57 +00:00
lm := NewMatcher()
2018-08-13 07:48:32 +00:00
//port := types.NewPort("110", types.NewHost("192.168.1.215"), types.TYPE_TCP)
//scanInfo := scaninfo.NewServiceScanInfo(port)
//var ipport string
//ipport = port.Host.Ip + ":" + string(port.Port)
//
//fmt.Println(ipport)
bytett := make([]byte, 1024)
2018-09-03 13:36:57 +00:00
read, _ := conn.Read(bytett)
2018-08-13 07:48:32 +00:00
2018-09-03 13:36:57 +00:00
if err := lm.Match(matchCtx, 0, osm.NewPacket(bytett, read)); nil == err {
2018-08-13 07:48:32 +00:00
t.Log("good!")
}
2018-09-03 13:36:57 +00:00
fmt.Println(lm.PacketCount(matchCtx))
2018-08-13 07:48:32 +00:00
2018-09-03 13:36:57 +00:00
for ii := 0; ii < lm.PacketCount(matchCtx); ii++ {
2018-08-13 07:48:32 +00:00
2018-09-03 13:36:57 +00:00
pack := lm.Packet(matchCtx, ii)
2018-08-13 07:48:32 +00:00
//fmt.Println(pack)
2018-09-03 13:36:57 +00:00
conn.Write(pack.Buffer)
2018-08-13 07:48:32 +00:00
bytes := make([]byte, 1024)
2018-09-03 13:36:57 +00:00
rr, _ := conn.Read(bytes)
2018-08-13 07:48:32 +00:00
//fmt.Println(bytes)
2018-09-03 13:36:57 +00:00
if err := lm.Match(matchCtx, ii+1, osm.NewPacket(bytes, rr)); nil == err {
2018-08-13 07:48:32 +00:00
t.Log("send Good!")
}
}
}