service_matcher-go/imap/imap_test.go

150 lines
2.3 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
)
func ImapRun(client net.Conn, t *testing.T) {
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)
//client, _ := net.Dial("tcp", ipport)
//defer client.Close()
bytett := make([]byte, 1024)
rr, _ := client.Read(bytett)
2018-08-15 07:17:18 +00:00
bb := lm.Match(nil, 0, osm.NewPacket(bytett, rr))
2018-08-13 07:48:32 +00:00
if bb {
t.Log("good!")
}
fmt.Println(lm.PacketCount())
for ii := 0; ii < lm.PacketCount(); ii++ {
pack := lm.Packet(ii)
//fmt.Println(pack)
client.Write(pack.Buffer)
bytes := make([]byte, 1024)
read, _ := client.Read(bytes)
fmt.Println(cap(bytes))
//fmt.Println(bytes)
2018-08-15 07:17:18 +00:00
b := lm.Match(nil, ii+1, osm.NewPacket(bytes, read))
2018-08-13 07:48:32 +00:00
if b {
t.Log("send Good!")
}
}
}
func TestIMapTls(t *testing.T) {
conn, _ := tls.Dial(
"tcp",
"192.168.1.15:993",
&tls.Config{
InsecureSkipVerify: true,
ServerName: "192.168.1.15",
},
)
defer conn.Close()
ImapRun(conn, t)
}
func TestIMapNormal(t *testing.T) {
client, err := net.Dial("tcp", "192.168.1.15:143")
if err != nil {
t.Fatal(err)
}
defer client.Close()
ImapRun(client, t)
}
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)
client, _ := net.Dial("tcp", ipport)
defer client.Close()
bytett := make([]byte, 1024)
rr, _ := client.Read(bytett)
2018-08-15 07:17:18 +00:00
//bb := lm.Match(0, osm.NewPacket(bytett, rr), scanInfo)
bb := lm.Match(nil, 0, osm.NewPacket(bytett, rr))
2018-08-13 07:48:32 +00:00
if bb {
t.Log("good!")
}
fmt.Println(lm.PacketCount())
for ii := 0; ii < lm.PacketCount(); ii++ {
pack := lm.Packet(ii)
//fmt.Println(pack)
client.Write(pack.Buffer)
bytes := make([]byte, 1024)
read, _ := client.Read(bytes)
fmt.Println(cap(bytes))
//fmt.Println(bytes)
2018-08-15 07:17:18 +00:00
b := lm.Match(nil, ii+1, osm.NewPacket(bytes, read))
2018-08-13 07:48:32 +00:00
if b {
t.Log("send Good!")
}
}
//t.Log(scanInfo)
}