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
e36ea214a1
commit
447aaede5b
2 changed files with 38 additions and 33 deletions
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/evilsocket/bettercap-ng/core"
|
"github.com/evilsocket/bettercap-ng/core"
|
||||||
"github.com/evilsocket/bettercap-ng/log"
|
"github.com/evilsocket/bettercap-ng/log"
|
||||||
"github.com/evilsocket/bettercap-ng/network"
|
"github.com/evilsocket/bettercap-ng/network"
|
||||||
|
"github.com/evilsocket/bettercap-ng/packets"
|
||||||
"github.com/evilsocket/bettercap-ng/session"
|
"github.com/evilsocket/bettercap-ng/session"
|
||||||
|
|
||||||
"github.com/google/gopacket"
|
"github.com/google/gopacket"
|
||||||
|
@ -213,47 +214,22 @@ func (w *WDiscovery) Show(by string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WDiscovery) buildDeauthPkt(address1 net.HardwareAddr, address2 net.HardwareAddr, address3 net.HardwareAddr, _type layers.Dot11Type, reason layers.Dot11Reason, seq uint16) []byte {
|
|
||||||
var (
|
|
||||||
deauthLayer layers.Dot11MgmtDeauthentication
|
|
||||||
dot11Layer layers.Dot11
|
|
||||||
radioTapLayer layers.RadioTap
|
|
||||||
)
|
|
||||||
|
|
||||||
deauthLayer.Reason = reason
|
|
||||||
|
|
||||||
dot11Layer.Address1 = address1
|
|
||||||
dot11Layer.Address2 = address2
|
|
||||||
dot11Layer.Address3 = address3
|
|
||||||
dot11Layer.Type = _type
|
|
||||||
dot11Layer.SequenceNumber = seq
|
|
||||||
|
|
||||||
buffer := gopacket.NewSerializeBuffer()
|
|
||||||
gopacket.SerializeLayers(buffer,
|
|
||||||
gopacket.SerializeOptions{
|
|
||||||
ComputeChecksums: true,
|
|
||||||
FixLengths: true,
|
|
||||||
},
|
|
||||||
&radioTapLayer,
|
|
||||||
&dot11Layer,
|
|
||||||
&deauthLayer,
|
|
||||||
)
|
|
||||||
|
|
||||||
return buffer.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WDiscovery) sendDeauthPacket(ap net.HardwareAddr, client net.HardwareAddr) {
|
func (w *WDiscovery) sendDeauthPacket(ap net.HardwareAddr, client net.HardwareAddr) {
|
||||||
for seq := uint16(0); seq < 64; seq++ {
|
for seq := uint16(0); seq < 64; seq++ {
|
||||||
pkt := w.buildDeauthPkt(ap, client, ap, layers.Dot11TypeMgmtDeauthentication, layers.Dot11ReasonClass2FromNonAuth, seq)
|
if err, pkt := packets.NewDot11Deauth(ap, client, ap, layers.Dot11TypeMgmtDeauthentication, layers.Dot11ReasonClass2FromNonAuth, seq); err != nil {
|
||||||
if err := w.handle.WritePacketData(pkt); err != nil {
|
log.Error("Could not create deauth packet: %s", err)
|
||||||
|
continue
|
||||||
|
} else if err := w.handle.WritePacketData(pkt); err != nil {
|
||||||
log.Error("Could not send deauth packet: %s", err)
|
log.Error("Could not send deauth packet: %s", err)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
time.Sleep(2 * time.Millisecond)
|
time.Sleep(2 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
pkt = w.buildDeauthPkt(client, ap, ap, layers.Dot11TypeMgmtDeauthentication, layers.Dot11ReasonClass2FromNonAuth, seq)
|
if err, pkt := packets.NewDot11Deauth(client, ap, ap, layers.Dot11TypeMgmtDeauthentication, layers.Dot11ReasonClass2FromNonAuth, seq); err != nil {
|
||||||
if err := w.handle.WritePacketData(pkt); err != nil {
|
log.Error("Could not create deauth packet: %s", err)
|
||||||
|
continue
|
||||||
|
} else if err := w.handle.WritePacketData(pkt); err != nil {
|
||||||
log.Error("Could not send deauth packet: %s", err)
|
log.Error("Could not send deauth packet: %s", err)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
|
|
29
packets/dot11.go
Normal file
29
packets/dot11.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"github.com/google/gopacket/layers"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewDot11Deauth(a1 net.HardwareAddr, a2 net.HardwareAddr, a3 net.HardwareAddr, t layers.Dot11Type, reason layers.Dot11Reason, seq uint16) (error, []byte) {
|
||||||
|
var (
|
||||||
|
deauth layers.Dot11MgmtDeauthentication
|
||||||
|
dot11Layer layers.Dot11
|
||||||
|
radioTapLayer layers.RadioTap
|
||||||
|
)
|
||||||
|
|
||||||
|
deauth.Reason = reason
|
||||||
|
|
||||||
|
dot11Layer.Address1 = a1
|
||||||
|
dot11Layer.Address2 = a2
|
||||||
|
dot11Layer.Address3 = a3
|
||||||
|
dot11Layer.Type = t
|
||||||
|
dot11Layer.SequenceNumber = seq
|
||||||
|
|
||||||
|
return Serialize(
|
||||||
|
&radioTapLayer,
|
||||||
|
&dot11Layer,
|
||||||
|
&deauth,
|
||||||
|
)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue