service_matcher-go/imap/imap_test.go

152 lines
2.6 KiB
Go
Raw Normal View History

2018-08-13 07:48:32 +00:00
package imap
import (
"crypto/tls"
"fmt"
"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
)
2018-09-03 13:36:57 +00:00
func ImapRun(matchCtx *osm.MatchCtx, conn net.Conn, t *testing.T) {
2018-08-13 07:48:32 +00:00
lm := NewMatcher()
//port := types.NewPort("143", types.NewHost("192.168.1.215"), types.TYPE_TCP)
//
//scanInfo := types.NewServiceScanInfo(port)
//
//var ipport string
//ipport = port.Host.Ip + ":" + string(port.Port)
//
//fmt.Println(ipport)
2018-09-03 13:36:57 +00:00
//conn, _ := net.Dial("tcp", ipport)
2018-08-13 07:48:32 +00:00
2018-09-03 13:36:57 +00:00
//defer conn.Close()
2018-08-13 07:48:32 +00:00
bytett := make([]byte, 1024)
2018-09-03 13:36:57 +00:00
rr, _ := 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, rr)); 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
read, _ := conn.Read(bytes)
2018-08-13 07:48:32 +00:00
fmt.Println(cap(bytes))
//fmt.Println(bytes)
2018-09-03 13:36:57 +00:00
if err := lm.Match(nil, ii+1, osm.NewPacket(bytes, read)); nil == err {
2018-08-13 07:48:32 +00:00
t.Log("send Good!")
}
}
}
func TestIMapTls(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:993",
&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", 993)
ImapRun(matchCtx, conn, t)
2018-08-13 07:48:32 +00:00
}
func TestIMapNormal(t *testing.T) {
2018-09-03 13:36:57 +00:00
conn, err := net.Dial("tcp", "192.168.1.15:143")
2018-08-13 07:48:32 +00:00
if err != nil {
t.Fatal(err)
}
2018-09-03 13:36:57 +00:00
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", 143)
2018-08-13 07:48:32 +00:00
2018-09-03 13:36:57 +00:00
ImapRun(matchCtx, conn, t)
2018-08-13 07:48:32 +00:00
}
func TestImap(t *testing.T) {
lm := NewMatcher()
//port := types.NewPort("143", types.NewHost("192.168.1.215"), types.TYPE_TCP)
//scanInfo := scaninfo.NewServiceScanInfo(port)
var ipport string
//ipport = port.Host.Ip + ":" + port.Port_
fmt.Println(ipport)
2018-09-03 13:36:57 +00:00
conn, err := net.Dial("tcp", ipport)
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", 993)
2018-08-13 07:48:32 +00:00
bytett := make([]byte, 1024)
2018-09-03 13:36:57 +00:00
rr, _ := conn.Read(bytett)
2018-08-13 07:48:32 +00:00
2018-08-15 07:17:18 +00:00
//bb := lm.Match(0, osm.NewPacket(bytett, rr), scanInfo)
2018-09-03 13:36:57 +00:00
if err := lm.Match(nil, 0, osm.NewPacket(bytett, rr)); 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
read, _ := conn.Read(bytes)
2018-08-13 07:48:32 +00:00
fmt.Println(cap(bytes))
//fmt.Println(bytes)
2018-09-03 13:36:57 +00:00
if err := lm.Match(nil, ii+1, osm.NewPacket(bytes, read)); nil == err {
2018-08-13 07:48:32 +00:00
t.Log("send Good!")
}
}
//t.Log(scanInfo)
}