2018-08-13 07:48:32 +00:00
|
|
|
package nbss
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/binary"
|
|
|
|
|
2018-08-15 07:17:18 +00:00
|
|
|
osm "git.loafle.net/overflow/service_matcher-go"
|
2018-08-13 07:48:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
NBSS_SESSION_REQUEST uint8 = 0x81
|
|
|
|
NBSS_POSITIVE_SESSION_RESPONSE uint8 = 0x82
|
|
|
|
NBSS_NEGATIVE_SESSION_RESPONSE uint8 = 0x83
|
|
|
|
)
|
|
|
|
|
|
|
|
type NBSS struct {
|
|
|
|
MsgType uint8
|
|
|
|
Flags uint8 //0-6 : Reserved, must be zero. 7 : Length extension.
|
|
|
|
Length uint16
|
|
|
|
CalledNameLen uint8
|
|
|
|
CalledName [16]uint16
|
|
|
|
_ uint8
|
|
|
|
CallingNameLen uint8
|
|
|
|
CallingName [16]uint16
|
|
|
|
_ uint8
|
|
|
|
}
|
|
|
|
|
|
|
|
type NBSSMatcher struct {
|
2018-08-15 07:17:18 +00:00
|
|
|
osm.Matchers
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *NBSSMatcher) Key() string {
|
2018-08-13 07:48:32 +00:00
|
|
|
return "NBSS"
|
|
|
|
}
|
|
|
|
|
2018-09-12 04:26:27 +00:00
|
|
|
func (m *NBSSMatcher) Type() string {
|
|
|
|
return "NETWORK"
|
|
|
|
}
|
2018-09-13 08:31:11 +00:00
|
|
|
func (m *NBSSMatcher) Vendor(matchCtx *osm.MatchCtx) string {
|
|
|
|
return "UNKNOWN"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *NBSSMatcher) Version(matchCtx *osm.MatchCtx) string {
|
|
|
|
return "UNKNOWN"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *NBSSMatcher) OsType(matchCtx *osm.MatchCtx) string {
|
|
|
|
return "UNKNOWN"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *NBSSMatcher) OsVersion(matchCtx *osm.MatchCtx) string {
|
|
|
|
return "UNKNOWN"
|
|
|
|
}
|
2018-09-12 04:26:27 +00:00
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *NBSSMatcher) Name(matchCtx *osm.MatchCtx) string {
|
2018-08-13 07:48:32 +00:00
|
|
|
return "NBSS"
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:41:28 +00:00
|
|
|
func (m *NBSSMatcher) IsPrePacket() bool {
|
2018-08-13 07:48:32 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *NBSSMatcher) HasResponse(matchCtx *osm.MatchCtx, index int) bool {
|
2018-08-13 07:48:32 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *NBSSMatcher) IsError(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) bool {
|
2018-08-13 07:48:32 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *NBSSMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) error {
|
2018-08-13 07:48:32 +00:00
|
|
|
|
2018-09-03 06:42:56 +00:00
|
|
|
if packet == nil || !packet.Valid() {
|
2018-08-15 07:17:18 +00:00
|
|
|
return osm.NoPacketReceivedError()
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reader := new(bytes.Buffer)
|
2018-09-03 07:23:25 +00:00
|
|
|
reader.Write(packet.Buffer)
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
n := NBSS{}
|
|
|
|
if err := binary.Read(reader, binary.LittleEndian, &n); err != nil {
|
2018-08-15 07:17:18 +00:00
|
|
|
return osm.NotMatchedError()
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-03 07:56:41 +00:00
|
|
|
switch n.MsgType {
|
|
|
|
case NBSS_POSITIVE_SESSION_RESPONSE, NBSS_NEGATIVE_SESSION_RESPONSE:
|
|
|
|
default:
|
2018-08-15 07:17:18 +00:00
|
|
|
return osm.NotMatchedError()
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-15 07:17:18 +00:00
|
|
|
func NewMatcher() osm.Matcher {
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
m := &NBSSMatcher{}
|
|
|
|
|
|
|
|
tempBuf := new(bytes.Buffer)
|
|
|
|
binary.Write(tempBuf, binary.BigEndian, NBSS{})
|
|
|
|
|
|
|
|
query := NBSS{
|
|
|
|
MsgType: NBSS_SESSION_REQUEST,
|
|
|
|
Flags: 0x00,
|
|
|
|
Length: 0x4400,
|
|
|
|
CalledNameLen: 0x20,
|
|
|
|
CallingNameLen: 0x20,
|
|
|
|
}
|
|
|
|
|
|
|
|
query.CalledName[0] = 0x4D45 // L
|
|
|
|
query.CalledName[1] = 0x4745 // F
|
|
|
|
|
|
|
|
query.CallingName[0] = 0x4D45
|
|
|
|
query.CallingName[1] = 0x4745
|
|
|
|
|
|
|
|
for i := 2; i < 16; i++ {
|
|
|
|
query.CalledName[i] = 0x4143 //Space
|
|
|
|
query.CallingName[i] = 0x4143
|
|
|
|
}
|
|
|
|
writer := new(bytes.Buffer)
|
|
|
|
binary.Write(writer, binary.LittleEndian, query)
|
|
|
|
|
2018-08-15 07:17:18 +00:00
|
|
|
m.AddPacket(osm.NewPacket(writer.Bytes(), writer.Len()))
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|