diff --git a/modules/wifi/wifi.go b/modules/wifi/wifi.go index b014f310..377227d8 100644 --- a/modules/wifi/wifi.go +++ b/modules/wifi/wifi.go @@ -21,7 +21,6 @@ import ( "github.com/evilsocket/islazy/fs" "github.com/evilsocket/islazy/ops" "github.com/evilsocket/islazy/str" - "github.com/evilsocket/islazy/tui" ) type WiFiModule struct { @@ -581,9 +580,12 @@ func (mod *WiFiModule) Configure() error { // second fatal error, just bail return fmt.Errorf("error while activating handle: %s", err) } else { - // first fatal error, try again without setting the interface in monitor mode - mod.Warning("error while activating handle: %s, %s", err, tui.Bold("interface might already be monitoring. retrying!")) - opts.Monitor = false + // first fatal error, forcing monitor mode + // https://github.com/bettercap/bettercap/issues/819 + opts.Monitor = false; + if err := network.ForceMonitorMode(ifName); err != nil { + return err + } } } } diff --git a/network/net_darwin.go b/network/net_darwin.go index 5e8ce195..e9f6821c 100644 --- a/network/net_darwin.go +++ b/network/net_darwin.go @@ -21,6 +21,10 @@ func getInterfaceName(iface net.Interface) string { return iface.Name } +func ForceMonitorMode(iface string) error { + return nil +} + func SetInterfaceChannel(iface string, channel int) error { cIface := C.CString(iface) defer C.free(unsafe.Pointer(cIface)) diff --git a/network/net_linux.go b/network/net_linux.go index 533561d6..d91a808f 100644 --- a/network/net_linux.go +++ b/network/net_linux.go @@ -16,6 +16,22 @@ func getInterfaceName(iface net.Interface) string { return iface.Name } +// See https://github.com/bettercap/bettercap/issues/819 +func ForceMonitorMode(iface string) error { + _, _ = core.Exec("ip", []string{"link", "set", iface, "down"}) + + out, err := core.Exec("iw", []string{"dev", iface, "set", "type", "monitor"}) + if err != nil { + return fmt.Errorf("iw: out=%s err=%s", out, err) + } else if out != "" { + return fmt.Errorf("Unexpected output while setting interface %s into monitor mode: %s", iface, out) + } + + _, _ = core.Exec("ip", []string{"link", "set", iface, "up"}) + + return nil +} + func SetInterfaceChannel(iface string, channel int) error { curr := GetInterfaceChannel(iface) // the interface is already on this channel diff --git a/network/net_windows.go b/network/net_windows.go index bf56e98f..00ad4af5 100644 --- a/network/net_windows.go +++ b/network/net_windows.go @@ -53,3 +53,7 @@ func GetSupportedFrequencies(iface string) ([]int, error) { freqs := make([]int, 0) return freqs, fmt.Errorf("Windows does not support WiFi channel hopping.") } + +func ForceMonitorMode(iface string) error { + return nil +} \ No newline at end of file