mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 13:33:21 -07:00
Add option to manually specify the gateway.
This commit is contained in:
parent
c0d3c314fc
commit
e1023d4b66
3 changed files with 29 additions and 7 deletions
|
@ -4,6 +4,7 @@ import "flag"
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
InterfaceName *string
|
InterfaceName *string
|
||||||
|
Gateway *string
|
||||||
Caplet *string
|
Caplet *string
|
||||||
AutoStart *string
|
AutoStart *string
|
||||||
Debug *bool
|
Debug *bool
|
||||||
|
@ -19,6 +20,7 @@ type Options struct {
|
||||||
func ParseOptions() (Options, error) {
|
func ParseOptions() (Options, error) {
|
||||||
o := Options{
|
o := Options{
|
||||||
InterfaceName: flag.String("iface", "", "Network interface to bind to, if empty the default interface will be auto selected."),
|
InterfaceName: flag.String("iface", "", "Network interface to bind to, if empty the default interface will be auto selected."),
|
||||||
|
Gateway: flag.String("gw","","Manually specify the gateway address, if not specified or invalid, the default gateway will be used."),
|
||||||
AutoStart: flag.String("autostart", "events.stream, net.recon", "Comma separated list of modules to auto start."),
|
AutoStart: flag.String("autostart", "events.stream, net.recon", "Comma separated list of modules to auto start."),
|
||||||
Caplet: flag.String("caplet", "", "Read commands from this file and execute them in the interactive session."),
|
Caplet: flag.String("caplet", "", "Read commands from this file and execute them in the interactive session."),
|
||||||
Debug: flag.Bool("debug", false, "Print debug messages."),
|
Debug: flag.Bool("debug", false, "Print debug messages."),
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/core"
|
"github.com/bettercap/bettercap/core"
|
||||||
|
@ -48,3 +49,19 @@ func FindGateway(iface *Endpoint) (*Endpoint, error) {
|
||||||
Debug("FindGateway(%s): nothing found :/", iface.Name())
|
Debug("FindGateway(%s): nothing found :/", iface.Name())
|
||||||
return nil, ErrNoGateway
|
return nil, ErrNoGateway
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GatewayProvidedByUser(iface *Endpoint, gateway string) (*Endpoint, error) {
|
||||||
|
Debug("GatewayProvidedByUser(%s) [cmd=%v opts=%v parser=%v]", gateway, IPv4RouteCmd, IPv4RouteCmdOpts, IPv4RouteParser)
|
||||||
|
if IPv4Validator.MatchString(gateway) {
|
||||||
|
Debug("valid gateway ip %s",gateway)
|
||||||
|
ifName := iface.Name()
|
||||||
|
// we have the address, now we need its mac
|
||||||
|
mac, err := ArpLookup(ifName, gateway, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
Debug("gateway is %s[%s]", gateway, mac)
|
||||||
|
return NewEndpoint(gateway, mac), nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("Provided gateway %s not a valid IPv4 address! Revert to find default gateway.",gateway)
|
||||||
|
}
|
||||||
|
|
|
@ -226,13 +226,16 @@ func (s *Session) Start() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Gateway, err = network.FindGateway(s.Interface); err != nil {
|
if s.Gateway, err = network.GatewayProvidedByUser(s.Interface, *s.Options.Gateway); err != nil {
|
||||||
level := log.WARNING
|
level := log.WARNING
|
||||||
if s.Interface.IsMonitor() {
|
if s.Interface.IsMonitor() {
|
||||||
level = log.DEBUG
|
level = log.DEBUG
|
||||||
}
|
}
|
||||||
s.Events.Log(level, "%s", err.Error())
|
s.Events.Log(level, "%s", err.Error())
|
||||||
}
|
if s.Gateway, err = network.FindGateway(s.Interface); err != nil {
|
||||||
|
s.Events.Log(level, "%s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if s.Gateway == nil || s.Gateway.IpAddress == s.Interface.IpAddress {
|
if s.Gateway == nil || s.Gateway.IpAddress == s.Interface.IpAddress {
|
||||||
s.Gateway = s.Interface
|
s.Gateway = s.Interface
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue