misc: each module now has its own tagged logging

This commit is contained in:
evilsocket 2019-02-12 15:16:02 +01:00
commit 9cd4e380fb
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
47 changed files with 343 additions and 349 deletions

View file

@ -2,13 +2,13 @@ package wifi
import (
"fmt"
"github.com/bettercap/bettercap/modules/utils"
"net"
"strconv"
"sync"
"time"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/modules/utils"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/packets"
"github.com/bettercap/bettercap/session"
@ -224,7 +224,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
freqs := []int{}
if args[0] != "clear" {
log.Debug("setting hopping channels to %s", args[0])
w.Debug("setting hopping channels to %s", args[0])
for _, s := range str.Comma(args[0]) {
if ch, err := strconv.Atoi(s); err != nil {
return err
@ -239,13 +239,13 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
}
if len(freqs) == 0 {
log.Debug("resetting hopping channels")
w.Debug("resetting hopping channels")
if freqs, err = network.GetSupportedFrequencies(w.Session.Interface.Name()); err != nil {
return err
}
}
log.Debug("new frequencies: %v", freqs)
w.Debug("new frequencies: %v", freqs)
w.frequencies = freqs
// if wifi.recon is not running, this would block forever
@ -338,7 +338,7 @@ func (w *WiFiModule) Configure() error {
return fmt.Errorf("error while setting timeout: %s", err)
} else if w.handle, err = ihandle.Activate(); err != nil {
if retry == 0 && err.Error() == ErrIfaceNotUp {
log.Warning("interface %s is down, bringing it up ...", ifName)
w.Warning("interface %s is down, bringing it up ...", ifName)
if err := network.ActivateInterface(ifName); err != nil {
return err
}
@ -366,14 +366,14 @@ func (w *WiFiModule) Configure() error {
return fmt.Errorf("error while getting supported frequencies of %s: %s", ifName, err)
}
log.Debug("wifi supported frequencies: %v", w.frequencies)
w.Debug("wifi supported frequencies: %v", w.frequencies)
// we need to start somewhere, this is just to check if
// this OS supports switching channel programmatically.
if err = network.SetInterfaceChannel(ifName, 1); err != nil {
return fmt.Errorf("error while initializing %s to channel 1: %s", ifName, err)
}
log.Info("wifi.recon started (min rssi: %d dBm)", w.minRSSI)
w.Info("started (min rssi: %d dBm)", w.minRSSI)
}
}
@ -448,7 +448,7 @@ func (w *WiFiModule) Start() error {
if ok, radiotap, dot11 := packets.Dot11Parse(packet); ok {
// check FCS checksum
if w.skipBroken && !dot11.ChecksumValid() {
log.Debug("Skipping dot11 packet with invalid checksum.")
w.Debug("skipping dot11 packet with invalid checksum.")
continue
}

View file

@ -5,7 +5,6 @@ import (
"net"
"time"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/packets"
"github.com/bettercap/bettercap/session"
@ -49,7 +48,7 @@ func (w *WiFiModule) startAp() error {
if !w.apConfig.Encryption {
enc = tui.Green("Open")
}
log.Info("Sending beacons as SSID %s (%s) on channel %d (%s).",
w.Info("sending beacons as SSID %s (%s) on channel %d (%s).",
tui.Bold(w.apConfig.SSID),
w.apConfig.BSSID.String(),
w.apConfig.Channel,
@ -60,7 +59,7 @@ func (w *WiFiModule) startAp() error {
defer w.writes.Done()
if err, pkt := packets.NewDot11Beacon(w.apConfig, seqn); err != nil {
log.Error("Could not create beacon packet: %s", err)
w.Error("could not create beacon packet: %s", err)
} else {
w.injectPacket(pkt)
}

View file

@ -6,20 +6,19 @@ import (
"net"
"sort"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/packets"
)
func (w *WiFiModule) sendAssocPacket(ap *network.AccessPoint) {
if err, pkt := packets.NewDot11Auth(w.Session.Interface.HW, ap.HW, 1); err != nil {
log.Error("cloud not create auth packet: %s", err)
w.Error("cloud not create auth packet: %s", err)
} else {
w.injectPacket(pkt)
}
if err, pkt := packets.NewDot11AssociationRequest(w.Session.Interface.HW, ap.HW, ap.ESSID(), 1); err != nil {
log.Error("cloud not create association request packet: %s", err)
w.Error("cloud not create association request packet: %s", err)
} else {
w.injectPacket(pkt)
}
@ -36,7 +35,7 @@ func (w *WiFiModule) skipAssoc(to net.HardwareAddr) bool {
func (w *WiFiModule) isAssocSilent() bool {
if err, is := w.BoolParam("wifi.assoc.silent"); err != nil {
log.Warning("%v", err)
w.Warning("%v", err)
} else {
w.assocSilent = is
}
@ -45,7 +44,7 @@ func (w *WiFiModule) isAssocSilent() bool {
func (w *WiFiModule) doAssocOpen() bool {
if err, is := w.BoolParam("wifi.assoc.open"); err != nil {
log.Warning("%v", err)
w.Warning("%v", err)
} else {
w.assocOpen = is
}
@ -78,7 +77,7 @@ func (w *WiFiModule) startAssoc(to net.HardwareAddr) error {
if !w.skipAssoc(ap.HW) {
toAssoc = append(toAssoc, ap)
} else {
log.Debug("skipping ap:%v because skip list %v", ap, w.assocSkip)
w.Debug("skipping ap:%v because skip list %v", ap, w.assocSkip)
}
}
}
@ -104,13 +103,13 @@ func (w *WiFiModule) startAssoc(to net.HardwareAddr) error {
// send the association request frames
for _, ap := range toAssoc {
if w.Running() {
logger := log.Info
logger := w.Info
if w.isAssocSilent() {
logger = log.Debug
logger = w.Debug
}
if ap.IsOpen() && !w.doAssocOpen() {
log.Debug("skipping association for open network %s (wifi.assoc.open is false)", ap.ESSID())
w.Debug("skipping association for open network %s (wifi.assoc.open is false)", ap.ESSID())
} else {
logger("sending association request to AP %s (channel:%d encryption:%s)", ap.ESSID(), ap.Channel(), ap.Encryption)

View file

@ -7,14 +7,13 @@ import (
"sort"
"time"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/packets"
)
func (w *WiFiModule) injectPacket(data []byte) {
if err := w.handle.WritePacketData(data); err != nil {
log.Error("cloud not inject WiFi packet: %s", err)
w.Error("could not inject WiFi packet: %s", err)
w.Session.Queue.TrackError()
} else {
w.Session.Queue.TrackSent(uint64(len(data)))
@ -26,14 +25,14 @@ func (w *WiFiModule) injectPacket(data []byte) {
func (w *WiFiModule) sendDeauthPacket(ap net.HardwareAddr, client net.HardwareAddr) {
for seq := uint16(0); seq < 64 && w.Running(); seq++ {
if err, pkt := packets.NewDot11Deauth(ap, client, ap, seq); err != nil {
log.Error("cloud not create deauth packet: %s", err)
w.Error("could not create deauth packet: %s", err)
continue
} else {
w.injectPacket(pkt)
}
if err, pkt := packets.NewDot11Deauth(client, ap, ap, seq); err != nil {
log.Error("cloud not create deauth packet: %s", err)
w.Error("could not create deauth packet: %s", err)
continue
} else {
w.injectPacket(pkt)
@ -52,7 +51,7 @@ func (w *WiFiModule) skipDeauth(to net.HardwareAddr) bool {
func (w *WiFiModule) isDeauthSilent() bool {
if err, is := w.BoolParam("wifi.deauth.silent"); err != nil {
log.Warning("%v", err)
w.Warning("%v", err)
} else {
w.deauthSilent = is
}
@ -61,7 +60,7 @@ func (w *WiFiModule) isDeauthSilent() bool {
func (w *WiFiModule) doDeauthOpen() bool {
if err, is := w.BoolParam("wifi.deauth.open"); err != nil {
log.Warning("%v", err)
w.Warning("%v", err)
} else {
w.deauthOpen = is
}
@ -101,7 +100,7 @@ func (w *WiFiModule) startDeauth(to net.HardwareAddr) error {
if !w.skipDeauth(ap.HW) && !w.skipDeauth(client.HW) {
toDeauth = append(toDeauth, flow{Ap: ap, Client: client})
} else {
log.Debug("skipping ap:%v client:%v because skip list %v", ap, client, w.deauthSkip)
w.Debug("skipping ap:%v client:%v because skip list %v", ap, client, w.deauthSkip)
}
}
}
@ -130,13 +129,13 @@ func (w *WiFiModule) startDeauth(to net.HardwareAddr) error {
client := deauth.Client
ap := deauth.Ap
if w.Running() {
logger := log.Info
logger := w.Info
if w.isDeauthSilent() {
logger = log.Debug
logger = w.Debug
}
if ap.IsOpen() && !w.doDeauthOpen() {
log.Debug("skipping deauth for open network %s (wifi.deauth.open is false)", ap.ESSID())
w.Debug("skipping deauth for open network %s (wifi.deauth.open is false)", ap.ESSID())
} else {
logger("deauthing client %s from AP %s (channel:%d encryption:%s)", client.String(), ap.ESSID(), ap.Channel(), ap.Encryption)

View file

@ -3,7 +3,6 @@ package wifi
import (
"time"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/network"
)
@ -15,9 +14,9 @@ func (w *WiFiModule) onChannel(channel int, cb func()) {
w.stickChan = channel
if err := network.SetInterfaceChannel(w.Session.Interface.Name(), channel); err != nil {
log.Warning("error while hopping to channel %d: %s", channel, err)
w.Warning("error while hopping to channel %d: %s", channel, err)
} else {
log.Debug("hopped on channel %d", channel)
w.Debug("hopped on channel %d", channel)
}
cb()
@ -29,7 +28,7 @@ func (w *WiFiModule) channelHopper() {
w.reads.Add(1)
defer w.reads.Done()
log.Info("channel hopper started.")
w.Info("channel hopper started.")
for w.Running() {
delay := w.hopPeriod
@ -51,17 +50,17 @@ func (w *WiFiModule) channelHopper() {
channel = w.stickChan
}
log.Debug("hopping on channel %d", channel)
w.Debug("hopping on channel %d", channel)
w.chanLock.Lock()
if err := network.SetInterfaceChannel(w.Session.Interface.Name(), channel); err != nil {
log.Warning("error while hopping to channel %d: %s", channel, err)
w.Warning("error while hopping to channel %d: %s", channel, err)
}
w.chanLock.Unlock()
select {
case _ = <-w.hopChanges:
log.Debug("hop changed")
w.Debug("hop changed")
break loopCurrentChannels
case <-time.After(delay):
if !w.Running() {

View file

@ -4,14 +4,11 @@ import (
"bytes"
"time"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/packets"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/evilsocket/islazy/tui"
)
var maxStationTTL = 5 * time.Minute
@ -20,13 +17,13 @@ func (w *WiFiModule) stationPruner() {
w.reads.Add(1)
defer w.reads.Done()
log.Debug("wifi stations pruner started.")
w.Debug("wifi stations pruner started.")
for w.Running() {
// loop every AP
for _, ap := range w.Session.WiFi.List() {
sinceLastSeen := time.Since(ap.LastSeen)
if sinceLastSeen > maxStationTTL {
log.Debug("station %s not seen in %s, removing.", ap.BSSID(), sinceLastSeen)
w.Debug("station %s not seen in %s, removing.", ap.BSSID(), sinceLastSeen)
w.Session.WiFi.Remove(ap.BSSID())
continue
}
@ -34,7 +31,7 @@ func (w *WiFiModule) stationPruner() {
for _, c := range ap.Clients() {
sinceLastSeen := time.Since(c.LastSeen)
if sinceLastSeen > maxStationTTL {
log.Debug("client %s of station %s not seen in %s, removing.", c.String(), ap.BSSID(), sinceLastSeen)
w.Debug("client %s of station %s not seen in %s, removing.", c.String(), ap.BSSID(), sinceLastSeen)
ap.RemoveClient(c.BSSID())
w.Session.Events.Add("wifi.client.lost", WiFiClientEvent{
@ -75,7 +72,7 @@ func (w *WiFiModule) discoverAccessPoints(radiotap *layers.RadioTap, dot11 *laye
})
}
} else {
log.Debug("skipping %s with %d dBm", from.String(), radiotap.DBMAntennaSignal)
w.Debug("skipping %s with %d dBm", from.String(), radiotap.DBMAntennaSignal)
}
}
}
@ -151,7 +148,7 @@ func (w *WiFiModule) discoverHandshakes(radiotap *layers.RadioTap, dot11 *layers
// first, locate the AP in our list by its BSSID
ap, found := w.Session.WiFi.Get(apMac.String())
if !found {
log.Warning("could not find AP with BSSID %s", apMac.String())
w.Warning("could not find AP with BSSID %s", apMac.String())
return
}
@ -176,8 +173,7 @@ func (w *WiFiModule) discoverHandshakes(radiotap *layers.RadioTap, dot11 *layers
PMKID = "with PMKID"
}
log.Debug("[%s] got frame 1/4 of the %s <-> %s handshake (%s) (anonce:%x)",
tui.Green("wifi"),
w.Debug("got frame 1/4 of the %s <-> %s handshake (%s) (anonce:%x)",
apMac,
staMac,
PMKID,
@ -186,8 +182,7 @@ func (w *WiFiModule) discoverHandshakes(radiotap *layers.RadioTap, dot11 *layers
// [2] (MIC) client is sending SNonce+MIC to the API
station.Handshake.AddFrame(1, packet)
log.Debug("[%s] got frame 2/4 of the %s <-> %s handshake (snonce:%x mic:%x)",
tui.Green("wifi"),
w.Debug("got frame 2/4 of the %s <-> %s handshake (snonce:%x mic:%x)",
apMac,
staMac,
key.Nonce,
@ -196,8 +191,7 @@ func (w *WiFiModule) discoverHandshakes(radiotap *layers.RadioTap, dot11 *layers
// [3]: (INSTALL+ACK+MIC) AP informs the client that the PTK is installed
station.Handshake.AddFrame(2, packet)
log.Debug("[%s] got frame 3/4 of the %s <-> %s handshake (mic:%x)",
tui.Green("wifi"),
w.Debug("got frame 3/4 of the %s <-> %s handshake (mic:%x)",
apMac,
staMac,
key.MIC)
@ -207,9 +201,9 @@ func (w *WiFiModule) discoverHandshakes(radiotap *layers.RadioTap, dot11 *layers
numUnsaved := station.Handshake.NumUnsaved()
doSave := numUnsaved > 0
if doSave && w.shakesFile != "" {
log.Debug("saving handshake frames to %s", w.shakesFile)
w.Debug("saving handshake frames to %s", w.shakesFile)
if err := w.Session.WiFi.SaveHandshakesTo(w.shakesFile, w.handle.LinkType()); err != nil {
log.Error("error while saving handshake frames to %s: %s", w.shakesFile, err)
w.Error("error while saving handshake frames to %s: %s", w.shakesFile, err)
}
}

View file

@ -2,13 +2,13 @@ package wifi
import (
"fmt"
"github.com/bettercap/bettercap/modules/discovery"
"os"
"sort"
"strconv"
"strings"
"time"
"github.com/bettercap/bettercap/modules/discovery"
"github.com/bettercap/bettercap/network"
"github.com/dustin/go-humanize"