154 lines
2.5 KiB
Go
154 lines
2.5 KiB
Go
|
package imap
|
||
|
|
||
|
|
||
|
import (
|
||
|
"crypto/tls"
|
||
|
"fmt"
|
||
|
//"git.loafle.net/overflow/overflow_discovery/collector/core/scan/port"
|
||
|
"git.loafle.net/overflow/overflow_discovery/match/packet"
|
||
|
//"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)
|
||
|
|
||
|
bb := lm.Match(0, packet.NewPacket(bytett, rr), nil)
|
||
|
|
||
|
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(ii+1, packet.NewPacket(bytes, read), nil)
|
||
|
|
||
|
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)
|
||
|
|
||
|
//bb := lm.Match(0, packet.NewPacket(bytett, rr), scanInfo)
|
||
|
bb := lm.Match(0, packet.NewPacket(bytett, rr), nil)
|
||
|
|
||
|
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(ii+1, packet.NewPacket(bytes, read), nil)
|
||
|
|
||
|
if b {
|
||
|
t.Log("send Good!")
|
||
|
}
|
||
|
|
||
|
}
|
||
|
//t.Log(scanInfo)
|
||
|
}
|