mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
new: wifi.min.rssi, wifi.ap.ttl and wifi.sta.ttl changes are now applied in realtime
This commit is contained in:
parent
53b0d81f20
commit
12a11ef19d
5 changed files with 47 additions and 9 deletions
|
@ -138,9 +138,17 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
|
|||
return err
|
||||
}))
|
||||
|
||||
mod.AddParam(session.NewIntParameter("wifi.rssi.min",
|
||||
minRSSI := session.NewIntParameter("wifi.rssi.min",
|
||||
"-200",
|
||||
"Minimum WiFi signal strength in dBm."))
|
||||
"Minimum WiFi signal strength in dBm.")
|
||||
|
||||
mod.AddObservableParam(minRSSI, func(v string) {
|
||||
if err, v := minRSSI.Get(s); err != nil {
|
||||
mod.Error("%v", err)
|
||||
} else if mod.minRSSI = v.(int); mod.Started {
|
||||
mod.Info("wifi.rssi.min set to %d", mod.minRSSI)
|
||||
}
|
||||
})
|
||||
|
||||
deauth := session.NewModuleHandler("wifi.deauth BSSID", `wifi\.deauth ((?:[a-fA-F0-9:]{11,})|all|\*)`,
|
||||
"Start a 802.11 deauth attack, if an access point BSSID is provided, every client will be deauthenticated, otherwise only the selected client. Use 'all', '*' or a broadcast BSSID (ff:ff:ff:ff:ff:ff) to iterate every access point with at least one client and start a deauth attack for each one.",
|
||||
|
@ -189,13 +197,29 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
|
|||
|
||||
mod.AddHandler(assoc)
|
||||
|
||||
mod.AddParam(session.NewIntParameter("wifi.ap.ttl",
|
||||
apTTL := session.NewIntParameter("wifi.ap.ttl",
|
||||
"300",
|
||||
"Seconds of inactivity for an access points to be considered not in range anymore."))
|
||||
"Seconds of inactivity for an access points to be considered not in range anymore.")
|
||||
|
||||
mod.AddParam(session.NewIntParameter("wifi.sta.ttl",
|
||||
mod.AddObservableParam(apTTL, func(v string) {
|
||||
if err, v := apTTL.Get(s); err != nil {
|
||||
mod.Error("%v", err)
|
||||
} else if mod.apTTL = v.(int); mod.Started {
|
||||
mod.Info("wifi.ap.ttl set to %d", mod.apTTL)
|
||||
}
|
||||
})
|
||||
|
||||
staTTL := session.NewIntParameter("wifi.sta.ttl",
|
||||
"300",
|
||||
"Seconds of inactivity for a client station to be considered not in range or not connected to its access point anymore."))
|
||||
"Seconds of inactivity for a client station to be considered not in range or not connected to its access point anymore.")
|
||||
|
||||
mod.AddObservableParam(staTTL, func(v string) {
|
||||
if err, v := staTTL.Get(s); err != nil {
|
||||
mod.Error("%v", err)
|
||||
} else if mod.staTTL = v.(int); mod.Started {
|
||||
mod.Info("wifi.sta.ttl set to %d", mod.staTTL)
|
||||
}
|
||||
})
|
||||
|
||||
mod.AddParam(session.NewStringParameter("wifi.region",
|
||||
"",
|
||||
|
|
|
@ -43,6 +43,9 @@ func (mod *WiFiModule) stationPruner() {
|
|||
}
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
// refresh
|
||||
maxApTTL = time.Duration(mod.apTTL) * time.Second
|
||||
maxStaTTL = time.Duration(mod.staTTL) * time.Second
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,11 +87,12 @@ func (env *Environment) WithCallback(name, value string, cb EnvironmentChangedCa
|
|||
|
||||
func (env *Environment) Set(name, value string) string {
|
||||
env.Lock()
|
||||
defer env.Unlock()
|
||||
|
||||
old := env.Data[name]
|
||||
env.Data[name] = value
|
||||
|
||||
env.Unlock()
|
||||
|
||||
if cb, hasCallback := env.cbs[name]; hasCallback {
|
||||
cb(value)
|
||||
}
|
||||
|
|
|
@ -233,6 +233,12 @@ func (m *SessionModule) AddParam(p *ModuleParam) *ModuleParam {
|
|||
return p
|
||||
}
|
||||
|
||||
func (m *SessionModule) AddObservableParam(p *ModuleParam, cb EnvironmentChangedCallback) *ModuleParam {
|
||||
m.params[p.Name] = p
|
||||
p.RegisterObserver(m.Session, cb)
|
||||
return p
|
||||
}
|
||||
|
||||
func (m *SessionModule) Running() bool {
|
||||
m.StatusLock.RLock()
|
||||
defer m.StatusLock.RUnlock()
|
||||
|
|
|
@ -62,7 +62,7 @@ func NewDecimalParameter(name string, def_value string, desc string) *ModulePara
|
|||
return NewModuleParameter(name, def_value, FLOAT, "^[\\d]+(\\.\\d+)?$", desc)
|
||||
}
|
||||
|
||||
func (p ModuleParam) Validate(value string) (error, interface{}) {
|
||||
func (p ModuleParam) validate(value string) (error, interface{}) {
|
||||
if p.Validator != nil {
|
||||
if !p.Validator.MatchString(value) {
|
||||
return fmt.Errorf("Parameter %s not valid: '%s' does not match rule '%s'.", tui.Bold(p.Name), value, p.Validator.String()), nil
|
||||
|
@ -125,7 +125,7 @@ func (p ModuleParam) getUnlocked(s *Session) string {
|
|||
func (p ModuleParam) Get(s *Session) (error, interface{}) {
|
||||
_, v := s.Env.Get(p.Name)
|
||||
v = p.parse(s, v)
|
||||
return p.Validate(v)
|
||||
return p.validate(v)
|
||||
}
|
||||
|
||||
func (p ModuleParam) Help(padding int) string {
|
||||
|
@ -138,6 +138,10 @@ func (p ModuleParam) Register(s *Session) {
|
|||
s.Env.Set(p.Name, p.Value)
|
||||
}
|
||||
|
||||
func (p ModuleParam) RegisterObserver(s *Session, cb EnvironmentChangedCallback) {
|
||||
s.Env.WithCallback(p.Name, p.Value, cb)
|
||||
}
|
||||
|
||||
type JSONModuleParam struct {
|
||||
Name string `json:"name"`
|
||||
Type ParamType `json:"type"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue