This commit is contained in:
crusader 2018-09-03 22:52:01 +09:00
parent d5bc04d5ee
commit e2ce812f82
7 changed files with 21 additions and 18 deletions

View File

@ -20,7 +20,7 @@ func (m *ElasticSearchMatcher) Key() string {
func (m *ElasticSearchMatcher) Name(matchCtx *osm.MatchCtx) string { func (m *ElasticSearchMatcher) Name(matchCtx *osm.MatchCtx) string {
name := "ElasticSearch" name := "ElasticSearch"
if v, ok := matchCtx.GetAttribute("number"); ok { if v, ok := matchCtx.GetAttribute("number"); ok {
name = name + " (" + v.(string) + ")" name = name + " (" + v + ")"
} }
return name return name
} }

View File

@ -17,7 +17,7 @@ func (m *HTTPMatcher) Key() string {
func (m *HTTPMatcher) Name(matchCtx *osm.MatchCtx) string { func (m *HTTPMatcher) Name(matchCtx *osm.MatchCtx) string {
name := "HTTP" name := "HTTP"
if v, ok := matchCtx.GetAttribute("server"); ok { if v, ok := matchCtx.GetAttribute("server"); ok {
name = name + " (" + v.(string) + ")" name = name + " (" + v + ")"
} }
return name return name
} }

View File

@ -42,7 +42,7 @@ func (m *Matchers) AddPacket(packet *Packet) {
type MatchCtx struct { type MatchCtx struct {
address string address string
port int port int
attributes map[string]interface{} attributes map[string]string
} }
func (mc *MatchCtx) Address() string { func (mc *MatchCtx) Address() string {
@ -53,25 +53,25 @@ func (mc *MatchCtx) Port() int {
return mc.port return mc.port
} }
func (mc *MatchCtx) GetAttribute(key string) (value interface{}, ok bool) { func (mc *MatchCtx) GetAttribute(key string) (value string, ok bool) {
value, ok = mc.attributes[key] value, ok = mc.attributes[key]
return return
} }
func (mc *MatchCtx) SetAttribute(key string, value interface{}) { func (mc *MatchCtx) SetAttribute(key string, value string) {
mc.attributes[key] = value mc.attributes[key] = value
} }
func (mc *MatchCtx) InitAttribute() { func (mc *MatchCtx) InitAttribute() {
mc.attributes = make(map[string]interface{}) mc.attributes = make(map[string]string)
} }
func NewMatchCtx(address string, port int) *MatchCtx { func NewMatchCtx(address string, port int) *MatchCtx {
return &MatchCtx{ return &MatchCtx{
address: address, address: address,
port: port, port: port,
attributes: make(map[string]interface{}), attributes: make(map[string]string),
} }
} }

View File

@ -20,10 +20,10 @@ func (m *MySqlMatcher) Key() string {
func (m *MySqlMatcher) Name(matchCtx *osm.MatchCtx) string { func (m *MySqlMatcher) Name(matchCtx *osm.MatchCtx) string {
name := "MySQL" name := "MySQL"
if v, ok := matchCtx.GetAttribute("version"); ok { if v, ok := matchCtx.GetAttribute("version"); ok {
if strings.Contains(v.(string), "MariaDB") { if strings.Contains(v, "MariaDB") {
name = "MariaDB" name = "MariaDB"
} }
name = name + " (" + v.(string) + ")" name = name + " (" + v + ")"
} }
return name return name
} }

View File

@ -2,6 +2,7 @@ package redis
import ( import (
"bufio" "bufio"
"strconv"
"strings" "strings"
osm "git.loafle.net/overflow/service_matcher-go" osm "git.loafle.net/overflow/service_matcher-go"
@ -23,16 +24,16 @@ func (m *RedisMatcher) Name(matchCtx *osm.MatchCtx) string {
name := "Redis" name := "Redis"
if v, ok := matchCtx.GetAttribute("protected"); ok { if v, ok := matchCtx.GetAttribute("protected"); ok {
if v.(bool) { if _v, _err := strconv.ParseBool(v); nil != _err && _v {
return name + " (protected)" return name + " (protected)"
} }
} }
if v, ok := matchCtx.GetAttribute("redis_mode"); ok { if v, ok := matchCtx.GetAttribute("redis_mode"); ok {
name = name + " " + v.(string) name = name + " " + v
} }
if v, ok := matchCtx.GetAttribute("redis_version"); ok { if v, ok := matchCtx.GetAttribute("redis_version"); ok {
name = name + " (" + v.(string) + ")" name = name + " (" + v + ")"
} }
return name return name
} }
@ -80,7 +81,7 @@ func (m *RedisMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm.Pack
protected := m.checkProtectedMode(packet) protected := m.checkProtectedMode(packet)
matchCtx.SetAttribute("protected", protected) matchCtx.SetAttribute("protected", strconv.FormatBool(protected))
if protected { if protected {
return nil return nil
} }
@ -89,10 +90,11 @@ func (m *RedisMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm.Pack
response := string(packet.Bytes()) response := string(packet.Bytes())
if v, ok := matchCtx.GetAttribute("protected"); ok { if v, ok := matchCtx.GetAttribute("protected"); ok {
if !v.(bool) { if _v, _err := strconv.ParseBool(v); nil != _err && _v {
m.parseResponse(matchCtx, response) m.parseResponse(matchCtx, response)
} }
} }
return nil return nil
case 2: case 2:
sign := string([]rune(resp)[0]) sign := string([]rune(resp)[0])
@ -151,7 +153,7 @@ func (m *RedisMatcher) parseResponse(matchCtx *osm.MatchCtx, response string) {
func (m *RedisMatcher) PacketCount(matchCtx *osm.MatchCtx) int { func (m *RedisMatcher) PacketCount(matchCtx *osm.MatchCtx) int {
if v, ok := matchCtx.GetAttribute("protected"); ok { if v, ok := matchCtx.GetAttribute("protected"); ok {
if v.(bool) { if _v, _err := strconv.ParseBool(v); nil != _err && _v {
return 1 return 1
} }
} }

View File

@ -3,6 +3,7 @@ package sqlserver
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"strconv"
osm "git.loafle.net/overflow/service_matcher-go" osm "git.loafle.net/overflow/service_matcher-go"
) )
@ -118,12 +119,12 @@ func (m *SQLServerMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm.
case 0: case 0:
return nil return nil
case 1: case 1:
matchCtx.SetAttribute("isSSL", true) matchCtx.SetAttribute("isSSL", strconv.FormatBool(true))
return nil return nil
case 2: case 2:
return nil return nil
case 3: case 3:
matchCtx.SetAttribute("isSSL", true) matchCtx.SetAttribute("isSSL", strconv.FormatBool(true))
return nil return nil
default: default:
return osm.NotMatchedError() return osm.NotMatchedError()

View File

@ -19,7 +19,7 @@ func (m *SSHMatcher) Key() string {
func (m *SSHMatcher) Name(matchCtx *osm.MatchCtx) string { func (m *SSHMatcher) Name(matchCtx *osm.MatchCtx) string {
name := "SSH" name := "SSH"
if v, ok := matchCtx.GetAttribute("softwareversion"); ok { if v, ok := matchCtx.GetAttribute("softwareversion"); ok {
name = name + " (" + v.(string) + ")" name = name + " (" + v + ")"
} }
return name return name
} }