probe/internal/matcher/matcher.go

98 lines
2.4 KiB
Go
Raw Normal View History

2018-08-12 10:24:23 +00:00
package matcher
import (
2018-08-15 07:46:52 +00:00
osm "git.loafle.net/overflow/service_matcher-go"
2018-09-18 03:39:00 +00:00
"git.loafle.net/overflow/service_matcher-go/echo"
2018-08-15 07:46:52 +00:00
"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"
2018-08-12 10:24:23 +00:00
)
var (
2018-08-15 07:46:52 +00:00
AllMatchers []osm.Matcher
2018-08-12 10:24:23 +00:00
2018-08-15 07:46:52 +00:00
TCPMatchers []osm.Matcher
UDPMatchers []osm.UDPMatcher
2018-08-12 10:24:23 +00:00
2018-08-15 07:46:52 +00:00
TCPPrePacketMatchers []osm.Matcher
TCPNotPrePacketMatchers []osm.Matcher
HTTPSubMatchers []osm.Matcher
2018-08-12 10:24:23 +00:00
)
func init() {
//TCP
addTCPMatcher(ssh.NewMatcher())
2018-09-18 03:39:00 +00:00
addTCPMatcher(echo.NewMatcher())
2018-08-12 10:24:23 +00:00
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())
2018-08-12 10:24:23 +00:00
}
2018-08-15 07:46:52 +00:00
func addTCPMatcher(m osm.Matcher) {
2018-08-12 10:24:23 +00:00
AllMatchers = append(AllMatchers, m)
TCPMatchers = append(TCPMatchers, m)
if m.IsPrePacket() {
TCPPrePacketMatchers = append(TCPPrePacketMatchers, m)
} else {
TCPNotPrePacketMatchers = append(TCPNotPrePacketMatchers, m)
}
}
2018-08-15 07:46:52 +00:00
func addUDPMatcher(m osm.UDPMatcher) {
2018-08-12 10:24:23 +00:00
AllMatchers = append(AllMatchers, m)
UDPMatchers = append(UDPMatchers, m)
}
func addHTTPSubMatcher(m osm.Matcher) {
HTTPSubMatchers = append(HTTPSubMatchers, m)
}
2018-08-15 07:46:52 +00:00
func GetTCPMatchers(isPrePacket bool) []osm.Matcher {
2018-08-12 10:24:23 +00:00
if isPrePacket {
return TCPPrePacketMatchers
}
return TCPNotPrePacketMatchers
}
2018-08-15 07:46:52 +00:00
func GetUDPMatchers() []osm.UDPMatcher {
2018-08-12 10:24:23 +00:00
return UDPMatchers
}
func GetHTTPSubMatchers() []osm.Matcher {
return HTTPSubMatchers
}
2018-10-23 05:16:41 +00:00
func GetMatcherByKey(matchCtx *osm.MatchCtx, key string) osm.Matcher {
2018-08-12 10:24:23 +00:00
for _, m := range AllMatchers {
2018-10-23 05:16:41 +00:00
if m.Key(matchCtx) == key {
2018-08-12 10:24:23 +00:00
return m
}
}
return nil
}