network_service_matcher/imap/imap_test.go
crusader ac4d422cd9 ing
2017-12-04 16:27:08 +09:00

152 lines
2.5 KiB
Go

package imap
import (
"crypto/tls"
"fmt"
//"git.loafle.net/overflow/overflow_discovery/collector/core/scan/port"
cnsm "git.loafle.net/commons_go/network_service_matcher"
//"git.loafle.net/overflow/overflow_discovery/collector/core/scan/service/matcher/scaninfo"
//"git.loafle.net/overflow/overflow_discovery/collector/discovery/types"
"net"
"testing"
)
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)
bb := lm.Match(nil, 0, cnsm.NewPacket(bytett, rr))
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)
b := lm.Match(nil, ii+1, cnsm.NewPacket(bytes, read))
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)
//bb := lm.Match(0, cnsm.NewPacket(bytett, rr), scanInfo)
bb := lm.Match(nil, 0, cnsm.NewPacket(bytett, rr))
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)
b := lm.Match(nil, ii+1, cnsm.NewPacket(bytes, read))
if b {
t.Log("send Good!")
}
}
//t.Log(scanInfo)
}