mirror of
https://github.com/bettercap/bettercap
synced 2025-07-13 00:23:49 -07:00
fix: reporting module name when it's already running or already stopped
This commit is contained in:
parent
fbcaf2989f
commit
40ec724ca6
20 changed files with 30 additions and 24 deletions
|
@ -80,7 +80,7 @@ func (mod *AnyProxy) Configure() error {
|
||||||
var dstAddress string
|
var dstAddress string
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if err, iface = mod.StringParam("any.proxy.iface"); err != nil {
|
} else if err, iface = mod.StringParam("any.proxy.iface"); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err, protocol = mod.StringParam("any.proxy.protocol"); err != nil {
|
} else if err, protocol = mod.StringParam("any.proxy.protocol"); err != nil {
|
||||||
|
|
|
@ -126,7 +126,7 @@ func (mod *RestAPI) Configure() error {
|
||||||
var port int
|
var port int
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if err, ip = mod.StringParam("api.rest.address"); err != nil {
|
} else if err, ip = mod.StringParam("api.rest.address"); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err, port = mod.IntParam("api.rest.port"); err != nil {
|
} else if err, port = mod.IntParam("api.rest.port"); err != nil {
|
||||||
|
|
|
@ -140,7 +140,7 @@ func (w dummyWriter) Write(p []byte) (n int, err error) {
|
||||||
|
|
||||||
func (mod *BLERecon) Configure() (err error) {
|
func (mod *BLERecon) Configure() (err error) {
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if mod.gattDevice == nil {
|
} else if mod.gattDevice == nil {
|
||||||
mod.Debug("initializing device ...")
|
mod.Debug("initializing device ...")
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ func (mod *BLERecon) enumAllTheThings(mac string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod.setCurrentDevice(dev)
|
mod.setCurrentDevice(dev)
|
||||||
if err := mod.Configure(); err != nil && err != session.ErrAlreadyStarted {
|
if err := mod.Configure(); err != nil && err != session.ErrAlreadyStarted(mod.Name()) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ func (mod *DHCP6Spoofer) Configure() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
if mod.Handle, err = pcap.OpenLive(mod.Session.Interface.Name(), 65536, true, pcap.BlockForever); err != nil {
|
if mod.Handle, err = pcap.OpenLive(mod.Session.Interface.Name(), 65536, true, pcap.BlockForever); err != nil {
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (mod *DNSSpoofer) Configure() error {
|
||||||
var address net.IP
|
var address net.IP
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if mod.Handle, err = pcap.OpenLive(mod.Session.Interface.Name(), 65536, true, pcap.BlockForever); err != nil {
|
} else if mod.Handle, err = pcap.OpenLive(mod.Session.Interface.Name(), 65536, true, pcap.BlockForever); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err = mod.Handle.SetBPFFilter("udp"); err != nil {
|
} else if err = mod.Handle.SetBPFFilter("udp"); err != nil {
|
||||||
|
|
|
@ -72,7 +72,7 @@ func (mod *GPS) Author() string {
|
||||||
|
|
||||||
func (mod *GPS) Configure() (err error) {
|
func (mod *GPS) Configure() (err error) {
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if err, mod.serialPort = mod.StringParam("gps.device"); err != nil {
|
} else if err, mod.serialPort = mod.StringParam("gps.device"); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err, mod.baudRate = mod.IntParam("gps.baudrate"); err != nil {
|
} else if err, mod.baudRate = mod.IntParam("gps.baudrate"); err != nil {
|
||||||
|
|
|
@ -163,7 +163,7 @@ func (mod *HIDRecon) Configure() error {
|
||||||
var n int
|
var n int
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err, mod.useLNA = mod.BoolParam("hid.lna"); err != nil {
|
if err, mod.useLNA = mod.BoolParam("hid.lna"); err != nil {
|
||||||
|
|
|
@ -89,7 +89,7 @@ func (mod *HttpProxy) Configure() error {
|
||||||
var whitelist string
|
var whitelist string
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if err, address = mod.StringParam("http.proxy.address"); err != nil {
|
} else if err, address = mod.StringParam("http.proxy.address"); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err, proxyPort = mod.IntParam("http.proxy.port"); err != nil {
|
} else if err, proxyPort = mod.IntParam("http.proxy.port"); err != nil {
|
||||||
|
|
|
@ -71,7 +71,7 @@ func (mod *HttpServer) Configure() error {
|
||||||
var port int
|
var port int
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err, path = mod.StringParam("http.server.path"); err != nil {
|
if err, path = mod.StringParam("http.server.path"); err != nil {
|
||||||
|
|
|
@ -106,7 +106,7 @@ func (mod *HttpsProxy) Configure() error {
|
||||||
var blacklist string
|
var blacklist string
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if err, address = mod.StringParam("https.proxy.address"); err != nil {
|
} else if err, address = mod.StringParam("https.proxy.address"); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err, proxyPort = mod.IntParam("https.proxy.port"); err != nil {
|
} else if err, proxyPort = mod.IntParam("https.proxy.port"); err != nil {
|
||||||
|
|
|
@ -89,7 +89,7 @@ func (mod *HttpsServer) Configure() error {
|
||||||
var keyFile string
|
var keyFile string
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err, path = mod.StringParam("https.server.path"); err != nil {
|
if err, path = mod.StringParam("https.server.path"); err != nil {
|
||||||
|
|
|
@ -103,7 +103,7 @@ func (mod *MacChanger) setMac(mac net.HardwareAddr) error {
|
||||||
|
|
||||||
func (mod *MacChanger) Start() error {
|
func (mod *MacChanger) Start() error {
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if err := mod.Configure(); err != nil {
|
} else if err := mod.Configure(); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err := mod.setMac(mod.fakeMac); err != nil {
|
} else if err := mod.setMac(mod.fakeMac); err != nil {
|
||||||
|
|
|
@ -79,7 +79,7 @@ func (mod *MySQLServer) Configure() error {
|
||||||
var port int
|
var port int
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if err, mod.infile = mod.StringParam("mysql.server.infile"); err != nil {
|
} else if err, mod.infile = mod.StringParam("mysql.server.infile"); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err, mod.outfile = mod.StringParam("mysql.server.outfile"); err != nil {
|
} else if err, mod.outfile = mod.StringParam("mysql.server.outfile"); err != nil {
|
||||||
|
|
|
@ -146,7 +146,7 @@ func (mod *Sniffer) Configure() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if err, mod.Ctx = mod.GetContext(); err != nil {
|
} else if err, mod.Ctx = mod.GetContext(); err != nil {
|
||||||
if mod.Ctx != nil {
|
if mod.Ctx != nil {
|
||||||
mod.Ctx.Close()
|
mod.Ctx.Close()
|
||||||
|
|
|
@ -190,7 +190,7 @@ func dummyCallback(payload *nfqueue.Payload) int {
|
||||||
|
|
||||||
func (mod *PacketProxy) Start() error {
|
func (mod *PacketProxy) Start() error {
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if err := mod.Configure(); err != nil {
|
} else if err := mod.Configure(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ func (mod *TcpProxy) Configure() error {
|
||||||
var tunnelPort int
|
var tunnelPort int
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if err, address = mod.StringParam("tcp.address"); err != nil {
|
} else if err, address = mod.StringParam("tcp.address"); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err, proxyAddress = mod.StringParam("tcp.proxy.address"); err != nil {
|
} else if err, proxyAddress = mod.StringParam("tcp.proxy.address"); err != nil {
|
||||||
|
|
|
@ -59,7 +59,7 @@ func (mod *Ticker) Configure() error {
|
||||||
var period int
|
var period int
|
||||||
|
|
||||||
if mod.Running() {
|
if mod.Running() {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
} else if err, commands = mod.StringParam("ticker.commands"); err != nil {
|
} else if err, commands = mod.StringParam("ticker.commands"); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err, period = mod.IntParam("ticker.period"); err != nil {
|
} else if err, period = mod.IntParam("ticker.period"); err != nil {
|
||||||
|
|
|
@ -35,7 +35,7 @@ func (mod *WiFiModule) startAp() error {
|
||||||
if !mod.Running() {
|
if !mod.Running() {
|
||||||
return errNoRecon
|
return errNoRecon
|
||||||
} else if mod.apRunning {
|
} else if mod.apRunning {
|
||||||
return session.ErrAlreadyStarted
|
return session.ErrAlreadyStarted(mod.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
@ -230,9 +230,9 @@ func (m *SessionModule) Running() bool {
|
||||||
func (m *SessionModule) SetRunning(running bool, cb func()) error {
|
func (m *SessionModule) SetRunning(running bool, cb func()) error {
|
||||||
if running == m.Running() {
|
if running == m.Running() {
|
||||||
if m.Started {
|
if m.Started {
|
||||||
return ErrAlreadyStarted
|
return ErrAlreadyStarted(m.Name)
|
||||||
} else {
|
} else {
|
||||||
return ErrAlreadyStopped
|
return ErrAlreadyStopped(m.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,14 +35,20 @@ const (
|
||||||
var (
|
var (
|
||||||
I = (*Session)(nil)
|
I = (*Session)(nil)
|
||||||
|
|
||||||
ErrAlreadyStarted = errors.New("module is already running")
|
|
||||||
ErrAlreadyStopped = errors.New("module is not running")
|
|
||||||
ErrNotSupported = errors.New("this component is not supported on this OS")
|
ErrNotSupported = errors.New("this component is not supported on this OS")
|
||||||
|
|
||||||
reCmdSpaceCleaner = regexp.MustCompile(`^([^\s]+)\s+(.+)$`)
|
reCmdSpaceCleaner = regexp.MustCompile(`^([^\s]+)\s+(.+)$`)
|
||||||
reEnvVarCapture = regexp.MustCompile(`{env\.([^}]+)}`)
|
reEnvVarCapture = regexp.MustCompile(`{env\.([^}]+)}`)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func ErrAlreadyStarted(name string) error {
|
||||||
|
return fmt.Errorf("module %s is already running", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ErrAlreadyStopped(name string) error {
|
||||||
|
return fmt.Errorf("module %s is not running", name)
|
||||||
|
}
|
||||||
|
|
||||||
type UnknownCommandCallback func(cmd string) bool
|
type UnknownCommandCallback func(cmd string) bool
|
||||||
|
|
||||||
type GPS struct {
|
type GPS struct {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue