refact: minor refactoring of net.recon module

This commit is contained in:
evilsocket 2018-01-08 09:15:36 +01:00
parent f1f9ca4ef0
commit dd2fd0f30f

View file

@ -65,32 +65,7 @@ func (d Discovery) OnSessionEnded(s *session.Session) {
} }
} }
func (d *Discovery) Start() error { func (d *Discovery) checkShared(new net.ArpTable) {
if d.Running() == false {
d.SetRunning(true)
go func() {
for {
select {
case <-time.After(time.Duration(d.refresh) * time.Second):
var err error
if d.current, err = net.ArpUpdate(d.Session.Interface.Name()); err != nil {
d.Session.Events.Log(session.ERROR, "%s", err)
continue
}
var new net.ArpTable = make(net.ArpTable)
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
}
if len(new) > 0 || len(rem) > 0 {
n_gw_shared := 0 n_gw_shared := 0
for ip, mac := range new { for ip, mac := range new {
if ip != d.Session.Gateway.IpAddress && mac == d.Session.Gateway.HwAddress { if ip != d.Session.Gateway.IpAddress && mac == d.Session.Gateway.HwAddress {
@ -109,8 +84,23 @@ func (d *Discovery) Start() error {
b = "" b = ""
} }
d.Session.Events.Log(session.WARNING, "WARNING: Found %d endpoint%s which share%s the same MAC of the gateway (%s), there're might be some IP isolation going on, skipping.", n_gw_shared, a, b, d.Session.Gateway.HwAddress) d.Session.Events.Log(session.WARNING, "Found %d endpoint%s which share%s the same MAC of the gateway (%s), there're might be some IP isolation going on, skipping.", n_gw_shared, a, b, d.Session.Gateway.HwAddress)
} }
}
func (d *Discovery) runDiff() {
var new net.ArpTable = make(net.ArpTable)
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
}
if len(new) > 0 || len(rem) > 0 {
d.checkShared(new)
// refresh target pool // refresh target pool
for ip, mac := range rem { for ip, mac := range rem {
@ -121,6 +111,24 @@ func (d *Discovery) Start() error {
d.Session.Targets.AddIfNotExist(ip, mac) d.Session.Targets.AddIfNotExist(ip, mac)
} }
} }
}
func (d *Discovery) Start() error {
if d.Running() == false {
d.SetRunning(true)
go func() {
for {
select {
case <-time.After(time.Duration(d.refresh) * time.Second):
var err error
if d.current, err = net.ArpUpdate(d.Session.Interface.Name()); err != nil {
d.Session.Events.Log(session.ERROR, "%s", err)
continue
}
d.runDiff()
d.before = d.current d.before = d.current