mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
wifi module can now use a pcap file as offline recon
This commit is contained in:
parent
ce4975fdd1
commit
582e1ae81e
1 changed files with 63 additions and 40 deletions
|
@ -30,16 +30,18 @@ type WiFiProbe struct {
|
||||||
type WiFiModule struct {
|
type WiFiModule struct {
|
||||||
session.SessionModule
|
session.SessionModule
|
||||||
|
|
||||||
handle *pcap.Handle
|
handle *pcap.Handle
|
||||||
channel int
|
source string
|
||||||
hopPeriod time.Duration
|
channel int
|
||||||
frequencies []int
|
hopPeriod time.Duration
|
||||||
ap *network.AccessPoint
|
frequencies []int
|
||||||
stickChan int
|
ap *network.AccessPoint
|
||||||
skipBroken bool
|
stickChan int
|
||||||
pktSourceChan chan gopacket.Packet
|
skipBroken bool
|
||||||
writes *sync.WaitGroup
|
pktSourceChan chan gopacket.Packet
|
||||||
reads *sync.WaitGroup
|
pktSourceChanClosed bool
|
||||||
|
writes *sync.WaitGroup
|
||||||
|
reads *sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWiFiModule(s *session.Session) *WiFiModule {
|
func NewWiFiModule(s *session.Session) *WiFiModule {
|
||||||
|
@ -108,6 +110,11 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
|
||||||
"",
|
"",
|
||||||
"WiFi channel or empty for channel hopping."))
|
"WiFi channel or empty for channel hopping."))
|
||||||
|
|
||||||
|
w.AddParam(session.NewStringParameter("wifi.source.file",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"If set, the wifi module will read from this pcap file instead of the hardware interface."))
|
||||||
|
|
||||||
w.AddParam(session.NewIntParameter("wifi.hop.period",
|
w.AddParam(session.NewIntParameter("wifi.hop.period",
|
||||||
"250",
|
"250",
|
||||||
"If channel hopping is enabled (empty wifi.recon.channel), this is the time in millseconds the algorithm will hop on every channel (it'll be doubled if both 2.4 and 5.0 bands are available)."))
|
"If channel hopping is enabled (empty wifi.recon.channel), this is the time in millseconds the algorithm will hop on every channel (it'll be doubled if both 2.4 and 5.0 bands are available)."))
|
||||||
|
@ -145,21 +152,32 @@ func mhz2chan(freq int) int {
|
||||||
|
|
||||||
func (w *WiFiModule) Configure() error {
|
func (w *WiFiModule) Configure() error {
|
||||||
var hopPeriod int
|
var hopPeriod int
|
||||||
|
var err error
|
||||||
|
|
||||||
ihandle, err := pcap.NewInactiveHandle(w.Session.Interface.Name())
|
if err, w.source = w.StringParam("wifi.source.file"); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer ihandle.CleanUp()
|
|
||||||
|
|
||||||
if err = ihandle.SetRFMon(true); err != nil {
|
if w.source != "" {
|
||||||
return fmt.Errorf("Error while setting interface %s in monitor mode: %s", core.Bold(w.Session.Interface.Name()), err)
|
if w.handle, err = pcap.OpenOffline(w.source); err != nil {
|
||||||
} else if err = ihandle.SetSnapLen(65536); err != nil {
|
return err
|
||||||
return err
|
}
|
||||||
} else if err = ihandle.SetTimeout(pcap.BlockForever); err != nil {
|
} else {
|
||||||
return err
|
ihandle, err := pcap.NewInactiveHandle(w.Session.Interface.Name())
|
||||||
} else if w.handle, err = ihandle.Activate(); err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
defer ihandle.CleanUp()
|
||||||
|
|
||||||
|
if err = ihandle.SetRFMon(true); err != nil {
|
||||||
|
return fmt.Errorf("Error while setting interface %s in monitor mode: %s", core.Bold(w.Session.Interface.Name()), err)
|
||||||
|
} else if err = ihandle.SetSnapLen(65536); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err = ihandle.SetTimeout(pcap.BlockForever); err != nil {
|
||||||
|
return err
|
||||||
|
} else if w.handle, err = ihandle.Activate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err, w.skipBroken = w.BoolParam("wifi.skip-broken"); err != nil {
|
if err, w.skipBroken = w.BoolParam("wifi.skip-broken"); err != nil {
|
||||||
|
@ -170,25 +188,27 @@ func (w *WiFiModule) Configure() error {
|
||||||
|
|
||||||
w.hopPeriod = time.Duration(hopPeriod) * time.Millisecond
|
w.hopPeriod = time.Duration(hopPeriod) * time.Millisecond
|
||||||
|
|
||||||
if err, w.channel = w.IntParam("wifi.recon.channel"); err == nil {
|
if w.source == "" {
|
||||||
if err = network.SetInterfaceChannel(w.Session.Interface.Name(), w.channel); err != nil {
|
if err, w.channel = w.IntParam("wifi.recon.channel"); err == nil {
|
||||||
return err
|
if err = network.SetInterfaceChannel(w.Session.Interface.Name(), w.channel); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Info("WiFi recon active on channel %d.", w.channel)
|
||||||
|
} else {
|
||||||
|
w.channel = 0
|
||||||
|
// we need to start somewhere, this is just to check if
|
||||||
|
// this OS supports switching channel programmatically.
|
||||||
|
if err = network.SetInterfaceChannel(w.Session.Interface.Name(), 1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Info("WiFi recon active with channel hopping.")
|
||||||
}
|
}
|
||||||
log.Info("WiFi recon active on channel %d.", w.channel)
|
|
||||||
} else {
|
|
||||||
w.channel = 0
|
|
||||||
// we need to start somewhere, this is just to check if
|
|
||||||
// this OS supports switching channel programmatically.
|
|
||||||
if err = network.SetInterfaceChannel(w.Session.Interface.Name(), 1); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
log.Info("WiFi recon active with channel hopping.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if frequencies, err := network.GetSupportedFrequencies(w.Session.Interface.Name()); err != nil {
|
if frequencies, err := network.GetSupportedFrequencies(w.Session.Interface.Name()); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
w.frequencies = frequencies
|
w.frequencies = frequencies
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -380,7 +400,7 @@ func (w *WiFiModule) Start() error {
|
||||||
|
|
||||||
w.SetRunning(true, func() {
|
w.SetRunning(true, func() {
|
||||||
// start channel hopper if needed
|
// start channel hopper if needed
|
||||||
if w.channel == 0 {
|
if w.channel == 0 && w.source == "" {
|
||||||
go w.channelHopper()
|
go w.channelHopper()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,6 +437,7 @@ func (w *WiFiModule) Start() error {
|
||||||
w.updateStats(dot11, packet)
|
w.updateStats(dot11, packet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
w.pktSourceChanClosed = true
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -427,7 +448,9 @@ func (w *WiFiModule) Stop() error {
|
||||||
// wait any pending write operation
|
// wait any pending write operation
|
||||||
w.writes.Wait()
|
w.writes.Wait()
|
||||||
// signal the main for loop we want to exit
|
// signal the main for loop we want to exit
|
||||||
w.pktSourceChan <- nil
|
if w.pktSourceChanClosed == false {
|
||||||
|
w.pktSourceChan <- nil
|
||||||
|
}
|
||||||
// close the pcap handle to make the main for exit
|
// close the pcap handle to make the main for exit
|
||||||
w.handle.Close()
|
w.handle.Close()
|
||||||
// close the pcap handle to make the main for exit
|
// close the pcap handle to make the main for exit
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue