2017-12-04 07:27:08 +00:00
|
|
|
package cassandra
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/binary"
|
|
|
|
|
|
|
|
cnsm "git.loafle.net/commons_go/network_service_matcher"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cassandra struct {
|
|
|
|
Version uint8
|
|
|
|
Flags uint8
|
|
|
|
Stream uint16
|
|
|
|
Opcode uint8
|
|
|
|
Length uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
type CassandraMatcher struct {
|
|
|
|
cnsm.Matchers
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *CassandraMatcher) ServiceName() string {
|
2018-03-29 13:55:08 +00:00
|
|
|
return "CASSANDRA"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *CassandraMatcher) String() string {
|
2017-12-04 07:27:08 +00:00
|
|
|
return "Cassandra"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *CassandraMatcher) IsPrePacket() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *CassandraMatcher) HasResponse(index int) bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *CassandraMatcher) IsError(info cnsm.MatchInfo, index int, packet *cnsm.Packet) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *CassandraMatcher) Match(info cnsm.MatchInfo, index int, packet *cnsm.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() cnsm.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(cnsm.NewPacket(writer.Bytes(), writer.Len()))
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|