new: implemented syn.scan module (closes #67)

This commit is contained in:
evilsocket 2018-02-22 21:20:36 +01:00
commit ce76c7258d
8 changed files with 338 additions and 3 deletions

View file

@ -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)

29
packets/tcp.go Normal file
View file

@ -0,0 +1,29 @@
package packets
import (
"github.com/google/gopacket/layers"
"net"
)
func NewTCPSyn(from net.IP, from_hw net.HardwareAddr, to net.IP, to_hw net.HardwareAddr, srcPort int, dstPort int) (error, []byte) {
eth := layers.Ethernet{
SrcMAC: from_hw,
DstMAC: to_hw,
EthernetType: layers.EthernetTypeIPv4,
}
ip4 := layers.IPv4{
Protocol: layers.IPProtocolTCP,
Version: 4,
TTL: 64,
SrcIP: from,
DstIP: to,
}
tcp := layers.TCP{
SrcPort: layers.TCPPort(srcPort),
DstPort: layers.TCPPort(dstPort),
SYN: true,
}
tcp.SetNetworkLayerForChecksum(&ip4)
return Serialize(&eth, &ip4, &tcp)
}