overflow_discovery/service/matcher/cassandra/cassandra.go
crusader 3dd6cb79ca ing
2017-11-21 21:47:55 +09:00

95 lines
1.5 KiB
Go

package cassandra
import (
"bytes"
"encoding/binary"
"git.loafle.net/overflow/overflow_discovery/service/matcher"
)
type cassandra struct {
Version uint8
Flags uint8
Stream uint16
Opcode uint8
Length uint32
}
type CassandraMatcher struct {
matcher.Matchers
}
func (m *CassandraMatcher) ServiceName() string {
return "Cassandra"
}
func (m *CassandraMatcher) IsPrePacket() bool {
return false
}
func (m *CassandraMatcher) HasResponse(index int) bool {
return true
}
func (m *CassandraMatcher) IsError(info matcher.MatchInfo, index int, packet *matcher.Packet) bool {
return false
}
func (m *CassandraMatcher) Match(info matcher.MatchInfo, index int, packet *matcher.Packet) bool {
if packet == nil {
return false
}
reader := new(bytes.Buffer)
reader.Write(packet.Buffer)
c := cassandra{}
if err := binary.Read(reader, binary.BigEndian, &c); err != nil {
return false
}
if c.Version != 0x84 {
return false
}
if c.Flags != 0x00 {
return false
}
if c.Stream != 0x00 {
return false
}
if c.Opcode != 0x06 {
return false
}
//var itemcount uint16
//if binary.Read(reader, binary.BigEndian, &itemcount) != nil {
// return false
//}
//
//if itemcount != 0 && itemcount != 2 {
// return false
//}
return true
}
func NewMatcher() matcher.Matcher {
m := &CassandraMatcher{}
c := cassandra{
Version: 4,
Flags: 0,
Stream: 0,
Opcode: 5,
Length: 0,
}
writer := new(bytes.Buffer)
binary.Write(writer, binary.LittleEndian, c)
m.AddPacket(matcher.NewPacket(writer.Bytes(), writer.Len()))
return m
}