mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
110d288f98
commit
7356bf2295
2 changed files with 37 additions and 26 deletions
|
@ -321,7 +321,7 @@ func (w *WiFiRecon) startDeauth() error {
|
||||||
return errors.New("No base station or client set.")
|
return errors.New("No base station or client set.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WiFiRecon) discoverAccessPoints(radiotapLayer gopacket.Layer, dot11 *layers.Dot11, packet gopacket.Packet) {
|
func (w *WiFiRecon) discoverAccessPoints(radiotap *layers.RadioTap, dot11 *layers.Dot11, packet gopacket.Packet) {
|
||||||
dot11infoLayer := packet.Layer(layers.LayerTypeDot11InformationElement)
|
dot11infoLayer := packet.Layer(layers.LayerTypeDot11InformationElement)
|
||||||
if dot11infoLayer == nil {
|
if dot11infoLayer == nil {
|
||||||
return
|
return
|
||||||
|
@ -335,7 +335,6 @@ func (w *WiFiRecon) discoverAccessPoints(radiotapLayer gopacket.Layer, dot11 *la
|
||||||
dst := dot11.Address1
|
dst := dot11.Address1
|
||||||
// packet sent to broadcast mac with a SSID set?
|
// packet sent to broadcast mac with a SSID set?
|
||||||
if bytes.Compare(dst, network.BroadcastMac) == 0 && len(dot11info.Info) > 0 {
|
if bytes.Compare(dst, network.BroadcastMac) == 0 && len(dot11info.Info) > 0 {
|
||||||
radiotap, _ := radiotapLayer.(*layers.RadioTap)
|
|
||||||
ssid := string(dot11info.Info)
|
ssid := string(dot11info.Info)
|
||||||
bssid := dot11.Address3.String()
|
bssid := dot11.Address3.String()
|
||||||
channel := mhz2chan(int(radiotap.ChannelFrequency))
|
channel := mhz2chan(int(radiotap.ChannelFrequency))
|
||||||
|
@ -343,7 +342,7 @@ func (w *WiFiRecon) discoverAccessPoints(radiotapLayer gopacket.Layer, dot11 *la
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WiFiRecon) discoverClients(radiotapLayer gopacket.Layer, dot11 *layers.Dot11, ap net.HardwareAddr, packet gopacket.Packet) {
|
func (w *WiFiRecon) discoverClients(radiotap *layers.RadioTap, dot11 *layers.Dot11, ap net.HardwareAddr, packet gopacket.Packet) {
|
||||||
// only check data packets of connected stations
|
// only check data packets of connected stations
|
||||||
if dot11.Type.MainType() != layers.Dot11TypeData {
|
if dot11.Type.MainType() != layers.Dot11TypeData {
|
||||||
return
|
return
|
||||||
|
@ -352,7 +351,6 @@ func (w *WiFiRecon) discoverClients(radiotapLayer gopacket.Layer, dot11 *layers.
|
||||||
bssid := dot11.Address1
|
bssid := dot11.Address1
|
||||||
// packet going to this specific BSSID?
|
// packet going to this specific BSSID?
|
||||||
if bytes.Compare(bssid, ap) == 0 {
|
if bytes.Compare(bssid, ap) == 0 {
|
||||||
radiotap, _ := radiotapLayer.(*layers.RadioTap)
|
|
||||||
src := dot11.Address2
|
src := dot11.Address2
|
||||||
channel := mhz2chan(int(radiotap.ChannelFrequency))
|
channel := mhz2chan(int(radiotap.ChannelFrequency))
|
||||||
w.wifi.AddIfNew("", src.String(), false, channel)
|
w.wifi.AddIfNew("", src.String(), false, channel)
|
||||||
|
@ -386,29 +384,17 @@ func (w *WiFiRecon) Start() error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
radiotapLayer := packet.Layer(layers.LayerTypeRadioTap)
|
// perform initial dot11 parsing and layers validation
|
||||||
if radiotapLayer == nil {
|
if ok, radiotap, dot11 := packets.Dot11Parse(packet); ok == true {
|
||||||
continue
|
// keep collecting traffic statistics
|
||||||
}
|
w.updateStats(dot11, packet)
|
||||||
|
|
||||||
dot11Layer := packet.Layer(layers.LayerTypeDot11)
|
|
||||||
if dot11Layer == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
dot11, ok := dot11Layer.(*layers.Dot11)
|
|
||||||
if ok == false {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
w.updateStats(dot11, packet)
|
|
||||||
|
|
||||||
if w.isApSelected() == false {
|
|
||||||
// no access point bssid selected, keep scanning for other aps
|
// no access point bssid selected, keep scanning for other aps
|
||||||
w.discoverAccessPoints(radiotapLayer, dot11, packet)
|
if w.isApSelected() == false {
|
||||||
} else {
|
w.discoverAccessPoints(radiotap, dot11, packet)
|
||||||
// discover stations connected to the selected access point bssid
|
} else {
|
||||||
w.discoverClients(radiotapLayer, dot11, w.accessPoint, packet)
|
// discover stations connected to the selected access point bssid
|
||||||
|
w.discoverClients(radiotap, dot11, w.accessPoint, packet)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,6 +3,7 @@ package packets
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/google/gopacket"
|
||||||
"github.com/google/gopacket/layers"
|
"github.com/google/gopacket/layers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,3 +28,27 @@ func NewDot11Deauth(a1 net.HardwareAddr, a2 net.HardwareAddr, a3 net.HardwareAdd
|
||||||
&deauth,
|
&deauth,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Dot11Parse(packet gopacket.Packet) (ok bool, radiotap *layers.RadioTap, dot11 *layers.Dot11) {
|
||||||
|
ok = false
|
||||||
|
radiotap = nil
|
||||||
|
dot11 = nil
|
||||||
|
|
||||||
|
radiotapLayer := packet.Layer(layers.LayerTypeRadioTap)
|
||||||
|
if radiotapLayer == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
radiotap, ok = radiotapLayer.(*layers.RadioTap)
|
||||||
|
if ok == false || radiotap == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dot11Layer := packet.Layer(layers.LayerTypeDot11)
|
||||||
|
if dot11Layer == nil {
|
||||||
|
ok = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dot11, ok = dot11Layer.(*layers.Dot11)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue