mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 04:59:25 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
c901cf31d5
commit
c2cd198d37
3 changed files with 21 additions and 32 deletions
|
@ -1,7 +1,6 @@
|
||||||
package modules
|
package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
@ -65,17 +64,6 @@ func (p ArpSpoofer) Author() string {
|
||||||
return "Simone Margaritelli <evilsocket@protonmail.com>"
|
return "Simone Margaritelli <evilsocket@protonmail.com>"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ArpSpoofer) shouldSpoof(ip net.IP) bool {
|
|
||||||
if ip.IsLoopback() == true {
|
|
||||||
return false
|
|
||||||
} else if bytes.Compare(ip, p.Session.Interface.IP) == 0 {
|
|
||||||
return false
|
|
||||||
} else if bytes.Compare(ip, p.Session.Gateway.IP) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *ArpSpoofer) getMAC(ip net.IP, probe bool) (net.HardwareAddr, error) {
|
func (p *ArpSpoofer) getMAC(ip net.IP, probe bool) (net.HardwareAddr, error) {
|
||||||
var mac string
|
var mac string
|
||||||
var hw net.HardwareAddr
|
var hw net.HardwareAddr
|
||||||
|
@ -115,7 +103,7 @@ func (p *ArpSpoofer) sendArp(saddr net.IP, smac net.HardwareAddr, check_running
|
||||||
for _, ip := range p.addresses {
|
for _, ip := range p.addresses {
|
||||||
if check_running && p.Running() == false {
|
if check_running && p.Running() == false {
|
||||||
return
|
return
|
||||||
} else if p.shouldSpoof(ip) == false {
|
} else if p.Session.Skip(ip) == true {
|
||||||
log.Debug("Skipping address %s from ARP spoofing.", ip)
|
log.Debug("Skipping address %s from ARP spoofing.", ip)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,18 +52,6 @@ func (p Prober) Author() string {
|
||||||
return "Simone Margaritelli <evilsocket@protonmail.com>"
|
return "Simone Margaritelli <evilsocket@protonmail.com>"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Prober) shouldProbe(ip net.IP) bool {
|
|
||||||
addr := ip.String()
|
|
||||||
if ip.IsLoopback() == true {
|
|
||||||
return false
|
|
||||||
} else if addr == p.Session.Interface.IpAddress {
|
|
||||||
return false
|
|
||||||
} else if addr == p.Session.Gateway.IpAddress {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Prober) sendProbe(from net.IP, from_hw net.HardwareAddr, ip net.IP) {
|
func (p *Prober) sendProbe(from net.IP, from_hw net.HardwareAddr, ip net.IP) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
@ -103,7 +91,7 @@ func (p *Prober) Start() error {
|
||||||
|
|
||||||
for p.Running() {
|
for p.Running() {
|
||||||
for _, ip := range addresses {
|
for _, ip := range addresses {
|
||||||
if p.shouldProbe(ip) == false {
|
if p.Session.Skip(ip) == true {
|
||||||
log.Debug("Skipping address %s from UDP probing.", ip)
|
log.Debug("Skipping address %s from UDP probing.", ip)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@ package session
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -17,7 +19,7 @@ import (
|
||||||
|
|
||||||
"github.com/evilsocket/bettercap-ng/core"
|
"github.com/evilsocket/bettercap-ng/core"
|
||||||
"github.com/evilsocket/bettercap-ng/firewall"
|
"github.com/evilsocket/bettercap-ng/firewall"
|
||||||
"github.com/evilsocket/bettercap-ng/net"
|
bnet "github.com/evilsocket/bettercap-ng/net"
|
||||||
"github.com/evilsocket/bettercap-ng/packets"
|
"github.com/evilsocket/bettercap-ng/packets"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,8 +34,8 @@ var (
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
Options core.Options `json:"options"`
|
Options core.Options `json:"options"`
|
||||||
Interface *net.Endpoint `json:"interface"`
|
Interface *bnet.Endpoint `json:"interface"`
|
||||||
Gateway *net.Endpoint `json:"gateway"`
|
Gateway *bnet.Endpoint `json:"gateway"`
|
||||||
Firewall firewall.FirewallManager `json:"-"`
|
Firewall firewall.FirewallManager `json:"-"`
|
||||||
Env *Environment `json:"env"`
|
Env *Environment `json:"env"`
|
||||||
Targets *Targets `json:"targets"`
|
Targets *Targets `json:"targets"`
|
||||||
|
@ -280,9 +282,9 @@ func (s *Session) Start() error {
|
||||||
return s.Modules[i].Name() < s.Modules[j].Name()
|
return s.Modules[i].Name() < s.Modules[j].Name()
|
||||||
})
|
})
|
||||||
|
|
||||||
net.OuiInit()
|
bnet.OuiInit()
|
||||||
|
|
||||||
if s.Interface, err = net.FindInterface(*s.Options.InterfaceName); err != nil {
|
if s.Interface, err = bnet.FindInterface(*s.Options.InterfaceName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +292,7 @@ func (s *Session) Start() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Gateway, err = net.FindGateway(s.Interface); err != nil {
|
if s.Gateway, err = bnet.FindGateway(s.Interface); err != nil {
|
||||||
s.Events.Log(core.WARNING, "%s", err.Error())
|
s.Events.Log(core.WARNING, "%s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,6 +323,17 @@ func (s *Session) Start() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Session) Skip(ip net.IP) bool {
|
||||||
|
if ip.IsLoopback() == true {
|
||||||
|
return true
|
||||||
|
} else if bytes.Compare(ip, s.Interface.IP) == 0 {
|
||||||
|
return true
|
||||||
|
} else if bytes.Compare(ip, s.Gateway.IP) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Session) IsOn(moduleName string) bool {
|
func (s *Session) IsOn(moduleName string) bool {
|
||||||
for _, m := range s.Modules {
|
for _, m := range s.Modules {
|
||||||
if m.Name() == moduleName {
|
if m.Name() == moduleName {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue