misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2019-02-12 12:12:04 +01:00
commit 57983c6524
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
2 changed files with 95 additions and 91 deletions

View file

@ -2,7 +2,6 @@ package wifi
import ( import (
"bytes" "bytes"
"net"
"time" "time"
"github.com/bettercap/bettercap/log" "github.com/bettercap/bettercap/log"
@ -148,19 +147,7 @@ func allZeros(s []byte) bool {
} }
func (w *WiFiModule) discoverHandshakes(radiotap *layers.RadioTap, dot11 *layers.Dot11, packet gopacket.Packet) { func (w *WiFiModule) discoverHandshakes(radiotap *layers.RadioTap, dot11 *layers.Dot11, packet gopacket.Packet) {
// ref. https://wlan1nde.wordpress.com/2014/10/27/4-way-handshake/ if ok, key, apMac, staMac := packets.Dot11ParseEAPOL(packet, dot11); ok {
if keyLayer := packet.Layer(layers.LayerTypeEAPOLKey); keyLayer != nil {
if key := keyLayer.(*layers.EAPOLKey); key.KeyType == layers.EAPOLKeyTypePairwise {
staMac := net.HardwareAddr{}
apMac := net.HardwareAddr{}
if dot11.Flags.FromDS() {
staMac = dot11.Address1
apMac = dot11.Address2
} else if dot11.Flags.ToDS() {
staMac = dot11.Address2
apMac = dot11.Address1
}
// first, locate the AP in our list by its BSSID // first, locate the AP in our list by its BSSID
ap, found := w.Session.WiFi.Get(apMac.String()) ap, found := w.Session.WiFi.Get(apMac.String())
if !found { if !found {
@ -244,5 +231,4 @@ func (w *WiFiModule) discoverHandshakes(radiotap *layers.RadioTap, dot11 *layers
ap.RemoveClient(staMac.String()) ap.RemoveClient(staMac.String())
} }
} }
}
} }

View file

@ -273,3 +273,21 @@ func Dot11ParseDSSet(packet gopacket.Packet) (bool, int) {
return found, channel return found, channel
} }
func Dot11ParseEAPOL(packet gopacket.Packet, dot11 *layers.Dot11) (ok bool, key *layers.EAPOLKey, apMac net.HardwareAddr, staMac net.HardwareAddr) {
ok = false
// ref. https://wlan1nde.wordpress.com/2014/10/27/4-way-handshake/
if keyLayer := packet.Layer(layers.LayerTypeEAPOLKey); keyLayer != nil {
if key = keyLayer.(*layers.EAPOLKey); key.KeyType == layers.EAPOLKeyTypePairwise {
ok = true
if dot11.Flags.FromDS() {
staMac = dot11.Address1
apMac = dot11.Address2
} else if dot11.Flags.ToDS() {
staMac = dot11.Address2
apMac = dot11.Address1
}
}
}
return
}