commons_go/matcher/matcher.go
jackdaw@loafle.com eb02693cf5 .
2017-04-10 20:14:12 +09:00

116 lines
4.0 KiB
Go

package matcher
import (
//"loafle.com/overflow/collector/core/scan/service/matcher/activedirectory"
//"loafle.com/overflow/collector/core/scan/service/matcher/cassandra"
//"loafle.com/overflow/collector/core/scan/service/matcher/dns"
//"loafle.com/overflow/collector/core/scan/service/matcher/ftp"
//"loafle.com/overflow/collector/core/scan/service/matcher/http"
//"loafle.com/overflow/collector/core/scan/service/matcher/imap"
//"loafle.com/overflow/collector/core/scan/service/matcher/ldap"
//"loafle.com/overflow/collector/core/scan/service/matcher/mongodb"
//"loafle.com/overflow/collector/core/scan/service/matcher/mssql"
//"loafle.com/overflow/collector/core/scan/service/matcher/mysql"
//"loafle.com/overflow/collector/core/scan/service/matcher/netbios"
"loafle.com/overflow/commons_go/matcher/oracle"
"loafle.com/overflow/commons_go/matcher/packet"
"loafle.com/overflow/commons_go/model/scaninfo"
//"loafle.com/overflow/collector/core/scan/service/matcher/pop"
//"loafle.com/overflow/collector/core/scan/service/matcher/redis"
//"loafle.com/overflow/collector/core/scan/service/matcher/rmi"
//"loafle.com/overflow/collector/core/scan/service/matcher/smb"
//"loafle.com/overflow/collector/core/scan/service/matcher/smtp"
//"loafle.com/overflow/collector/core/scan/service/matcher/snmp"
//"loafle.com/overflow/collector/core/scan/service/matcher/ssh"
//"loafle.com/overflow/collector/core/scan/service/matcher/telnet"
//"loafle.com/overflow/collector/core/scan/service/matcher/wmi"
)
var (
TcpMatchers []Matcher
UdpMatchers []UDPMatcher
)
func init() {
//TCP
//TcpMatchers = append(TcpMatchers, smtp.NewSmtpMatcher())
//TcpMatchers = append(TcpMatchers, ldap.NewLDAPMatcher())
//TcpMatchers = append(TcpMatchers, activedirectory.NewActiveDirectoryMatcher())
//TcpMatchers = append(TcpMatchers, mongodb.NewMongoDBMatcher())
//TcpMatchers = append(TcpMatchers, mysql.NewMySqlMatcher())
//TcpMatchers = append(TcpMatchers, mssql.NewMSSqlMatcher())
//TcpMatchers = append(TcpMatchers, redis.NewRedisMatcher())
//TcpMatchers = append(TcpMatchers, redis.NewRedisProtectedMatcher())
//TcpMatchers = append(TcpMatchers, netbios.NewNetBiosMatcher())
//TcpMatchers = append(TcpMatchers, smb.NewSMBMatcher())
//TcpMatchers = append(TcpMatchers, cassandra.NewCassandraMatcher())
//TcpMatchers = append(TcpMatchers, imap.NewIMAPMatcher())
TcpMatchers = append(TcpMatchers, oracle.NewOracleMatcher())
//TcpMatchers = append(TcpMatchers, pop.NewPOPMatcher())
//TcpMatchers = append(TcpMatchers, wmi.NewWMIMatcher())
//TcpMatchers = append(TcpMatchers, ftp.NewFTPMatcher())
//TcpMatchers = append(TcpMatchers, http.NewHTTPMatcher())
//TcpMatchers = append(TcpMatchers, rmi.NewRMIMatcher())
//TcpMatchers = append(TcpMatchers, ssh.NewSSHMatcher())
//TcpMatchers = append(TcpMatchers, telnet.NewTelnetMatcher())
//UdpMatchers = append(UdpMatchers, dns.NewDnsMatcher())
//UdpMatchers = append(UdpMatchers, snmp.NewSNMPv2Matcher())
//UdpMatchers = append(UdpMatchers, snmp.NewSNMPv3Matcher())
}
type Matcher interface {
Match(index int, packet *packet.Packet, info scaninfo.ServiceScanInfo) bool
PacketCount() int
Packet(index int) *packet.Packet
ServiceName() string
IsError(index int, packet *packet.Packet, info scaninfo.ServiceScanInfo) bool
IsNoResponse(index int) bool
IsPrePacket() bool
}
type UDPMatcher interface {
Matcher
IsSend(port int) bool
}
func GetTcpMatchers(ispre bool) []Matcher {
retMatchers := make([]Matcher, 0)
l := len(TcpMatchers)
for i := 0; i < l; i++ {
c := TcpMatchers[i].IsPrePacket()
if c == ispre {
retMatchers = append(retMatchers, TcpMatchers[i])
}
}
return retMatchers
}
func GetUdpMatchers() []UDPMatcher {
retMatchers := make([]UDPMatcher, 0)
l := len(UdpMatchers)
for i := 0; i < l; i++ {
retMatchers = append(retMatchers, UdpMatchers[i])
}
return retMatchers
}
func GetMatcherByName(serName string) Matcher {
for _, m := range TcpMatchers {
if m.ServiceName() == serName {
return m
}
}
for _, m := range UdpMatchers {
if m.ServiceName() == serName {
return m
}
}
return nil
}