probe/internal/matcher/matcher.go
2018-08-29 13:08:37 +09:00

96 lines
2.3 KiB
Go

package matcher
import (
osm "git.loafle.net/overflow/service_matcher-go"
"git.loafle.net/overflow/service_matcher-go/elasticsearch"
"git.loafle.net/overflow/service_matcher-go/ftp"
"git.loafle.net/overflow/service_matcher-go/http"
"git.loafle.net/overflow/service_matcher-go/ldap"
"git.loafle.net/overflow/service_matcher-go/lpd"
"git.loafle.net/overflow/service_matcher-go/mongodb"
"git.loafle.net/overflow/service_matcher-go/mysql"
"git.loafle.net/overflow/service_matcher-go/nbss"
"git.loafle.net/overflow/service_matcher-go/postgresql"
"git.loafle.net/overflow/service_matcher-go/redis"
"git.loafle.net/overflow/service_matcher-go/ssh"
"git.loafle.net/overflow/service_matcher-go/telnet"
)
var (
AllMatchers []osm.Matcher
TCPMatchers []osm.Matcher
UDPMatchers []osm.UDPMatcher
TCPPrePacketMatchers []osm.Matcher
TCPNotPrePacketMatchers []osm.Matcher
HTTPSubMatchers []osm.Matcher
)
func init() {
//TCP
addTCPMatcher(ssh.NewMatcher())
addTCPMatcher(mongodb.NewMatcher())
addTCPMatcher(mysql.NewMatcher())
addTCPMatcher(redis.NewMatcher())
addTCPMatcher(postgresql.NewMatcher())
addTCPMatcher(ftp.NewMatcher())
addTCPMatcher(http.NewMatcher())
addTCPMatcher(lpd.NewMatcher())
addTCPMatcher(telnet.NewMatcher())
addTCPMatcher(nbss.NewMatcher())
addTCPMatcher(ldap.NewMatcher())
addTCPMatcher(mysql.NewMatcher())
// UDP
// addUDPMatcher(dns.NewMatcher())
// HTTP-relative
addHTTPSubMatcher(elasticsearch.NewMatcher())
}
func addTCPMatcher(m osm.Matcher) {
AllMatchers = append(AllMatchers, m)
TCPMatchers = append(TCPMatchers, m)
if m.IsPrePacket() {
TCPPrePacketMatchers = append(TCPPrePacketMatchers, m)
} else {
TCPNotPrePacketMatchers = append(TCPNotPrePacketMatchers, m)
}
}
func addUDPMatcher(m osm.UDPMatcher) {
AllMatchers = append(AllMatchers, m)
UDPMatchers = append(UDPMatchers, m)
}
func addHTTPSubMatcher(m osm.Matcher) {
HTTPSubMatchers = append(HTTPSubMatchers, m)
}
func GetTCPMatchers(isPrePacket bool) []osm.Matcher {
if isPrePacket {
return TCPPrePacketMatchers
}
return TCPNotPrePacketMatchers
}
func GetUDPMatchers() []osm.UDPMatcher {
return UDPMatchers
}
func GetHTTPSubMatchers() []osm.Matcher {
return HTTPSubMatchers
}
func GetMatcherByKey(key string) osm.Matcher {
for _, m := range AllMatchers {
if m.Key() == key {
return m
}
}
return nil
}