wifi module can now use a pcap file as offline recon

This commit is contained in:
Matrix86 2018-03-12 15:32:50 +01:00
parent ce4975fdd1
commit 582e1ae81e

View file

@ -31,6 +31,7 @@ type WiFiModule struct {
session.SessionModule session.SessionModule
handle *pcap.Handle handle *pcap.Handle
source string
channel int channel int
hopPeriod time.Duration hopPeriod time.Duration
frequencies []int frequencies []int
@ -38,6 +39,7 @@ type WiFiModule struct {
stickChan int stickChan int
skipBroken bool skipBroken bool
pktSourceChan chan gopacket.Packet pktSourceChan chan gopacket.Packet
pktSourceChanClosed bool
writes *sync.WaitGroup writes *sync.WaitGroup
reads *sync.WaitGroup reads *sync.WaitGroup
} }
@ -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,7 +152,17 @@ func mhz2chan(freq int) int {
func (w *WiFiModule) Configure() error { func (w *WiFiModule) Configure() error {
var hopPeriod int var hopPeriod int
var err error
if err, w.source = w.StringParam("wifi.source.file"); err != nil {
return err
}
if w.source != "" {
if w.handle, err = pcap.OpenOffline(w.source); err != nil {
return err
}
} else {
ihandle, err := pcap.NewInactiveHandle(w.Session.Interface.Name()) ihandle, err := pcap.NewInactiveHandle(w.Session.Interface.Name())
if err != nil { if err != nil {
return err return err
@ -161,6 +178,7 @@ func (w *WiFiModule) Configure() error {
} else if w.handle, err = ihandle.Activate(); err != nil { } else if w.handle, err = ihandle.Activate(); err != nil {
return err return err
} }
}
if err, w.skipBroken = w.BoolParam("wifi.skip-broken"); err != nil { if err, w.skipBroken = w.BoolParam("wifi.skip-broken"); err != nil {
return err return err
@ -170,6 +188,7 @@ func (w *WiFiModule) Configure() error {
w.hopPeriod = time.Duration(hopPeriod) * time.Millisecond w.hopPeriod = time.Duration(hopPeriod) * time.Millisecond
if w.source == "" {
if err, w.channel = w.IntParam("wifi.recon.channel"); err == nil { if err, w.channel = w.IntParam("wifi.recon.channel"); err == nil {
if err = network.SetInterfaceChannel(w.Session.Interface.Name(), w.channel); err != nil { if err = network.SetInterfaceChannel(w.Session.Interface.Name(), w.channel); err != nil {
return err return err
@ -190,6 +209,7 @@ func (w *WiFiModule) Configure() error {
} 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
if w.pktSourceChanClosed == false {
w.pktSourceChan <- nil 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