| 1 | package wifiscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.16 bytes/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 6 | "github.com/bettercap/bettercap/networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/" |
| 7 | "github.com/bettercap/bettercap/packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/" |
| 8 | "github.com/google/gopacket/layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/" |
| 9 | "netscip-go gomod github.com/golang/go/src go1.16 net/" |
| 10 | ) |
| 11 | |
| 12 | func (mod *WiFiModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#) isCSASilentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#isCSASilent().() bool { |
| 13 | if err, is := mod.BoolParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#BoolParam().("wifi.channel_switch_announce.silent"); err != nil { |
| 14 | mod.Warningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Warning().("%v", err) |
| 15 | } else { |
| 16 | mod.csaSilentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#csaSilent. = is |
| 17 | } |
| 18 | return mod.csaSilentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#csaSilent. |
| 19 | } |
| 20 | |
| 21 | func (mod *WiFiModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#) sendBeaconWithCSAPacketscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#sendBeaconWithCSAPacket().(ap *networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#, toChan int8) { |
| 22 | ssid := ap.ESSIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#ESSID().() |
| 23 | if ssid == "<hidden>" { |
| 24 | ssid = "" |
| 25 | } |
| 26 | hw, _ := netscip-go gomod github.com/golang/go/src go1.16 net/.ParseMACscip-go gomod github.com/golang/go/src go1.16 net/ParseMAC().(ap.BSSIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#BSSID().()) |
| 27 | |
| 28 | for seq := uint16(0); seq < 256 && mod.Runningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Running().(); seq++ { |
| 29 | if err, pkt := packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.NewDot11Beaconscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/NewDot11Beacon().(packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.Dot11ApConfigscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Dot11ApConfig#{ |
| 30 | SSIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Dot11ApConfig#SSID.: ssid, |
| 31 | BSSIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Dot11ApConfig#BSSID.: hw, |
| 32 | Channelscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Dot11ApConfig#Channel.: ap.Channelscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#Channel., |
| 33 | Encryptionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Dot11ApConfig#Encryption.: false, |
| 34 | SpectrumManagementscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Dot11ApConfig#SpectrumManagement.: true, |
| 35 | }, 0, packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.Dot11Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Dot11Info().(layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.Dot11InformationElementIDSwitchChannelAnnouncescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Dot11InformationElementIDSwitchChannelAnnounce., []byte{0, byte(toChan), 1})); err != nil { |
| 36 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("could not create beacon packet: %s", err) |
| 37 | continue |
| 38 | } else { |
| 39 | mod.injectPacketscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#injectPacket().(pkt) |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | func (mod *WiFiModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#) startCSAscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#startCSA().(to netscip-go gomod github.com/golang/go/src go1.16 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#, toChan int8) error { |
| 45 | // if not already running, temporarily enable the pcap handle |
| 46 | // for packet injection |
| 47 | if !mod.Runningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Running().() { |
| 48 | if err := mod.Configurescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#Configure().(); err != nil { |
| 49 | return err |
| 50 | } |
| 51 | defer mod.handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#handle..Closescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/Handle#Close().() |
| 52 | } |
| 53 | |
| 54 | var ap *networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint# = nil |
| 55 | |
| 56 | for _, _ap := range mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..WiFiscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#WiFi..Listscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/WiFi#List().() { |
| 57 | if bytesscip-go gomod github.com/golang/go/src go1.16 bytes/.Equalscip-go gomod github.com/golang/go/src go1.16 bytes/Equal().(_ap.HWscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#HW., to) { |
| 58 | ap = _ap |
| 59 | } |
| 60 | |
| 61 | } |
| 62 | |
| 63 | if ap == nil { |
| 64 | return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("%s is an unknown BSSID", to.Stringscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#String().()) |
| 65 | } |
| 66 | |
| 67 | mod.writesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#writes..Addscip-go gomod github.com/golang/go/src go1.16 sync/WaitGroup#Add().(1) |
| 68 | go func() { |
| 69 | defer mod.writesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#writes..Donescip-go gomod github.com/golang/go/src go1.16 sync/WaitGroup#Done().() |
| 70 | |
| 71 | if mod.Runningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Running().() { |
| 72 | logger := mod.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Info(). |
| 73 | if mod.isCSASilentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#isCSASilent().() { |
| 74 | logger = mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug(). |
| 75 | } |
| 76 | logger("channel hop attack in AP %s (channel:%d encryption:%s), hop to channel %d ", ap.ESSIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#ESSID().(), ap.Channelscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#Channel., ap.Encryptionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#Encryption., toChan) |
| 77 | // send the beacon frame with channel switch announce element id |
| 78 | mod.onChannelscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#onChannel().(ap.Channelscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#Channel., func() { |
| 79 | mod.sendBeaconWithCSAPacketscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#sendBeaconWithCSAPacket().(ap, toChan) |
| 80 | }) |
| 81 | } |
| 82 | |
| 83 | }() |
| 84 | |
| 85 | return nil |
| 86 | } |