This commit is contained in:
evilsocket 2018-02-08 06:00:38 +01:00
commit 90b720f1b6

View file

@ -4,12 +4,13 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net"
"os" "os"
"strings" "strings"
"sync" "sync"
"github.com/evilsocket/bettercap-ng/core" "github.com/evilsocket/bettercap-ng/core"
"github.com/evilsocket/bettercap-ng/net" bnet "github.com/evilsocket/bettercap-ng/net"
) )
const TargetsDefaultTTL = 10 const TargetsDefaultTTL = 10
@ -19,21 +20,21 @@ type Targets struct {
sync.Mutex sync.Mutex
Session *Session `json:"-"` Session *Session `json:"-"`
Interface *net.Endpoint Interface *bnet.Endpoint
Gateway *net.Endpoint Gateway *bnet.Endpoint
Targets map[string]*net.Endpoint Targets map[string]*bnet.Endpoint
TTL map[string]uint TTL map[string]uint
Aliases map[string]string Aliases map[string]string
aliasesFileName string aliasesFileName string
} }
func NewTargets(s *Session, iface, gateway *net.Endpoint) *Targets { func NewTargets(s *Session, iface, gateway *bnet.Endpoint) *Targets {
t := &Targets{ t := &Targets{
Session: s, Session: s,
Interface: iface, Interface: iface,
Gateway: gateway, Gateway: gateway,
Targets: make(map[string]*net.Endpoint), Targets: make(map[string]*bnet.Endpoint),
TTL: make(map[string]uint), TTL: make(map[string]uint),
Aliases: make(map[string]string), Aliases: make(map[string]string),
} }
@ -48,11 +49,11 @@ func NewTargets(s *Session, iface, gateway *net.Endpoint) *Targets {
return t return t
} }
func (tp *Targets) List() (list []*net.Endpoint) { func (tp *Targets) List() (list []*bnet.Endpoint) {
tp.Lock() tp.Lock()
defer tp.Unlock() defer tp.Unlock()
list = make([]*net.Endpoint, 0) list = make([]*bnet.Endpoint, 0)
for _, t := range tp.Targets { for _, t := range tp.Targets {
list = append(list, t) list = append(list, t)
} }
@ -137,7 +138,8 @@ func (tp *Targets) Remove(ip, mac string) {
} }
func (tp *Targets) shouldIgnore(ip string) bool { func (tp *Targets) shouldIgnore(ip string) bool {
return (ip == tp.Interface.IpAddress || ip == tp.Gateway.IpAddress || ip == "255.255.255.255") addr := net.ParseIP(ip)
return (ip == tp.Interface.IpAddress || ip == tp.Gateway.IpAddress || tp.Session.Interface.Net.Contains(addr) == false)
} }
func (tp *Targets) Has(ip string) bool { func (tp *Targets) Has(ip string) bool {
@ -153,7 +155,7 @@ func (tp *Targets) Has(ip string) bool {
return false return false
} }
func (tp *Targets) AddIfNew(ip, mac string) *net.Endpoint { func (tp *Targets) AddIfNew(ip, mac string) *bnet.Endpoint {
tp.Lock() tp.Lock()
defer tp.Unlock() defer tp.Unlock()
@ -161,7 +163,7 @@ func (tp *Targets) AddIfNew(ip, mac string) *net.Endpoint {
return nil return nil
} }
mac = net.NormalizeMac(mac) mac = bnet.NormalizeMac(mac)
if t, found := tp.Targets[mac]; found { if t, found := tp.Targets[mac]; found {
if tp.TTL[mac] < TargetsDefaultTTL { if tp.TTL[mac] < TargetsDefaultTTL {
tp.TTL[mac]++ tp.TTL[mac]++
@ -169,8 +171,8 @@ func (tp *Targets) AddIfNew(ip, mac string) *net.Endpoint {
return t return t
} }
e := net.NewEndpoint(ip, mac) e := bnet.NewEndpoint(ip, mac)
e.ResolvedCallback = func(e *net.Endpoint) { e.ResolvedCallback = func(e *bnet.Endpoint) {
tp.Session.Events.Add("endpoint.resolved", e) tp.Session.Events.Add("endpoint.resolved", e)
} }