overflow_discovery/service/match/imap/imap_test.go

154 lines
2.5 KiB
Go
Raw Normal View History

2017-11-21 12:47:55 +00:00
package imap
import (
"crypto/tls"
"fmt"
//"git.loafle.net/overflow/overflow_discovery/collector/core/scan/port"
2017-11-21 12:52:45 +00:00
"git.loafle.net/overflow/overflow_discovery/service/matcher"
2017-11-21 12:47:55 +00:00
//"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 := NewIMAPMatcher()
//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)
2017-11-21 12:52:45 +00:00
bb := lm.Match(0, matcher.NewPacket(bytett, rr), nil)
2017-11-21 12:47:55 +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)
2017-11-21 12:52:45 +00:00
b := lm.Match(ii+1, matcher.NewPacket(bytes, read), nil)
2017-11-21 12:47:55 +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 := NewIMAPMatcher()
//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)
2017-11-21 12:52:45 +00:00
//bb := lm.Match(0, matcher.NewPacket(bytett, rr), scanInfo)
bb := lm.Match(0, matcher.NewPacket(bytett, rr), nil)
2017-11-21 12:47:55 +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)
2017-11-21 12:52:45 +00:00
b := lm.Match(ii+1, matcher.NewPacket(bytes, read), nil)
2017-11-21 12:47:55 +00:00
if b {
t.Log("send Good!")
}
}
//t.Log(scanInfo)
}