2017-12-04 07:27:08 +00:00
|
|
|
package smtp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
cnsm "git.loafle.net/commons_go/network_service_matcher"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SmtpMatcher struct {
|
|
|
|
cnsm.Matchers
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SmtpMatcher) ServiceName() string {
|
|
|
|
return "SMTP"
|
|
|
|
}
|
|
|
|
|
2018-03-29 13:55:08 +00:00
|
|
|
func (t *SmtpMatcher) String() string {
|
|
|
|
return "SMTP"
|
|
|
|
}
|
|
|
|
|
2017-12-04 07:27:08 +00:00
|
|
|
func (t *SmtpMatcher) IsPrePacket() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SmtpMatcher) HasResponse(index int) bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SmtpMatcher) IsError(info cnsm.MatchInfo, index int, packet *cnsm.Packet) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SmtpMatcher) Match(info cnsm.MatchInfo, index int, packet *cnsm.Packet) bool {
|
|
|
|
if packet == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
buf := string(packet.Buffer)
|
|
|
|
if len(buf) == 0 || len(buf) < 5 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
splits := strings.Split(buf, "\r\n")
|
|
|
|
splits = strings.Split(buf, " ")
|
|
|
|
if index == 0 {
|
|
|
|
if splits[0] == "220" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
} else if index == 1 {
|
|
|
|
if splits[0] == "250" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
} else if index == 2 {
|
|
|
|
if splits[0] == "221" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMatcher() cnsm.Matcher {
|
|
|
|
|
|
|
|
m := &SmtpMatcher{}
|
|
|
|
|
|
|
|
b := []byte("helo test\r\n")
|
|
|
|
m.AddPacket(cnsm.NewPacket(b, len(b)))
|
|
|
|
|
|
|
|
b = []byte("quit\r\n")
|
|
|
|
m.AddPacket(cnsm.NewPacket(b, len(b)))
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|