mirror of
https://github.com/bettercap/bettercap
synced 2025-07-29 19:20:00 -07:00
Revert "Issue #157: wifi.recon can now select one or multiple channels (comma separated) and show only the selected channels."
This reverts commit 054ce2a1bf
.
This commit is contained in:
parent
054ce2a1bf
commit
1e408f62ba
3 changed files with 19 additions and 99 deletions
|
@ -6,7 +6,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -91,10 +90,6 @@ func NewWiFiRecon(s *session.Session) *WiFiRecon {
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
w.ap = nil
|
w.ap = nil
|
||||||
w.stickChan = 0
|
w.stickChan = 0
|
||||||
var err error
|
|
||||||
if w.frequencies, err = network.GetSupportedFrequencies(w.Session.Interface.Name()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -118,38 +113,9 @@ func NewWiFiRecon(s *session.Session) *WiFiRecon {
|
||||||
"",
|
"",
|
||||||
"WiFi channel or empty for channel hopping."))
|
"WiFi channel or empty for channel hopping."))
|
||||||
|
|
||||||
w.AddHandler(session.NewModuleHandler("wifi.recon.channel", `wifi\.recon\.channel[\s]*([0-9]+(?:[, ]+[0-9]+)*)?`,
|
|
||||||
"WiFi channels (comma separated) or empty for channel hopping.",
|
|
||||||
func(args []string) error {
|
|
||||||
newfrequencies := w.frequencies[:0]
|
|
||||||
|
|
||||||
if len(args) > 0 && args[0] != "" {
|
|
||||||
channels := strings.Split(args[0], ",")
|
|
||||||
for _, c := range channels {
|
|
||||||
trimmed := strings.Trim(c, " ")
|
|
||||||
channel, err := strconv.Atoi(trimmed)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
newfrequencies = append(newfrequencies, chan2mhz(channel))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// No channels setted, retrieve frequencies supported by the card
|
|
||||||
if frequencies, err := network.GetSupportedFrequencies(w.Session.Interface.Name()); err != nil {
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
newfrequencies = frequencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
w.frequencies = newfrequencies
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}))
|
|
||||||
|
|
||||||
w.AddParam(session.NewIntParameter("wifi.hop.period",
|
w.AddParam(session.NewIntParameter("wifi.hop.period",
|
||||||
"250",
|
"250",
|
||||||
"If channel hopping is enabled (empty wifi.recon.channel), this is the time in milliseconds the algorithm will hop on every channel (it'll be doubled if both 2.4 and 5.0 bands are available)."))
|
"If channel hopping is enabled (empty wifi.recon.channel), this is the time in millseconds the algorithm will hop on every channel (it'll be doubled if both 2.4 and 5.0 bands are available)."))
|
||||||
|
|
||||||
w.AddParam(session.NewBoolParameter("wifi.skip-broken",
|
w.AddParam(session.NewBoolParameter("wifi.skip-broken",
|
||||||
"true",
|
"true",
|
||||||
|
@ -170,8 +136,7 @@ func (w WiFiRecon) Author() string {
|
||||||
return "Gianluca Braga <matrix86@protonmail.com> && Simone Margaritelli <evilsocket@protonmail.com>>"
|
return "Gianluca Braga <matrix86@protonmail.com> && Simone Margaritelli <evilsocket@protonmail.com>>"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WiFiRecon) getRow(station *network.Station) ([]string, bool) {
|
func (w *WiFiRecon) getRow(station *network.Station) []string {
|
||||||
include := false
|
|
||||||
sinceStarted := time.Since(w.Session.StartedAt)
|
sinceStarted := time.Since(w.Session.StartedAt)
|
||||||
sinceFirstSeen := time.Since(station.FirstSeen)
|
sinceFirstSeen := time.Since(station.FirstSeen)
|
||||||
|
|
||||||
|
@ -215,13 +180,6 @@ func (w *WiFiRecon) getRow(station *network.Station) ([]string, bool) {
|
||||||
recvd = humanize.Bytes(station.Received)
|
recvd = humanize.Bytes(station.Received)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, frequencies := range w.frequencies {
|
|
||||||
if frequencies == station.Frequency {
|
|
||||||
include = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if w.isApSelected() {
|
if w.isApSelected() {
|
||||||
return []string{
|
return []string{
|
||||||
fmt.Sprintf("%d dBm", station.RSSI),
|
fmt.Sprintf("%d dBm", station.RSSI),
|
||||||
|
@ -231,7 +189,7 @@ func (w *WiFiRecon) getRow(station *network.Station) ([]string, bool) {
|
||||||
sent,
|
sent,
|
||||||
recvd,
|
recvd,
|
||||||
seen,
|
seen,
|
||||||
}, include
|
}
|
||||||
} else {
|
} else {
|
||||||
// this is ugly, but necessary in order to have this
|
// this is ugly, but necessary in order to have this
|
||||||
// method handle both access point and clients
|
// method handle both access point and clients
|
||||||
|
@ -254,7 +212,7 @@ func (w *WiFiRecon) getRow(station *network.Station) ([]string, bool) {
|
||||||
sent,
|
sent,
|
||||||
recvd,
|
recvd,
|
||||||
seen,
|
seen,
|
||||||
}, include
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,18 +228,6 @@ func mhz2chan(freq int) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func chan2mhz(channel int) int {
|
|
||||||
if channel <= 13 {
|
|
||||||
return ((channel - 1) * 5) + 2412
|
|
||||||
} else if channel == 14 {
|
|
||||||
return 2484
|
|
||||||
} else if channel <= 173 {
|
|
||||||
return ((channel - 7) * 5) + 5035
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WiFiRecon) isApSelected() bool {
|
func (w *WiFiRecon) isApSelected() bool {
|
||||||
return w.ap != nil
|
return w.ap != nil
|
||||||
}
|
}
|
||||||
|
@ -312,9 +258,7 @@ func (w *WiFiRecon) Show(by string) error {
|
||||||
|
|
||||||
rows := make([][]string, 0)
|
rows := make([][]string, 0)
|
||||||
for _, s := range stations {
|
for _, s := range stations {
|
||||||
if row, include := w.getRow(s); include == true {
|
rows = append(rows, w.getRow(s))
|
||||||
rows = append(rows, row)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
nrows := len(rows)
|
nrows := len(rows)
|
||||||
|
|
||||||
|
@ -366,12 +310,13 @@ func (w *WiFiRecon) Configure() error {
|
||||||
|
|
||||||
w.hopPeriod = time.Duration(hopPeriod) * time.Millisecond
|
w.hopPeriod = time.Duration(hopPeriod) * time.Millisecond
|
||||||
|
|
||||||
// No channels setted, retrieve frequencies supported by the card
|
if err, w.channel = w.IntParam("wifi.recon.channel"); err == nil {
|
||||||
if len(w.frequencies) == 0 {
|
if err = network.SetInterfaceChannel(w.Session.Interface.Name(), w.channel); err != nil {
|
||||||
if w.frequencies, err = network.GetSupportedFrequencies(w.Session.Interface.Name()); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Info("WiFi recon active on channel %d.", w.channel)
|
||||||
|
} else {
|
||||||
|
w.channel = 0
|
||||||
// we need to start somewhere, this is just to check if
|
// we need to start somewhere, this is just to check if
|
||||||
// this OS supports switching channel programmatically.
|
// this OS supports switching channel programmatically.
|
||||||
if err = network.SetInterfaceChannel(w.Session.Interface.Name(), 1); err != nil {
|
if err = network.SetInterfaceChannel(w.Session.Interface.Name(), 1); err != nil {
|
||||||
|
@ -380,6 +325,12 @@ func (w *WiFiRecon) Configure() error {
|
||||||
log.Info("WiFi recon active with channel hopping.")
|
log.Info("WiFi recon active with channel hopping.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if frequencies, err := network.GetSupportedFrequencies(w.Session.Interface.Name()); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
w.frequencies = frequencies
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -503,12 +454,7 @@ func (w *WiFiRecon) discoverAccessPoints(radiotap *layers.RadioTap, dot11 *layer
|
||||||
if ok, ssid := packets.Dot11ParseIDSSID(packet); ok == true {
|
if ok, ssid := packets.Dot11ParseIDSSID(packet); ok == true {
|
||||||
if isZeroBSSID(dot11.Address3) == false && isBroadcastBSSID(dot11.Address3) == false {
|
if isZeroBSSID(dot11.Address3) == false && isBroadcastBSSID(dot11.Address3) == false {
|
||||||
bssid := dot11.Address3.String()
|
bssid := dot11.Address3.String()
|
||||||
var frequency int
|
frequency := int(radiotap.ChannelFrequency)
|
||||||
if found, channel := packets.Dot11ParseDSSet(packet); found {
|
|
||||||
frequency = chan2mhz(channel)
|
|
||||||
} else {
|
|
||||||
frequency = int(radiotap.ChannelFrequency)
|
|
||||||
}
|
|
||||||
w.Session.WiFi.AddIfNew(ssid, bssid, frequency, radiotap.DBMAntennaSignal)
|
w.Session.WiFi.AddIfNew(ssid, bssid, frequency, radiotap.DBMAntennaSignal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -598,11 +544,10 @@ func (w *WiFiRecon) channelHopper() {
|
||||||
// more channels, therefore we need to increase the time
|
// more channels, therefore we need to increase the time
|
||||||
// we hop on each one otherwise me lose information
|
// we hop on each one otherwise me lose information
|
||||||
if len(w.frequencies) > 14 {
|
if len(w.frequencies) > 14 {
|
||||||
delay = delay * 2 * time.Millisecond
|
delay = 500 * time.Millisecond
|
||||||
}
|
}
|
||||||
|
|
||||||
frequencies := w.frequencies
|
for _, frequency := range w.frequencies {
|
||||||
for _, frequency := range frequencies {
|
|
||||||
channel := mhz2chan(frequency)
|
channel := mhz2chan(frequency)
|
||||||
// stick to the access point channel as long as it's selected
|
// stick to the access point channel as long as it's selected
|
||||||
// or as long as we're deauthing on it
|
// or as long as we're deauthing on it
|
||||||
|
|
|
@ -66,23 +66,6 @@ func Dot11ParseIDSSID(packet gopacket.Packet) (bool, string) {
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func Dot11ParseDSSet(packet gopacket.Packet) (bool, int) {
|
|
||||||
channel := 0
|
|
||||||
found := false
|
|
||||||
for _, layer := range packet.Layers() {
|
|
||||||
info, ok := layer.(*layers.Dot11InformationElement)
|
|
||||||
if ok == true {
|
|
||||||
if info.ID == layers.Dot11InformationElementIDDSSet {
|
|
||||||
channel, _ = Dot11InformationElementIDDSSetDecode(info.Info)
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return found, channel
|
|
||||||
}
|
|
||||||
|
|
||||||
func Dot11ParseEncryption(packet gopacket.Packet, dot11 *layers.Dot11) (bool, string, string, string) {
|
func Dot11ParseEncryption(packet gopacket.Packet, dot11 *layers.Dot11) (bool, string, string, string) {
|
||||||
var i uint16
|
var i uint16
|
||||||
enc := ""
|
enc := ""
|
||||||
|
|
|
@ -211,11 +211,3 @@ func Dot11InformationElementRSNInfoDecode(buf []byte) (rsn RSNInfo, err error) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func Dot11InformationElementIDDSSetDecode(buf []byte) (channel int, err error) {
|
|
||||||
if err = canParse("DSSet.channel", buf, 1); err == nil {
|
|
||||||
channel = int(buf[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue