ing
This commit is contained in:
73
matcher/pop/pop.go
Normal file
73
matcher/pop/pop.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package pop
|
||||
|
||||
import (
|
||||
"git.loafle.net/overflow/overflow_discovery/match/packet"
|
||||
"git.loafle.net/overflow/overflow_discovery/model/scaninfo"
|
||||
)
|
||||
|
||||
const (
|
||||
COMPARE_STR = "+OK"
|
||||
)
|
||||
|
||||
type POPMatcher struct {
|
||||
sendPackets []*packet.Packet
|
||||
}
|
||||
|
||||
func (p *POPMatcher) Match(index int, packet *packet.Packet, info scaninfo.ServiceScanInfo) bool {
|
||||
|
||||
switch index {
|
||||
case 0:
|
||||
fallthrough
|
||||
case 1:
|
||||
|
||||
recvStr := string(packet.Buffer)
|
||||
|
||||
if len(recvStr) < 3 {
|
||||
return false
|
||||
}
|
||||
|
||||
compareStr := recvStr[0:3]
|
||||
|
||||
if compareStr == COMPARE_STR {
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *POPMatcher) PacketCount() int {
|
||||
return len(p.sendPackets)
|
||||
}
|
||||
func (p *POPMatcher) Packet(index int) *packet.Packet {
|
||||
return p.sendPackets[index]
|
||||
}
|
||||
func (p *POPMatcher) ServiceName() string {
|
||||
return "POPMatcher"
|
||||
}
|
||||
|
||||
func (p *POPMatcher) IsError(index int, packet *packet.Packet, info scaninfo.ServiceScanInfo) bool {
|
||||
return false
|
||||
}
|
||||
func (p *POPMatcher) HasResponse(index int) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *POPMatcher) IsPrePacket() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func NewPOPMatcher() *POPMatcher {
|
||||
|
||||
pm := POPMatcher{}
|
||||
|
||||
reqStr := "QUIT\r\n"
|
||||
byte := make([]byte, len(reqStr))
|
||||
copy(byte[:], reqStr)
|
||||
pm.sendPackets = append(pm.sendPackets, packet.NewPacket(byte, len(reqStr)))
|
||||
|
||||
return &pm
|
||||
|
||||
}
|
||||
86
matcher/pop/pop_test.go
Normal file
86
matcher/pop/pop_test.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package pop
|
||||
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"git.loafle.net/overflow/overflow_discovery/match/packet"
|
||||
|
||||
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPopTLS(t *testing.T) {
|
||||
conn, _ := tls.Dial(
|
||||
"tcp",
|
||||
"192.168.1.15:995",
|
||||
&tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
ServerName: "192.168.1.15",
|
||||
},
|
||||
)
|
||||
|
||||
defer conn.Close()
|
||||
|
||||
pop3Run(conn, t)
|
||||
}
|
||||
|
||||
func TestPopNor(t *testing.T) {
|
||||
|
||||
client, _ := net.Dial("tcp", "192.168.1.15:110")
|
||||
|
||||
defer client.Close()
|
||||
|
||||
pop3Run(client, t)
|
||||
|
||||
}
|
||||
|
||||
func pop3Run(client net.Conn, t *testing.T) {
|
||||
|
||||
lm := NewPOPMatcher()
|
||||
|
||||
//port := types.NewPort("110", types.NewHost("192.168.1.215"), types.TYPE_TCP)
|
||||
//scanInfo := scaninfo.NewServiceScanInfo(port)
|
||||
//var ipport string
|
||||
//ipport = port.Host.Ip + ":" + string(port.Port)
|
||||
//
|
||||
//fmt.Println(ipport)
|
||||
|
||||
bytett := make([]byte, 1024)
|
||||
|
||||
read, _ := client.Read(bytett)
|
||||
|
||||
bb := lm.Match(0, packet.NewPacket(bytett, read), 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)
|
||||
|
||||
rr, _ := client.Read(bytes)
|
||||
|
||||
//fmt.Println(bytes)
|
||||
|
||||
b := lm.Match(ii+1, packet.NewPacket(bytes, rr), nil)
|
||||
|
||||
if b {
|
||||
t.Log("send Good!")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user