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
handle *pcap.Handle
source string
channel int
hopPeriod time.Duration
frequencies []int
@ -38,6 +39,7 @@ type WiFiModule struct {
stickChan int
skipBroken bool
pktSourceChan chan gopacket.Packet
pktSourceChanClosed bool
writes *sync.WaitGroup
reads *sync.WaitGroup
}
@ -108,6 +110,11 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
"",
"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",
"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)."))
@ -145,7 +152,17 @@ func mhz2chan(freq int) int {
func (w *WiFiModule) Configure() error {
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())
if err != nil {
return err
@ -161,6 +178,7 @@ func (w *WiFiModule) Configure() error {
} else if w.handle, err = ihandle.Activate(); err != nil {
return err
}
}
if err, w.skipBroken = w.BoolParam("wifi.skip-broken"); err != nil {
return err
@ -170,6 +188,7 @@ func (w *WiFiModule) Configure() error {
w.hopPeriod = time.Duration(hopPeriod) * time.Millisecond
if w.source == "" {
if err, w.channel = w.IntParam("wifi.recon.channel"); err == nil {
if err = network.SetInterfaceChannel(w.Session.Interface.Name(), w.channel); err != nil {
return err
@ -190,6 +209,7 @@ func (w *WiFiModule) Configure() error {
} else {
w.frequencies = frequencies
}
}
return nil
}
@ -380,7 +400,7 @@ func (w *WiFiModule) Start() error {
w.SetRunning(true, func() {
// start channel hopper if needed
if w.channel == 0 {
if w.channel == 0 && w.source == "" {
go w.channelHopper()
}
@ -417,6 +437,7 @@ func (w *WiFiModule) Start() error {
w.updateStats(dot11, packet)
}
}
w.pktSourceChanClosed = true
})
return nil
@ -427,7 +448,9 @@ func (w *WiFiModule) Stop() error {
// wait any pending write operation
w.writes.Wait()
// signal the main for loop we want to exit
if w.pktSourceChanClosed == false {
w.pktSourceChan <- nil
}
// close the pcap handle to make the main for exit
w.handle.Close()
// close the pcap handle to make the main for exit