-
Notifications
You must be signed in to change notification settings - Fork 3
/
frames.go
127 lines (116 loc) · 3.42 KB
/
frames.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"
"github.com/hkparker/Wave/models"
"net"
)
func sniffInterface(iface string, frames chan models.Wireless80211Frame) {
if handle, err := pcap.OpenLive(iface, 1600, true, 1); err != nil {
log.WithFields(log.Fields{
"at": "sniffInterface",
"error": err,
"interface": iface,
}).Fatal("failed to open pcap handler")
} else {
packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
for packet := range packetSource.Packets() {
radio, ok := packet.Layer(layers.LayerTypeRadioTap).(*layers.RadioTap)
if !ok {
log.WithFields(log.Fields{
"at": "sniffInterface",
}).Info("frame could not be asserted as radio tap")
continue
}
ether, ok := packet.Layer(layers.LayerTypeDot11).(*layers.Dot11)
if !ok {
log.WithFields(log.Fields{
"at": "sniffInterface",
}).Info("packet could not be asserted as 802.11 frame")
continue
}
frame := createFrame(packet, radio, ether, iface)
if rateLimit(frame) {
continue
}
frames <- frame
}
}
}
func createFrame(packet gopacket.Packet, radio *layers.RadioTap, ether *layers.Dot11, iface string) models.Wireless80211Frame {
frame := models.Wireless80211Frame{
Length: radio.Length,
TSFT: radio.TSFT,
FlagsRadio: radio.Flags,
Rate: radio.Rate,
ChannelFrequency: radio.ChannelFrequency,
ChannelFlags: radio.ChannelFlags,
FHSS: radio.FHSS,
DBMAntennaSignal: radio.DBMAntennaSignal,
DBMAntennaNoise: radio.DBMAntennaNoise,
LockQuality: radio.LockQuality,
TxAttenuation: radio.TxAttenuation,
DBTxAttenuation: radio.DBTxAttenuation,
DBMTxPower: radio.DBMTxPower,
Antenna: radio.Antenna,
DBAntennaSignal: radio.DBAntennaSignal,
DBAntennaNoise: radio.DBAntennaNoise,
RxFlags: radio.RxFlags,
TxFlags: radio.TxFlags,
RtsRetries: radio.RtsRetries,
DataRetries: radio.DataRetries,
MCS: radio.MCS,
AMPDUStatus: radio.AMPDUStatus,
VHT: radio.VHT,
Type: fmt.Sprint(ether.Type),
Proto: ether.Proto,
Flags80211: ether.Flags,
DurationID: ether.DurationID,
Address1: fmt.Sprint(ether.Address1),
Address2: fmt.Sprint(ether.Address2),
Address3: fmt.Sprint(ether.Address3),
Address4: fmt.Sprint(ether.Address4),
SequenceNumber: ether.SequenceNumber,
FragmentNumber: ether.FragmentNumber,
Checksum: ether.Checksum,
Interface: iface,
}
frame.ParseElements(packet, ether)
return frame
}
func streamFrames(frames chan models.Wireless80211Frame, wave_host string) {
var ws net.Conn
for {
if !local {
ws = dialWave(wave_host, frames)
}
for frame := range frames {
flat, err := json.Marshal(frame)
if err != nil {
log.WithFields(log.Fields{
"at": "streamFrames",
"error": err,
}).Warn("failed to marshal frame")
continue
}
if print {
fmt.Println(string(flat))
}
if !local {
if _, err := ws.Write([]byte(flat)); err != nil {
ws.Close()
log.WithFields(log.Fields{
"at": "streamFrames",
"error": err,
"wave_host": wave_host,
}).Error("failed to send frame, redailing Wave")
break
}
}
}
}
}