misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2019-03-23 14:11:28 +01:00
commit b8056e2026
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
3 changed files with 27 additions and 78 deletions

View file

@ -23,31 +23,22 @@ import (
"github.com/evilsocket/islazy/tui"
)
type parsedShake struct {
Radiotap *layers.RadioTap
Dot11 *layers.Dot11
Packet gopacket.Packet
}
type WiFiModule struct {
session.SessionModule
iface *network.Endpoint
handle *pcap.Handle
source string
region string
txPower int
minRSSI int
channel int
hopPeriod time.Duration
hopChanges chan bool
frequencies []int
ap *network.AccessPoint
stickChan int
shakesFile string
shakesHistory []parsedShake
iface *network.Endpoint
handle *pcap.Handle
source string
region string
txPower int
minRSSI int
channel int
hopPeriod time.Duration
hopChanges chan bool
frequencies []int
ap *network.AccessPoint
stickChan int
shakesFile string
skipBroken bool
pktSourceChan chan gopacket.Packet
pktSourceChanClosed bool
@ -75,7 +66,6 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
stickChan: 0,
hopPeriod: 250 * time.Millisecond,
hopChanges: make(chan bool),
shakesHistory: make([]parsedShake, 0),
ap: nil,
skipBroken: true,
apRunning: false,
@ -520,41 +510,11 @@ func (mod *WiFiModule) updateStats(dot11 *layers.Dot11, packet gopacket.Packet)
}
}
func (mod *WiFiModule) loadHandshakes() {
mod.shakesHistory = make([]parsedShake, 0)
if !fs.Exists(mod.shakesFile) {
return
}
handle, err := pcap.OpenOffline(mod.shakesFile)
if err != nil {
mod.Debug("can't open handshakes file: %v", mod.shakesFile)
return
}
defer handle.Close()
mod.Info("loading handshakes from %s", mod.shakesFile)
src := gopacket.NewPacketSource(handle, handle.LinkType())
for packet := range src.Packets() {
if ok, radiotap, dot11 := packets.Dot11Parse(packet); ok {
mod.shakesHistory = append(mod.shakesHistory, parsedShake{
Radiotap: radiotap,
Dot11: dot11,
Packet: packet,
})
}
}
}
func (mod *WiFiModule) Start() error {
if err := mod.Configure(); err != nil {
return err
}
mod.loadHandshakes()
mod.SetRunning(true, func() {
// start channel hopper if needed
if mod.channel == 0 && mod.source == "" {
@ -591,7 +551,7 @@ func (mod *WiFiModule) Start() error {
mod.discoverProbes(radiotap, dot11, packet)
mod.discoverAccessPoints(radiotap, dot11, packet)
mod.discoverClients(radiotap, dot11, packet)
mod.discoverHandshakes(radiotap, dot11, packet, false)
mod.discoverHandshakes(radiotap, dot11, packet)
mod.updateInfo(dot11, packet)
mod.updateStats(dot11, packet)
}