From 12a11ef19d86132f6dee936aa54403fff9fd2667 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Sun, 15 Sep 2019 15:10:56 +0200 Subject: [PATCH] new: wifi.min.rssi, wifi.ap.ttl and wifi.sta.ttl changes are now applied in realtime --- modules/wifi/wifi.go | 36 ++++++++++++++++++++++++++++++------ modules/wifi/wifi_recon.go | 3 +++ session/environment.go | 3 ++- session/module.go | 6 ++++++ session/module_param.go | 8 ++++++-- 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/modules/wifi/wifi.go b/modules/wifi/wifi.go index 0ba7c7cd..05048c3a 100644 --- a/modules/wifi/wifi.go +++ b/modules/wifi/wifi.go @@ -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", "", diff --git a/modules/wifi/wifi_recon.go b/modules/wifi/wifi_recon.go index a7ae756d..11aa53bd 100644 --- a/modules/wifi/wifi_recon.go +++ b/modules/wifi/wifi_recon.go @@ -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 } } diff --git a/session/environment.go b/session/environment.go index 3f496689..6df23f62 100644 --- a/session/environment.go +++ b/session/environment.go @@ -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) } diff --git a/session/module.go b/session/module.go index 0803023b..857a90a9 100644 --- a/session/module.go +++ b/session/module.go @@ -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() diff --git a/session/module_param.go b/session/module_param.go index 38bf5412..43aaeaa3 100644 --- a/session/module_param.go +++ b/session/module_param.go @@ -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"`