mirror of
https://github.com/bettercap/bettercap
synced 2025-07-08 05:51:37 -07:00
new: implemented syn.scan module (closes #67)
This commit is contained in:
parent
d6fe8fc663
commit
ce76c7258d
8 changed files with 338 additions and 3 deletions
|
@ -32,8 +32,10 @@ type Stats struct {
|
|||
Errors uint64
|
||||
}
|
||||
|
||||
type PacketCallback func(pkt gopacket.Packet)
|
||||
|
||||
type Queue struct {
|
||||
sync.Mutex
|
||||
sync.RWMutex
|
||||
|
||||
Activities chan Activity `json:"-"`
|
||||
|
||||
|
@ -44,6 +46,7 @@ type Queue struct {
|
|||
iface *network.Endpoint
|
||||
handle *pcap.Handle
|
||||
source *gopacket.PacketSource
|
||||
pktCb PacketCallback
|
||||
active bool
|
||||
}
|
||||
|
||||
|
@ -55,6 +58,7 @@ func NewQueue(iface *network.Endpoint) (q *Queue, err error) {
|
|||
|
||||
iface: iface,
|
||||
active: !iface.IsMonitor(),
|
||||
pktCb: nil,
|
||||
}
|
||||
|
||||
if q.active == true {
|
||||
|
@ -69,6 +73,21 @@ func NewQueue(iface *network.Endpoint) (q *Queue, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (q *Queue) OnPacket(cb PacketCallback) {
|
||||
q.Lock()
|
||||
defer q.Unlock()
|
||||
q.pktCb = cb
|
||||
}
|
||||
|
||||
func (q *Queue) onPacketCallback(pkt gopacket.Packet) {
|
||||
q.RLock()
|
||||
defer q.RUnlock()
|
||||
|
||||
if q.pktCb != nil {
|
||||
q.pktCb(pkt)
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Queue) trackProtocols(pkt gopacket.Packet) {
|
||||
// gather protocols stats
|
||||
pktLayers := pkt.Layers()
|
||||
|
@ -130,6 +149,8 @@ func (q *Queue) worker() {
|
|||
atomic.AddUint64(&q.Stats.PktReceived, 1)
|
||||
atomic.AddUint64(&q.Stats.Received, pktSize)
|
||||
|
||||
q.onPacketCallback(pkt)
|
||||
|
||||
// decode eth and ipv4 layers
|
||||
leth := pkt.Layer(layers.LayerTypeEthernet)
|
||||
lip4 := pkt.Layer(layers.LayerTypeIPv4)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue