new: added native wifi handshakes capture from wifi.recon module

This commit is contained in:
evilsocket 2019-02-05 19:42:13 +01:00
commit a6cfb2413f
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
9 changed files with 273 additions and 30 deletions

View file

@ -2,9 +2,16 @@ package network
import (
"encoding/json"
"os"
"strconv"
"sync"
"time"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcapgo"
"github.com/evilsocket/islazy/fs"
)
func Dot11Freq2Chan(freq int) int {
@ -174,3 +181,37 @@ func (w *WiFi) Clear() error {
w.aps = make(map[string]*AccessPoint)
return nil
}
func (w *WiFi) SaveHandshakesTo(fileName string, linkType layers.LinkType) error {
w.Lock()
defer w.Unlock()
doHead := !fs.Exists(fileName)
fp, err := os.OpenFile(fileName, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
return err
}
defer fp.Close()
writer := pcapgo.NewWriter(fp)
if doHead {
if err = writer.WriteFileHeader(65536, linkType); err != nil {
return err
}
}
for _, ap := range w.aps {
for _, station := range ap.Clients() {
station.Handshake.EachUnsavedPacket(func(pkt gopacket.Packet) {
err = writer.WritePacket(pkt.Metadata().CaptureInfo, pkt.Data())
})
if err != nil {
return err
}
}
}
return nil
}

View file

@ -96,3 +96,16 @@ func (ap *AccessPoint) Clients() (list []*Station) {
}
return
}
func (ap *AccessPoint) HasHandshakes() bool {
ap.Lock()
defer ap.Unlock()
for _, c := range ap.clients {
if c.Handshake.Complete() {
return true
}
}
return false
}

67
network/wifi_handshake.go Normal file
View file

@ -0,0 +1,67 @@
package network
import (
"github.com/google/gopacket"
"sync"
)
type Handshake struct {
sync.Mutex
Challenges []gopacket.Packet
Responses []gopacket.Packet
Confirmations []gopacket.Packet
unsaved []gopacket.Packet
}
func NewHandshake() *Handshake {
return &Handshake{
Challenges: make([]gopacket.Packet, 0),
Responses: make([]gopacket.Packet, 0),
Confirmations: make([]gopacket.Packet, 0),
unsaved: make([]gopacket.Packet, 0),
}
}
func (h *Handshake) AddFrame(n int, pkt gopacket.Packet) {
h.Lock()
defer h.Unlock()
switch n {
case 0:
h.Challenges = append(h.Challenges, pkt)
case 1:
h.Responses = append(h.Responses, pkt)
case 2:
h.Confirmations = append(h.Confirmations, pkt)
}
h.unsaved = append(h.unsaved, pkt)
}
func (h *Handshake) Complete() bool {
h.Lock()
defer h.Unlock()
nChal := len(h.Challenges)
nResp := len(h.Responses)
nConf := len(h.Confirmations)
return nChal > 0 && nResp > 0 && nConf > 0
}
func (h *Handshake) NumUnsaved() int {
h.Lock()
defer h.Unlock()
return len(h.unsaved)
}
func (h *Handshake) EachUnsavedPacket(cb func(gopacket.Packet)) {
h.Lock()
defer h.Unlock()
for _, pkt := range h.unsaved {
cb(pkt)
}
h.unsaved = make([]gopacket.Packet, 0)
}

View file

@ -14,6 +14,7 @@ type Station struct {
Cipher string `json:"cipher"`
Authentication string `json:"authentication"`
WPS map[string]string `json:"wps"`
Handshake *Handshake `json:"-"`
}
func cleanESSID(essid string) string {
@ -35,6 +36,7 @@ func NewStation(essid, bssid string, frequency int, rssi int8) *Station {
Frequency: frequency,
RSSI: rssi,
WPS: make(map[string]string),
Handshake: NewHandshake(),
}
}