new: main packet queue is now used to gather network stats, update endpoint, etc

This commit is contained in:
evilsocket 2018-01-13 18:40:43 +01:00
commit 913c581f9f
4 changed files with 127 additions and 15 deletions

View file

@ -33,7 +33,7 @@ type Session struct {
Firewall firewall.FirewallManager `json:"-"`
Env *Environment `json:"env"`
Targets *Targets `json:"targets"`
Queue *packets.Queue `json:"-"`
Queue *packets.Queue `json:"packets"`
Input *readline.Instance `json:"-"`
Active bool `json:"active"`
Prompt Prompt `json:"-"`
@ -174,7 +174,7 @@ func (s *Session) Start() error {
s.Env.Set("iface.ipv6", s.Interface.Ip6Address)
s.Env.Set("iface.mac", s.Interface.HwAddress)
if s.Queue, err = packets.NewQueue(s.Interface.Name()); err != nil {
if s.Queue, err = packets.NewQueue(s.Interface); err != nil {
return err
}
@ -227,6 +227,20 @@ func (s *Session) Start() error {
}()
s.Active = true
// keep reading network events in order to add / update endpoints
go func() {
for event := range s.Queue.Activities {
addr := event.IP.String()
mac := event.MAC.String()
s.Targets.AddIfNotExist(addr, mac)
if s.Active == false {
return
}
}
}()
s.Events.Add("session.started", nil)
return nil

View file

@ -4,6 +4,7 @@ import (
"fmt"
"sort"
"sync"
"time"
"github.com/evilsocket/bettercap-ng/core"
"github.com/evilsocket/bettercap-ng/net"
@ -63,6 +64,7 @@ func (tp *Targets) AddIfNotExist(ip, mac string) *net.Endpoint {
}
if t, found := tp.Targets[mac]; found {
t.LastSeen = time.Now()
return t
}