container_discovery/internal/matcher/matcher.go

107 lines
3.1 KiB
Go
Raw Permalink Normal View History

2018-04-19 11:36:56 +00:00
package matcher
import (
csm "git.loafle.net/commons/service_matcher-go"
"git.loafle.net/commons/service_matcher-go/activedirectory"
"git.loafle.net/commons/service_matcher-go/cassandra"
"git.loafle.net/commons/service_matcher-go/dns"
"git.loafle.net/commons/service_matcher-go/ftp"
"git.loafle.net/commons/service_matcher-go/http"
"git.loafle.net/commons/service_matcher-go/imap"
"git.loafle.net/commons/service_matcher-go/ldap"
"git.loafle.net/commons/service_matcher-go/mongodb"
"git.loafle.net/commons/service_matcher-go/mysql"
"git.loafle.net/commons/service_matcher-go/netbios"
"git.loafle.net/commons/service_matcher-go/oracle"
"git.loafle.net/commons/service_matcher-go/pop"
"git.loafle.net/commons/service_matcher-go/postgresql"
"git.loafle.net/commons/service_matcher-go/redis"
redis_protected "git.loafle.net/commons/service_matcher-go/redis/protected"
"git.loafle.net/commons/service_matcher-go/rmi"
"git.loafle.net/commons/service_matcher-go/smb"
"git.loafle.net/commons/service_matcher-go/smtp"
snmp_v2 "git.loafle.net/commons/service_matcher-go/snmp/v2"
snmp_v3 "git.loafle.net/commons/service_matcher-go/snmp/v3"
"git.loafle.net/commons/service_matcher-go/sqlserver"
"git.loafle.net/commons/service_matcher-go/ssh"
"git.loafle.net/commons/service_matcher-go/telnet"
"git.loafle.net/commons/service_matcher-go/wmi"
)
var (
AllMatchers []csm.Matcher
TCPMatchers []csm.Matcher
UDPMatchers []csm.UDPMatcher
TCPPrePacketMatchers []csm.Matcher
TCPNotPrePacketMatchers []csm.Matcher
)
func init() {
//TCP
addTCPMatcher(smtp.NewMatcher())
addTCPMatcher(ldap.NewMatcher())
addTCPMatcher(activedirectory.NewMatcher())
addTCPMatcher(mongodb.NewMatcher())
addTCPMatcher(mysql.NewMatcher())
addTCPMatcher(sqlserver.NewMatcher())
addTCPMatcher(redis.NewMatcher())
addTCPMatcher(redis_protected.NewMatcher())
addTCPMatcher(netbios.NewMatcher())
addTCPMatcher(smb.NewMatcher())
addTCPMatcher(cassandra.NewMatcher())
addTCPMatcher(imap.NewMatcher())
addTCPMatcher(oracle.NewMatcher())
addTCPMatcher(postgresql.NewMatcher())
addTCPMatcher(pop.NewMatcher())
addTCPMatcher(wmi.NewMatcher())
addTCPMatcher(ftp.NewMatcher())
addTCPMatcher(http.NewMatcher())
addTCPMatcher(rmi.NewMatcher())
addTCPMatcher(ssh.NewMatcher())
addTCPMatcher(telnet.NewMatcher())
// UDP
addUDPMatcher(dns.NewMatcher())
addUDPMatcher(snmp_v2.NewMatcher())
addUDPMatcher(snmp_v3.NewMatcher())
}
func addTCPMatcher(m csm.Matcher) {
AllMatchers = append(AllMatchers, m)
TCPMatchers = append(TCPMatchers, m)
if m.IsPrePacket() {
TCPPrePacketMatchers = append(TCPPrePacketMatchers, m)
} else {
TCPNotPrePacketMatchers = append(TCPNotPrePacketMatchers, m)
}
}
func addUDPMatcher(m csm.UDPMatcher) {
AllMatchers = append(AllMatchers, m)
UDPMatchers = append(UDPMatchers, m)
}
func GetTCPMatchers(isPrePacket bool) []csm.Matcher {
if isPrePacket {
return TCPPrePacketMatchers
}
return TCPNotPrePacketMatchers
}
func GetUDPMatchers() []csm.UDPMatcher {
return UDPMatchers
}
2018-06-21 10:54:31 +00:00
func GetMatcherByKey(key string) csm.Matcher {
2018-04-19 11:36:56 +00:00
for _, m := range AllMatchers {
2018-06-21 10:54:31 +00:00
if m.Key() == key {
2018-04-19 11:36:56 +00:00
return m
}
}
return nil
}