mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
26c532316a
commit
7b4fc3d31d
2 changed files with 32 additions and 1 deletions
|
@ -1,6 +1,11 @@
|
||||||
package zerogod
|
package zerogod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/v2/session"
|
"github.com/bettercap/bettercap/v2/session"
|
||||||
"github.com/bettercap/bettercap/v2/tls"
|
"github.com/bettercap/bettercap/v2/tls"
|
||||||
"github.com/google/gopacket"
|
"github.com/google/gopacket"
|
||||||
|
@ -74,8 +79,32 @@ func NewZeroGod(s *session.Session) *ZeroGod {
|
||||||
return mod.startAdvertiser(args[0])
|
return mod.startAdvertiser(args[0])
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// TODO: add autocomplete
|
||||||
|
mod.AddHandler(session.NewModuleHandler("zerogod.impersonate ADDRESS", "zerogod.impersonate (.+)",
|
||||||
|
"Impersonate ADDRESS by advertising the same discovery information.",
|
||||||
|
func(args []string) error {
|
||||||
|
if address := args[0]; address == "off" {
|
||||||
|
return mod.stopAdvertiser()
|
||||||
|
} else {
|
||||||
|
tmpDir := os.TempDir()
|
||||||
|
tmpFileName := filepath.Join(tmpDir, fmt.Sprintf("impersonate_%d.yml", rand.Int()))
|
||||||
|
|
||||||
|
if err := mod.save(address, tmpFileName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return mod.startAdvertiser(tmpFileName)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
mod.AddHandler(session.NewModuleHandler("zerogod.advertise off", "",
|
mod.AddHandler(session.NewModuleHandler("zerogod.advertise off", "",
|
||||||
"Start a previously started advertiser.",
|
"Stop a previously started advertiser.",
|
||||||
|
func(args []string) error {
|
||||||
|
return mod.stopAdvertiser()
|
||||||
|
}))
|
||||||
|
|
||||||
|
mod.AddHandler(session.NewModuleHandler("zerogod.impersonate off", "",
|
||||||
|
"Stop a previously started impersonation.",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
return mod.stopAdvertiser()
|
return mod.stopAdvertiser()
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -131,7 +131,9 @@ func (mod *ZeroGod) startAdvertiser(fileName string) error {
|
||||||
for _, svc := range advertiser.Services {
|
for _, svc := range advertiser.Services {
|
||||||
// if no external responder has been specified, check if port is available
|
// if no external responder has been specified, check if port is available
|
||||||
if svc.Responder == "" {
|
if svc.Responder == "" {
|
||||||
|
// if the port was not set or is not available or is requesdted by another service
|
||||||
for svc.Port == 0 || !isPortAvailable(svc.Port) || isPortRequested(svc, services) {
|
for svc.Port == 0 || !isPortAvailable(svc.Port) || isPortRequested(svc, services) {
|
||||||
|
// set a new one and try again
|
||||||
newPort := (rand.Intn(65535-1024) + 1024)
|
newPort := (rand.Intn(65535-1024) + 1024)
|
||||||
mod.Warning("port %d for service %s is not avaialble, trying %d ...",
|
mod.Warning("port %d for service %s is not avaialble, trying %d ...",
|
||||||
svc.Port,
|
svc.Port,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue