Debian Codegraph @

modules/wifi/wifi_hopping.go

raw symbols SCIP
1 package wifiscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/
2
3 import (
4 "netscip-go gomod github.com/golang/go/src go1.16 net/"
5 "timescip-go gomod github.com/golang/go/src go1.16 time/"
6
7 "github.com/bettercap/bettercap/networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/"
8 )
9
10 func (mod *WiFiModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#) isInterfaceConnectedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#isInterfaceConnected().() bool {
11 ifaces, err := netscip-go gomod github.com/golang/go/src go1.16 net/.Interfacesscip-go gomod github.com/golang/go/src go1.16 net/Interfaces().()
12 if err != nil {
13 mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("error while enumerating interfaces: %s", err)
14 return false
15 }
16
17 for _, iface := range ifaces {
18 if mod.ifacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#iface..HwAddressscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#HwAddress. == networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.NormalizeMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/NormalizeMac().(iface.HardwareAddrscip-go gomod github.com/golang/go/src go1.16 net/Interface#HardwareAddr..Stringscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#String().()) {
19 return true
20 }
21 }
22
23 return false
24 }
25
26 func (mod *WiFiModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#) hopUnlockedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#hopUnlocked().(channel int) (mustStop bool) {
27 // mod.Debug("hopping on channel %d", channel)
28
29 if err := networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.SetInterfaceChannelscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/SetInterfaceChannel().(mod.ifacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#iface..Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#Name().(), channel); err != nil {
30 // check if the device has been disconnected
31 if mod.isInterfaceConnectedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#isInterfaceConnected().() == false {
32 mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("interface %s disconnected, stopping module", mod.ifacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#iface..Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#Name().())
33 mustStop = true
34 } else {
35 mod.Warningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Warning().("error while hopping to channel %d: %s", channel, err)
36 }
37 }
38
39 return
40 }
41
42 func (mod *WiFiModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#) hopscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#hop().(channel int) (mustStop bool) {
43 mod.chanLockscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#chanLock..Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().()
44 defer mod.chanLockscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#chanLock..Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().()
45
46 return mod.hopUnlockedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#hopUnlocked().(channel)
47 }
48
49 func (mod *WiFiModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#) onChannelscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#onChannel().(channel int, cb func()) {
50 mod.chanLockscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#chanLock..Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().()
51 defer mod.chanLockscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#chanLock..Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().()
52
53 prev := mod.stickChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#stickChan.
54 mod.stickChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#stickChan. = channel
55
56 mod.hopUnlockedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#hopUnlocked().(channel)
57
58 cb()
59
60 mod.stickChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#stickChan. = prev
61 }
62
63 func (mod *WiFiModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#) channelHopperscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#channelHopper().() {
64 mod.readsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#reads..Addscip-go gomod github.com/golang/go/src go1.16 sync/WaitGroup#Add().(1)
65 defer mod.readsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#reads..Donescip-go gomod github.com/golang/go/src go1.16 sync/WaitGroup#Done().()
66
67 mod.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Info().("channel hopper started.")
68
69 for mod.Runningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Running().() {
70 delay := mod.hopPeriodscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#hopPeriod.
71 // if we have both 2.4 and 5ghz capabilities, we have
72 // more channels, therefore we need to increase the time
73 // we hop on each one otherwise me lose information
74 if len(mod.frequenciesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#frequencies.) > 14 {
75 delay = delay * 2
76 }
77
78 frequencies := mod.frequenciesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#frequencies.
79
80 loopCurrentChannels:
81 for _, frequency := range frequencies {
82 channel := networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.Dot11Freq2Chanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Dot11Freq2Chan().(frequency)
83 // stick to the access point channel as long as it's selected
84 // or as long as we're deauthing on it
85 if mod.stickChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#stickChan. != 0 {
86 channel = mod.stickChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#stickChan.
87 }
88
89 if stop := mod.hopscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#hop().(channel); stop {
90 mod.forcedStopscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#forcedStop().()
91 return
92 }
93
94 select {
95 case <-mod.hopChangesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/wifi`/WiFiModule#hopChanges.:
96 mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("hop changed")
97 break loopCurrentChannels
98 case <-timescip-go gomod github.com/golang/go/src go1.16 time/.Afterscip-go gomod github.com/golang/go/src go1.16 time/After().(delay):
99 if !mod.Runningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Running().() {
100 return
101 }
102 }
103 }
104 }
105 }