-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagpackets.go
58 lines (52 loc) · 1.37 KB
/
tagpackets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package greynetanalysis
import (
"github.com/CAIDA/goiputils"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
)
func IsZmap(p gopacket.Packet) bool {
if ipl4 := p.Layer(layers.LayerTypeIPv4); ipl4 != nil {
ipl, _ := ipl4.(*layers.IPv4)
return ipl.Id == 54321
} else {
return false
}
}
func IsMasscan(p gopacket.Packet) bool {
//ipid = dstip XOR dstport XOR tcpseq
ipl4 := p.Layer(layers.LayerTypeIPv4)
tcpl := p.Layer(layers.LayerTypeTCP)
if ipl4 != nil && tcpl != nil {
ipl, _ := ipl4.(*layers.IPv4)
tcph, _ := tcpl.(*layers.TCP)
dst32, _ := goiputils.IPv4ToInt(ipl.DstIP)
dstipu16 := uint16(dst32)
tcpseq16 := uint16(tcph.Seq)
dport := (uint16)(tcph.DstPort)
eipid := dstipu16 ^ tcpseq16 ^ dport
return ipl.Id == eipid
} else {
return false
}
}
func IsMirai(p gopacket.Packet) bool {
//tcp seq == dstip
ipl4 := p.Layer(layers.LayerTypeIPv4)
tcpl := p.Layer(layers.LayerTypeTCP)
if ipl4 != nil && tcpl != nil {
ipl, _ := ipl4.(*layers.IPv4)
tcph, _ := tcpl.(*layers.TCP)
dst32, _ := goiputils.IPv4ToInt(ipl.DstIP)
return dst32 == tcph.Seq
} else {
return false
}
}
func IsBogon(p gopacket.Packet) bool {
ipl4 := p.Layer(layers.LayerTypeIPv4)
if ipl4 != nil {
iph := ipl4.(*layers.IPv4)
return iph.SrcIP.IsUnspecified() || iph.SrcIP.IsPrivate() || iph.SrcIP.IsMulticast() || iph.SrcIP.IsLoopback()
}
return false
}