mirror of
https://github.com/bettercap/bettercap
synced 2025-07-06 13:02:12 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
f3e9c314e2
commit
afb66a7c4d
4 changed files with 50 additions and 46 deletions
4
caplets/airmon.cap
Normal file
4
caplets/airmon.cap
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
set ticker.commands clear; wifi.show
|
||||||
|
wifi.recon on
|
||||||
|
clear
|
||||||
|
ticker on
|
|
@ -8,33 +8,33 @@ import (
|
||||||
"github.com/evilsocket/bettercap-ng/session"
|
"github.com/evilsocket/bettercap-ng/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WLan struct {
|
type WiFi struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
Session *session.Session
|
Session *session.Session
|
||||||
Interface *network.Endpoint
|
Interface *network.Endpoint
|
||||||
Stations map[string]*WirelessStation
|
Stations map[string]*WiFiStation
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWLan(s *session.Session, iface *network.Endpoint) *WLan {
|
func NewWiFi(s *session.Session, iface *network.Endpoint) *WiFi {
|
||||||
return &WLan{
|
return &WiFi{
|
||||||
Session: s,
|
Session: s,
|
||||||
Interface: iface,
|
Interface: iface,
|
||||||
Stations: make(map[string]*WirelessStation),
|
Stations: make(map[string]*WiFiStation),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WLan) List() (list []*WirelessStation) {
|
func (w *WiFi) List() (list []*WiFiStation) {
|
||||||
w.Lock()
|
w.Lock()
|
||||||
defer w.Unlock()
|
defer w.Unlock()
|
||||||
|
|
||||||
list = make([]*WirelessStation, 0)
|
list = make([]*WiFiStation, 0)
|
||||||
for _, t := range w.Stations {
|
for _, t := range w.Stations {
|
||||||
list = append(list, t)
|
list = append(list, t)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WLan) Remove(mac string) {
|
func (w *WiFi) Remove(mac string) {
|
||||||
w.Lock()
|
w.Lock()
|
||||||
defer w.Unlock()
|
defer w.Unlock()
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ func (w *WLan) Remove(mac string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WLan) AddIfNew(ssid, mac string, isAp bool, channel int) *WirelessStation {
|
func (w *WiFi) AddIfNew(ssid, mac string, isAp bool, channel int) *WiFiStation {
|
||||||
w.Lock()
|
w.Lock()
|
||||||
defer w.Unlock()
|
defer w.Unlock()
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ func (w *WLan) AddIfNew(ssid, mac string, isAp bool, channel int) *WirelessStati
|
||||||
return station
|
return station
|
||||||
}
|
}
|
||||||
|
|
||||||
newStation := NewWirelessStation(ssid, mac, isAp, channel)
|
newStation := NewWiFiStation(ssid, mac, isAp, channel)
|
||||||
w.Stations[mac] = newStation
|
w.Stations[mac] = newStation
|
||||||
|
|
||||||
w.Session.Events.Add("wifi.station.new", newStation)
|
w.Session.Events.Add("wifi.station.new", newStation)
|
||||||
|
@ -62,7 +62,7 @@ func (w *WLan) AddIfNew(ssid, mac string, isAp bool, channel int) *WirelessStati
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WLan) Clear() error {
|
func (w *WiFi) Clear() error {
|
||||||
w.Stations = make(map[string]*WirelessStation)
|
w.Stations = make(map[string]*WiFiStation)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
|
@ -25,7 +25,7 @@ import (
|
||||||
type WDiscovery struct {
|
type WDiscovery struct {
|
||||||
session.SessionModule
|
session.SessionModule
|
||||||
|
|
||||||
wlan *WLan
|
wifi *WiFi
|
||||||
handle *pcap.Handle
|
handle *pcap.Handle
|
||||||
BroadcastMac []byte
|
BroadcastMac []byte
|
||||||
cliTarget net.HardwareAddr
|
cliTarget net.HardwareAddr
|
||||||
|
@ -34,30 +34,30 @@ type WDiscovery struct {
|
||||||
|
|
||||||
func NewWDiscovery(s *session.Session) *WDiscovery {
|
func NewWDiscovery(s *session.Session) *WDiscovery {
|
||||||
w := &WDiscovery{
|
w := &WDiscovery{
|
||||||
SessionModule: session.NewSessionModule("wlan.recon", s),
|
SessionModule: session.NewSessionModule("wifi.recon", s),
|
||||||
cliTarget: make([]byte, 0),
|
cliTarget: make([]byte, 0),
|
||||||
apTarget: make([]byte, 0),
|
apTarget: make([]byte, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
w.AddHandler(session.NewModuleHandler("wlan.recon on", "",
|
w.AddHandler(session.NewModuleHandler("wifi.recon on", "",
|
||||||
"Start 802.11 wireless base stations discovery.",
|
"Start 802.11 wireless base stations discovery.",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
return w.Start()
|
return w.Start()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
w.AddHandler(session.NewModuleHandler("wlan.recon off", "",
|
w.AddHandler(session.NewModuleHandler("wifi.recon off", "",
|
||||||
"Stop 802.11 wireless base stations discovery.",
|
"Stop 802.11 wireless base stations discovery.",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
return w.Stop()
|
return w.Stop()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
w.AddHandler(session.NewModuleHandler("wlan.deauth", "",
|
w.AddHandler(session.NewModuleHandler("wifi.deauth", "",
|
||||||
"Start a 802.11 deauth attack (use ticker to iterate the attack).",
|
"Start a 802.11 deauth attack (use ticker to iterate the attack).",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
return w.startDeauth()
|
return w.startDeauth()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
w.AddHandler(session.NewModuleHandler("wlan.recon set client MAC", "wlan.recon set client ((?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2}))",
|
w.AddHandler(session.NewModuleHandler("wifi.recon set client MAC", "wifi.recon set client ((?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2}))",
|
||||||
"Set client to deauth (single target).",
|
"Set client to deauth (single target).",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
var err error
|
var err error
|
||||||
|
@ -65,35 +65,35 @@ func NewWDiscovery(s *session.Session) *WDiscovery {
|
||||||
return err
|
return err
|
||||||
}))
|
}))
|
||||||
|
|
||||||
w.AddHandler(session.NewModuleHandler("wlan.recon clear client", "",
|
w.AddHandler(session.NewModuleHandler("wifi.recon clear client", "",
|
||||||
"Remove client to deauth.",
|
"Remove client to deauth.",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
w.cliTarget = make([]byte, 0)
|
w.cliTarget = make([]byte, 0)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
w.AddHandler(session.NewModuleHandler("wlan.recon set bs MAC", "wlan.recon set bs ((?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2}))",
|
w.AddHandler(session.NewModuleHandler("wifi.recon set bs MAC", "wifi.recon set bs ((?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2}))",
|
||||||
"Set 802.11 base station address to filter for.",
|
"Set 802.11 base station address to filter for.",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
var err error
|
var err error
|
||||||
if w.wlan != nil {
|
if w.wifi != nil {
|
||||||
w.wlan.Clear()
|
w.wifi.Clear()
|
||||||
}
|
}
|
||||||
w.apTarget, err = net.ParseMAC(args[0])
|
w.apTarget, err = net.ParseMAC(args[0])
|
||||||
return err
|
return err
|
||||||
}))
|
}))
|
||||||
|
|
||||||
w.AddHandler(session.NewModuleHandler("wlan.recon clear bs", "",
|
w.AddHandler(session.NewModuleHandler("wifi.recon clear bs", "",
|
||||||
"Remove the 802.11 base station filter.",
|
"Remove the 802.11 base station filter.",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
if w.wlan != nil {
|
if w.wifi != nil {
|
||||||
w.wlan.Clear()
|
w.wifi.Clear()
|
||||||
}
|
}
|
||||||
w.apTarget = make([]byte, 0)
|
w.apTarget = make([]byte, 0)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
w.AddHandler(session.NewModuleHandler("wlan.show", "",
|
w.AddHandler(session.NewModuleHandler("wifi.show", "",
|
||||||
"Show current hosts list (default sorting by essid).",
|
"Show current hosts list (default sorting by essid).",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
return w.Show("essid")
|
return w.Show("essid")
|
||||||
|
@ -103,7 +103,7 @@ func NewWDiscovery(s *session.Session) *WDiscovery {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w WDiscovery) Name() string {
|
func (w WDiscovery) Name() string {
|
||||||
return "wlan.recon"
|
return "wifi.recon"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w WDiscovery) Description() string {
|
func (w WDiscovery) Description() string {
|
||||||
|
@ -114,7 +114,7 @@ func (w WDiscovery) Author() string {
|
||||||
return "Gianluca Braga <matrix86@protonmail.com>"
|
return "Gianluca Braga <matrix86@protonmail.com>"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WDiscovery) getRow(station *WirelessStation) []string {
|
func (w *WDiscovery) getRow(station *WiFiStation) []string {
|
||||||
sinceStarted := time.Since(w.Session.StartedAt)
|
sinceStarted := time.Since(w.Session.StartedAt)
|
||||||
sinceFirstSeen := time.Since(station.FirstSeen)
|
sinceFirstSeen := time.Since(station.FirstSeen)
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ func mhz2chan(freq int) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type ByEssidSorter []*WirelessStation
|
type ByEssidSorter []*WiFiStation
|
||||||
|
|
||||||
func (a ByEssidSorter) Len() int { return len(a) }
|
func (a ByEssidSorter) Len() int { return len(a) }
|
||||||
func (a ByEssidSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
func (a ByEssidSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
|
@ -162,11 +162,11 @@ func (a ByEssidSorter) Less(i, j int) bool {
|
||||||
return a[i].ESSID() < a[j].ESSID()
|
return a[i].ESSID() < a[j].ESSID()
|
||||||
}
|
}
|
||||||
|
|
||||||
type ByWlanSeenSorter []*WirelessStation
|
type BywifiSeenSorter []*WiFiStation
|
||||||
|
|
||||||
func (a ByWlanSeenSorter) Len() int { return len(a) }
|
func (a BywifiSeenSorter) Len() int { return len(a) }
|
||||||
func (a ByWlanSeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
func (a BywifiSeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
func (a ByWlanSeenSorter) Less(i, j int) bool {
|
func (a BywifiSeenSorter) Less(i, j int) bool {
|
||||||
return a[i].LastSeen.After(a[j].LastSeen)
|
return a[i].LastSeen.After(a[j].LastSeen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,13 +180,13 @@ func (w *WDiscovery) showTable(header []string, rows [][]string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WDiscovery) Show(by string) error {
|
func (w *WDiscovery) Show(by string) error {
|
||||||
if w.wlan == nil {
|
if w.wifi == nil {
|
||||||
return errors.New("WLan is not yet initialized.")
|
return errors.New("WiFi is not yet initialized.")
|
||||||
}
|
}
|
||||||
|
|
||||||
stations := w.wlan.List()
|
stations := w.wifi.List()
|
||||||
if by == "seen" {
|
if by == "seen" {
|
||||||
sort.Sort(ByWlanSeenSorter(stations))
|
sort.Sort(BywifiSeenSorter(stations))
|
||||||
} else {
|
} else {
|
||||||
sort.Sort(ByEssidSorter(stations))
|
sort.Sort(ByEssidSorter(stations))
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ func (w *WDiscovery) startDeauth() error {
|
||||||
w.sendDeauthPacket(w.apTarget, w.cliTarget)
|
w.sendDeauthPacket(w.apTarget, w.cliTarget)
|
||||||
} else {
|
} else {
|
||||||
// deauth all AP's clients
|
// deauth all AP's clients
|
||||||
for _, station := range w.wlan.Stations {
|
for _, station := range w.wifi.Stations {
|
||||||
w.sendDeauthPacket(w.apTarget, station.HW)
|
w.sendDeauthPacket(w.apTarget, station.HW)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ func (w *WDiscovery) discoverAccessPoints(packet gopacket.Packet) {
|
||||||
if bytes.Compare(dst, w.BroadcastMac) == 0 && len(ssid) > 0 {
|
if bytes.Compare(dst, w.BroadcastMac) == 0 && len(ssid) > 0 {
|
||||||
radiotap, _ := radiotapLayer.(*layers.RadioTap)
|
radiotap, _ := radiotapLayer.(*layers.RadioTap)
|
||||||
channel := mhz2chan(int(radiotap.ChannelFrequency))
|
channel := mhz2chan(int(radiotap.ChannelFrequency))
|
||||||
w.wlan.AddIfNew(ssid, bssid, true, channel)
|
w.wifi.AddIfNew(ssid, bssid, true, channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,7 +330,7 @@ func (w *WDiscovery) discoverClients(bs net.HardwareAddr, packet gopacket.Packet
|
||||||
if bytes.Compare(bssid, bs) == 0 {
|
if bytes.Compare(bssid, bs) == 0 {
|
||||||
radiotap, _ := radiotapLayer.(*layers.RadioTap)
|
radiotap, _ := radiotapLayer.(*layers.RadioTap)
|
||||||
channel := mhz2chan(int(radiotap.ChannelFrequency))
|
channel := mhz2chan(int(radiotap.ChannelFrequency))
|
||||||
w.wlan.AddIfNew("", src.String(), false, channel)
|
w.wifi.AddIfNew("", src.String(), false, channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -354,7 +354,7 @@ func (w *WDiscovery) Configure() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
w.wlan = NewWLan(w.Session, w.Session.Interface)
|
w.wifi = NewWiFi(w.Session, w.Session.Interface)
|
||||||
w.BroadcastMac, _ = net.ParseMAC(network.BroadcastMac)
|
w.BroadcastMac, _ = net.ParseMAC(network.BroadcastMac)
|
||||||
|
|
||||||
return nil
|
return nil
|
|
@ -4,24 +4,24 @@ import (
|
||||||
"github.com/evilsocket/bettercap-ng/network"
|
"github.com/evilsocket/bettercap-ng/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WirelessStation struct {
|
type WiFiStation struct {
|
||||||
*network.Endpoint
|
*network.Endpoint
|
||||||
IsAP bool
|
IsAP bool
|
||||||
Channel int
|
Channel int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWirelessStation(essid, bssid string, isAp bool, channel int) *WirelessStation {
|
func NewWiFiStation(essid, bssid string, isAp bool, channel int) *WiFiStation {
|
||||||
return &WirelessStation{
|
return &WiFiStation{
|
||||||
Endpoint: network.NewEndpointNoResolve(network.MonitorModeAddress, bssid, essid, 0),
|
Endpoint: network.NewEndpointNoResolve(network.MonitorModeAddress, bssid, essid, 0),
|
||||||
IsAP: isAp,
|
IsAP: isAp,
|
||||||
Channel: channel,
|
Channel: channel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s WirelessStation) BSSID() string {
|
func (s WiFiStation) BSSID() string {
|
||||||
return s.HwAddress
|
return s.HwAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WirelessStation) ESSID() string {
|
func (s *WiFiStation) ESSID() string {
|
||||||
return s.Hostname
|
return s.Hostname
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue