Debian Codegraph @

packets/nbns.go

raw symbols SCIP
1 package packets
2
3 import (
4 "strconv"
5
6 "github.com/evilsocket/islazy/str"
7
8 "github.com/google/gopacket"
9 "github.com/google/gopacket/layers"
10 )
11
12 const (
13 NBNSPort = 137
14 NBNSMinRespSize = 73
15 )
16
17 var (
18 // NBNS hostname resolution request buffer.
19 NBNSRequest = []byte{
20 0x82, 0x28, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
21 0x0, 0x0, 0x20, 0x43, 0x4B, 0x41, 0x41, 0x41, 0x41,
22 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
23 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
24 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x0,
25 0x0, 0x21, 0x0, 0x1,
26 }
27 )
28
29 func NBNSGetMeta(pkt gopacket.Packet) map[string]string {
30 if ludp := pkt.Layer(layers.LayerTypeUDP); ludp != nil {
31 if udp := ludp.(*layers.UDP); udp != nil && udp.SrcPort == NBNSPort && len(udp.Payload) >= NBNSMinRespSize {
32 hostname := str.Trim(string(udp.Payload[57:72]))
33 if strconv.IsPrint(rune(hostname[0])) {
34 return map[string]string{
35 "nbns:hostname": hostname,
36 }
37 }
38 }
39 }
40 return nil
41 }