new: new wifi.handshakes.aggregate parameter to control how handshakes get saved

This commit is contained in:
evilsocket 2019-08-22 13:21:52 -04:00
commit da565afa9a
No known key found for this signature in database
GPG key ID: 82E42E7F3B34C97E
4 changed files with 63 additions and 26 deletions

View file

@ -39,6 +39,7 @@ type WiFiModule struct {
ap *network.AccessPoint
stickChan int
shakesFile string
shakesAggregate bool
skipBroken bool
pktSourceChan chan gopacket.Packet
pktSourceChanClosed bool
@ -59,26 +60,27 @@ type WiFiModule struct {
func NewWiFiModule(s *session.Session) *WiFiModule {
mod := &WiFiModule{
SessionModule: session.NewSessionModule("wifi", s),
iface: s.Interface,
minRSSI: -200,
channel: 0,
stickChan: 0,
hopPeriod: 250 * time.Millisecond,
hopChanges: make(chan bool),
ap: nil,
skipBroken: true,
apRunning: false,
deauthSkip: []net.HardwareAddr{},
deauthSilent: false,
deauthOpen: false,
assocSkip: []net.HardwareAddr{},
assocSilent: false,
assocOpen: false,
showManuf: false,
writes: &sync.WaitGroup{},
reads: &sync.WaitGroup{},
chanLock: &sync.Mutex{},
SessionModule: session.NewSessionModule("wifi", s),
iface: s.Interface,
minRSSI: -200,
channel: 0,
stickChan: 0,
hopPeriod: 250 * time.Millisecond,
hopChanges: make(chan bool),
ap: nil,
skipBroken: true,
apRunning: false,
deauthSkip: []net.HardwareAddr{},
deauthSilent: false,
deauthOpen: false,
assocSkip: []net.HardwareAddr{},
assocSilent: false,
assocOpen: false,
showManuf: false,
shakesAggregate: true,
writes: &sync.WaitGroup{},
reads: &sync.WaitGroup{},
chanLock: &sync.Mutex{},
}
mod.InitState("channels")
@ -220,6 +222,10 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
"",
"File path of the pcap file to save handshakes to."))
mod.AddParam(session.NewBoolParameter("wifi.handshakes.aggregate",
"true",
"If true, all handshakes will be saved inside a single file, otherwise a folder with per-network pcap files will be created."))
mod.AddParam(session.NewStringParameter("wifi.ap.ssid",
"FreeWiFi",
"",
@ -364,6 +370,8 @@ func (mod *WiFiModule) Configure() error {
if mod.shakesFile, err = fs.Expand(mod.shakesFile); err != nil {
return err
}
} else if err, mod.shakesAggregate = mod.BoolParam("wifi.handshakes.aggregate"); err != nil {
return err
}
if err, ifName = mod.StringParam("wifi.interface"); err != nil {

View file

@ -2,6 +2,8 @@ package wifi
import (
"bytes"
"fmt"
"path"
"github.com/bettercap/bettercap/packets"
@ -85,11 +87,15 @@ func (mod *WiFiModule) discoverHandshakes(radiotap *layers.RadioTap, dot11 *laye
// if we have unsaved packets as part of the handshake, save them.
numUnsaved := station.Handshake.NumUnsaved()
shakesFileName := mod.shakesFile
doSave := numUnsaved > 0
if doSave && mod.shakesFile != "" {
mod.Debug("saving handshake frames to %s", mod.shakesFile)
if err := mod.Session.WiFi.SaveHandshakesTo(mod.shakesFile, mod.handle.LinkType()); err != nil {
mod.Error("error while saving handshake frames to %s: %s", mod.shakesFile, err)
if doSave && shakesFileName != "" {
if mod.shakesAggregate == false {
shakesFileName = path.Join(shakesFileName, fmt.Sprintf("%s.pcap", station.PathFriendlyName()))
}
mod.Debug("saving handshake frames to %s", shakesFileName)
if err := mod.Session.WiFi.SaveHandshakesTo(shakesFileName, mod.handle.LinkType()); err != nil {
mod.Error("error while saving handshake frames to %s: %s", shakesFileName, err)
}
}
@ -97,7 +103,7 @@ func (mod *WiFiModule) discoverHandshakes(radiotap *layers.RadioTap, dot11 *laye
// or it contains the PMKID, generate a new event.
if doSave && (rawPMKID != nil || station.Handshake.Half() || station.Handshake.Complete()) {
mod.Session.Events.Add("wifi.client.handshake", HandshakeEvent{
File: mod.shakesFile,
File: shakesFileName,
NewPackets: numUnsaved,
AP: apMac.String(),
Station: staMac.String(),