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 {
name := "ElasticSearch"
if v, ok := matchCtx.GetAttribute("number"); ok {
name = name + " (" + v.(string) + ")"
name = name + " (" + v + ")"
}
return name
}

View File

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

View File

@ -42,7 +42,7 @@ func (m *Matchers) AddPacket(packet *Packet) {
type MatchCtx struct {
address string
port int
attributes map[string]interface{}
attributes map[string]string
}
func (mc *MatchCtx) Address() string {
@ -53,25 +53,25 @@ func (mc *MatchCtx) Port() int {
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]
return
}
func (mc *MatchCtx) SetAttribute(key string, value interface{}) {
func (mc *MatchCtx) SetAttribute(key string, value string) {
mc.attributes[key] = value
}
func (mc *MatchCtx) InitAttribute() {
mc.attributes = make(map[string]interface{})
mc.attributes = make(map[string]string)
}
func NewMatchCtx(address string, port int) *MatchCtx {
return &MatchCtx{
address: address,
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 {
name := "MySQL"
if v, ok := matchCtx.GetAttribute("version"); ok {
if strings.Contains(v.(string), "MariaDB") {
if strings.Contains(v, "MariaDB") {
name = "MariaDB"
}
name = name + " (" + v.(string) + ")"
name = name + " (" + v + ")"
}
return name
}

View File

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

View File

@ -3,6 +3,7 @@ package sqlserver
import (
"bytes"
"encoding/binary"
"strconv"
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:
return nil
case 1:
matchCtx.SetAttribute("isSSL", true)
matchCtx.SetAttribute("isSSL", strconv.FormatBool(true))
return nil
case 2:
return nil
case 3:
matchCtx.SetAttribute("isSSL", true)
matchCtx.SetAttribute("isSSL", strconv.FormatBool(true))
return nil
default:
return osm.NotMatchedError()

View File

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