fix: fixed packets queue stats

This commit is contained in:
evilsocket 2018-01-13 18:48:52 +01:00
commit 656b633023
3 changed files with 19 additions and 11 deletions

View file

@ -14,8 +14,9 @@ import (
) )
type Activity struct { type Activity struct {
IP net.IP IP net.IP
MAC net.HardwareAddr MAC net.HardwareAddr
Source bool
} }
type Queue struct { type Queue struct {
@ -94,15 +95,17 @@ func (q *Queue) worker() {
if bytes.Compare(q.iface.IP, ip4.SrcIP) != 0 && q.iface.Net.Contains(ip4.SrcIP) { if bytes.Compare(q.iface.IP, ip4.SrcIP) != 0 && q.iface.Net.Contains(ip4.SrcIP) {
q.Activities <- Activity{ q.Activities <- Activity{
IP: ip4.SrcIP, IP: ip4.SrcIP,
MAC: eth.SrcMAC, MAC: eth.SrcMAC,
Source: true,
} }
} }
if bytes.Compare(q.iface.IP, ip4.DstIP) != 0 && q.iface.Net.Contains(ip4.DstIP) { if bytes.Compare(q.iface.IP, ip4.DstIP) != 0 && q.iface.Net.Contains(ip4.DstIP) {
q.Activities <- Activity{ q.Activities <- Activity{
IP: ip4.DstIP, IP: ip4.DstIP,
MAC: eth.SrcMAC, MAC: eth.SrcMAC,
Source: false,
} }
} }
} }

View file

@ -10,6 +10,7 @@ import (
"sort" "sort"
"strings" "strings"
"syscall" "syscall"
"time"
"github.com/chzyer/readline" "github.com/chzyer/readline"
@ -231,9 +232,15 @@ func (s *Session) Start() error {
// keep reading network events in order to add / update endpoints // keep reading network events in order to add / update endpoints
go func() { go func() {
for event := range s.Queue.Activities { for event := range s.Queue.Activities {
addr := event.IP.String() if event.Source == true {
mac := event.MAC.String() addr := event.IP.String()
s.Targets.AddIfNotExist(addr, mac) mac := event.MAC.String()
existing := s.Targets.AddIfNotExist(addr, mac)
if existing != nil {
existing.LastSeen = time.Now()
}
}
if s.Active == false { if s.Active == false {
return return

View file

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