mirror of
https://github.com/bettercap/bettercap
synced 2025-07-06 04:52:10 -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"
|
||||
)
|
||||
|
||||
type WLan struct {
|
||||
type WiFi struct {
|
||||
sync.Mutex
|
||||
Session *session.Session
|
||||
Interface *network.Endpoint
|
||||
Stations map[string]*WirelessStation
|
||||
Stations map[string]*WiFiStation
|
||||
}
|
||||
|
||||
func NewWLan(s *session.Session, iface *network.Endpoint) *WLan {
|
||||
return &WLan{
|
||||
func NewWiFi(s *session.Session, iface *network.Endpoint) *WiFi {
|
||||
return &WiFi{
|
||||
Session: s,
|
||||
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()
|
||||
defer w.Unlock()
|
||||
|
||||
list = make([]*WirelessStation, 0)
|
||||
list = make([]*WiFiStation, 0)
|
||||
for _, t := range w.Stations {
|
||||
list = append(list, t)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WLan) Remove(mac string) {
|
||||
func (w *WiFi) Remove(mac string) {
|
||||
w.Lock()
|
||||
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()
|
||||
defer w.Unlock()
|
||||
|
||||
|
@ -54,7 +54,7 @@ func (w *WLan) AddIfNew(ssid, mac string, isAp bool, channel int) *WirelessStati
|
|||
return station
|
||||
}
|
||||
|
||||
newStation := NewWirelessStation(ssid, mac, isAp, channel)
|
||||
newStation := NewWiFiStation(ssid, mac, isAp, channel)
|
||||
w.Stations[mac] = 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
|
||||
}
|
||||
|
||||
func (w *WLan) Clear() error {
|
||||
w.Stations = make(map[string]*WirelessStation)
|
||||
func (w *WiFi) Clear() error {
|
||||
w.Stations = make(map[string]*WiFiStation)
|
||||
return nil
|
||||
}
|
|
@ -25,7 +25,7 @@ import (
|
|||
type WDiscovery struct {
|
||||
session.SessionModule
|
||||
|
||||
wlan *WLan
|
||||
wifi *WiFi
|
||||
handle *pcap.Handle
|
||||
BroadcastMac []byte
|
||||
cliTarget net.HardwareAddr
|
||||
|
@ -34,30 +34,30 @@ type WDiscovery struct {
|
|||
|
||||
func NewWDiscovery(s *session.Session) *WDiscovery {
|
||||
w := &WDiscovery{
|
||||
SessionModule: session.NewSessionModule("wlan.recon", s),
|
||||
SessionModule: session.NewSessionModule("wifi.recon", s),
|
||||
cliTarget: 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.",
|
||||
func(args []string) error {
|
||||
return w.Start()
|
||||
}))
|
||||
|
||||
w.AddHandler(session.NewModuleHandler("wlan.recon off", "",
|
||||
w.AddHandler(session.NewModuleHandler("wifi.recon off", "",
|
||||
"Stop 802.11 wireless base stations discovery.",
|
||||
func(args []string) error {
|
||||
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).",
|
||||
func(args []string) error {
|
||||
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).",
|
||||
func(args []string) error {
|
||||
var err error
|
||||
|
@ -65,35 +65,35 @@ func NewWDiscovery(s *session.Session) *WDiscovery {
|
|||
return err
|
||||
}))
|
||||
|
||||
w.AddHandler(session.NewModuleHandler("wlan.recon clear client", "",
|
||||
w.AddHandler(session.NewModuleHandler("wifi.recon clear client", "",
|
||||
"Remove client to deauth.",
|
||||
func(args []string) error {
|
||||
w.cliTarget = make([]byte, 0)
|
||||
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.",
|
||||
func(args []string) error {
|
||||
var err error
|
||||
if w.wlan != nil {
|
||||
w.wlan.Clear()
|
||||
if w.wifi != nil {
|
||||
w.wifi.Clear()
|
||||
}
|
||||
w.apTarget, err = net.ParseMAC(args[0])
|
||||
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.",
|
||||
func(args []string) error {
|
||||
if w.wlan != nil {
|
||||
w.wlan.Clear()
|
||||
if w.wifi != nil {
|
||||
w.wifi.Clear()
|
||||
}
|
||||
w.apTarget = make([]byte, 0)
|
||||
return nil
|
||||
}))
|
||||
|
||||
w.AddHandler(session.NewModuleHandler("wlan.show", "",
|
||||
w.AddHandler(session.NewModuleHandler("wifi.show", "",
|
||||
"Show current hosts list (default sorting by essid).",
|
||||
func(args []string) error {
|
||||
return w.Show("essid")
|
||||
|
@ -103,7 +103,7 @@ func NewWDiscovery(s *session.Session) *WDiscovery {
|
|||
}
|
||||
|
||||
func (w WDiscovery) Name() string {
|
||||
return "wlan.recon"
|
||||
return "wifi.recon"
|
||||
}
|
||||
|
||||
func (w WDiscovery) Description() string {
|
||||
|
@ -114,7 +114,7 @@ func (w WDiscovery) Author() string {
|
|||
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)
|
||||
sinceFirstSeen := time.Since(station.FirstSeen)
|
||||
|
||||
|
@ -151,7 +151,7 @@ func mhz2chan(freq int) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
type ByEssidSorter []*WirelessStation
|
||||
type ByEssidSorter []*WiFiStation
|
||||
|
||||
func (a ByEssidSorter) Len() int { return len(a) }
|
||||
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()
|
||||
}
|
||||
|
||||
type ByWlanSeenSorter []*WirelessStation
|
||||
type BywifiSeenSorter []*WiFiStation
|
||||
|
||||
func (a ByWlanSeenSorter) Len() int { return len(a) }
|
||||
func (a ByWlanSeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByWlanSeenSorter) Less(i, j int) bool {
|
||||
func (a BywifiSeenSorter) Len() int { return len(a) }
|
||||
func (a BywifiSeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a BywifiSeenSorter) Less(i, j int) bool {
|
||||
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 {
|
||||
if w.wlan == nil {
|
||||
return errors.New("WLan is not yet initialized.")
|
||||
if w.wifi == nil {
|
||||
return errors.New("WiFi is not yet initialized.")
|
||||
}
|
||||
|
||||
stations := w.wlan.List()
|
||||
stations := w.wifi.List()
|
||||
if by == "seen" {
|
||||
sort.Sort(ByWlanSeenSorter(stations))
|
||||
sort.Sort(BywifiSeenSorter(stations))
|
||||
} else {
|
||||
sort.Sort(ByEssidSorter(stations))
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ func (w *WDiscovery) startDeauth() error {
|
|||
w.sendDeauthPacket(w.apTarget, w.cliTarget)
|
||||
} else {
|
||||
// deauth all AP's clients
|
||||
for _, station := range w.wlan.Stations {
|
||||
for _, station := range w.wifi.Stations {
|
||||
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 {
|
||||
radiotap, _ := radiotapLayer.(*layers.RadioTap)
|
||||
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 {
|
||||
radiotap, _ := radiotapLayer.(*layers.RadioTap)
|
||||
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
|
||||
}
|
||||
|
||||
w.wlan = NewWLan(w.Session, w.Session.Interface)
|
||||
w.wifi = NewWiFi(w.Session, w.Session.Interface)
|
||||
w.BroadcastMac, _ = net.ParseMAC(network.BroadcastMac)
|
||||
|
||||
return nil
|
|
@ -4,24 +4,24 @@ import (
|
|||
"github.com/evilsocket/bettercap-ng/network"
|
||||
)
|
||||
|
||||
type WirelessStation struct {
|
||||
type WiFiStation struct {
|
||||
*network.Endpoint
|
||||
IsAP bool
|
||||
Channel int
|
||||
}
|
||||
|
||||
func NewWirelessStation(essid, bssid string, isAp bool, channel int) *WirelessStation {
|
||||
return &WirelessStation{
|
||||
func NewWiFiStation(essid, bssid string, isAp bool, channel int) *WiFiStation {
|
||||
return &WiFiStation{
|
||||
Endpoint: network.NewEndpointNoResolve(network.MonitorModeAddress, bssid, essid, 0),
|
||||
IsAP: isAp,
|
||||
Channel: channel,
|
||||
}
|
||||
}
|
||||
|
||||
func (s WirelessStation) BSSID() string {
|
||||
func (s WiFiStation) BSSID() string {
|
||||
return s.HwAddress
|
||||
}
|
||||
|
||||
func (s *WirelessStation) ESSID() string {
|
||||
func (s *WiFiStation) ESSID() string {
|
||||
return s.Hostname
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue