forked from pagpeter/TrackMe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fingerprint_h2.go
executable file
·98 lines (83 loc) · 2.27 KB
/
fingerprint_h2.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"fmt"
"strings"
)
// based on https://www.blackhat.com/docs/eu-17/materials/eu-17-Shuster-Passive-Fingerprinting-Of-HTTP2-Clients-wp.pdf
// Fingerprint format:
// S[;]|WU|P[,]#|PS[,]
// S: Settings param
// WU: Window Update
// P: Priority
// PS: Pseudo-header order (eg: "m,p,a,s")
func getSettingsFingerprint(frames []ParsedFrame) string {
var sf string // SettingsFingerprint
mapping := map[string]string{
"HEADER_TABLE_SIZE": "1",
"ENABLE_PUSH": "2",
"MAX_CONCURRENT_STREAMS": "3",
"INITIAL_WINDOW_SIZE": "4",
"MAX_FRAME_SIZE": "5",
"MAX_HEADER_LIST_SIZE": "6",
}
for _, frame := range frames {
if frame.Type == "SETTINGS" {
for _, setting := range frame.Settings {
parts := strings.Split(setting, " = ")
if len(parts) != 2 {
return "error"
}
sf += mapping[parts[0]] + ":" + parts[1] + ","
}
break
}
}
return strings.TrimRight(sf, ",")
}
func getWindowUpdateFingerprint(frames []ParsedFrame) string {
// TODO: there might be multiple WINDOW_UPDATE frames, but I am not sure
for _, frame := range frames {
if frame.Type == "WINDOW_UPDATE" {
return fmt.Sprintf("%d", frame.Increment)
}
}
return "00"
}
func getPriorityFingerprint(frames []ParsedFrame) string {
var pf string // PriorityFingerprint
for _, frame := range frames {
if frame.Type == "PRIORITY" {
pf += fmt.Sprintf("%v:%v:%v:%v", frame.Stream, frame.Priority.Exclusive, frame.Priority.DependsOn, frame.Priority.Weight)
pf += ","
}
}
if pf != "" {
return strings.TrimRight(pf, ",")
}
return "0"
}
func getHeaderOrderFingerprint(frames []ParsedFrame) string {
var hofp string // HeaderOrderFingerprint
for _, frame := range frames {
if frame.Type == "HEADERS" {
for c, header := range frame.Headers {
if strings.HasPrefix(header, ":") {
hofp += string(header[1])
if c < 3 {
hofp += ","
}
}
}
break
}
}
return hofp
}
func GetAkamaiFingerprint(frames []ParsedFrame) string {
var akamaiFingerprint string
akamaiFingerprint += getSettingsFingerprint(frames) + "|"
akamaiFingerprint += getWindowUpdateFingerprint(frames) + "|"
akamaiFingerprint += getPriorityFingerprint(frames) + "|"
akamaiFingerprint += getHeaderOrderFingerprint(frames)
return akamaiFingerprint
}