fix: fixed a bug of the probe and recon algos which prevented targets from being removed once offline

This commit is contained in:
evilsocket 2018-02-01 19:45:09 +01:00
commit 73f887087a
4 changed files with 12 additions and 32 deletions

View file

@ -60,8 +60,6 @@ func (p *Prober) shouldProbe(ip net.IP) bool {
return false
} else if addr == p.Session.Gateway.IpAddress {
return false
} else if p.Session.Targets.Has(addr) == true {
return false
}
return true
}

View file

@ -102,27 +102,21 @@ func (d *Discovery) checkShared(new net.ArpTable) {
}
func (d *Discovery) runDiff() {
var new net.ArpTable = make(net.ArpTable)
// check for endpoints who disappeared
var rem net.ArpTable = make(net.ArpTable)
if d.before != nil {
new = net.ArpDiff(d.current, d.before)
rem = net.ArpDiff(d.before, d.current)
} else {
new = d.current
for mac, t := range d.Session.Targets.Targets {
if _, found := d.current[mac]; found == false {
rem[mac] = t.IpAddress
}
}
if len(new) > 0 || len(rem) > 0 {
d.checkShared(new)
for mac, ip := range rem {
d.Session.Targets.Remove(ip, mac)
}
// refresh target pool
for ip, mac := range rem {
d.Session.Targets.Remove(ip, mac)
}
for ip, mac := range new {
d.Session.Targets.AddIfNotExist(ip, mac)
}
// now check for new friends ^_^
for ip, mac := range d.current {
d.Session.Targets.AddIfNotExist(ip, mac)
}
}

View file

@ -13,18 +13,6 @@ var (
arpTable = make(ArpTable)
)
func ArpDiff(current, before ArpTable) ArpTable {
diff := make(ArpTable)
for ip, mac := range current {
_, found := before[ip]
if !found {
diff[ip] = mac
}
}
return diff
}
func ArpLookup(iface string, address string, refresh bool) (string, error) {
// Refresh ARP table if first run or if a force refresh has been instructed.
if ArpParsed() == false || refresh == true {

View file

@ -12,7 +12,7 @@ import (
"github.com/evilsocket/bettercap-ng/net"
)
const TargetsDefaultTTL = 2
const TargetsDefaultTTL = 10
const TargetsAliasesFile = "~/bettercap.aliases"
type Targets struct {