-
Notifications
You must be signed in to change notification settings - Fork 21
/
ja3s_pcap.go
78 lines (65 loc) · 1.44 KB
/
ja3s_pcap.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//go:build !ja3_disable_gopacket
package ja3
import (
"fmt"
"io"
"strings"
"github.com/google/gopacket"
)
// ReadFileJa3s reads the PCAP file at the given path
// and prints out all packets containing JA3S digests to the supplied io.Writer
func ReadFileJa3s(file string, out io.Writer) {
r, f, link, err := openPcap(file)
if err != nil {
panic(err)
}
defer f.Close()
count := 0
for {
// read packet data
data, _, err := r.ReadPacketData()
if err == io.EOF {
if Debug {
fmt.Println(count, "fingerprints.")
}
return
} else if err != nil {
panic(err)
}
var (
// create gopacket
p = gopacket.NewPacket(data, link, gopacket.Lazy)
// get JA3 if possible
digest = DigestHexPacketJa3s(p)
)
// check if we got a result
if digest != "" {
count++
var (
b strings.Builder
nl = p.NetworkLayer()
tl = p.TransportLayer()
)
// got an a digest but no transport or network layer
if tl == nil || nl == nil {
if Debug {
fmt.Println("got a nil layer: ", nl, tl, p.Dump(), digest)
}
continue
}
b.WriteString("[")
b.WriteString(nl.NetworkFlow().Dst().String())
b.WriteString(":")
b.WriteString(tl.TransportFlow().Dst().String())
b.WriteString("] JA3S: ")
b.WriteString(string(BarePacketJa3s(p)))
b.WriteString(" --> ")
b.WriteString(digest)
b.WriteString("\n")
_, err := out.Write([]byte(b.String()))
if err != nil {
panic(err)
}
}
}
}