This repository was archived by the owner on Feb 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathh2_randomizer.go
More file actions
52 lines (44 loc) · 1.47 KB
/
h2_randomizer.go
File metadata and controls
52 lines (44 loc) · 1.47 KB
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
package legitagent
import (
"github.com/SyNdicateFoundation/fastrand"
"golang.org/x/net/http2"
"math"
)
func randomizeValue(base uint32, percentage float64) uint32 {
if base == 0 {
return 0
}
delta := uint32(float64(base) * percentage)
minX := base - delta
if base < delta {
minX = 1
}
maxX := base + delta
return fastrand.Number(minX, maxX)
}
func randomizeH2Settings(baseSettings map[http2.SettingID]uint32, profile H2RandomizationProfile) map[http2.SettingID]uint32 {
randomized := make(map[http2.SettingID]uint32)
for id, val := range baseSettings {
randomized[id] = val
}
switch profile {
case H2RandomizationProfileNormal:
if val, ok := randomized[http2.SettingHeaderTableSize]; ok {
randomized[http2.SettingHeaderTableSize] = randomizeValue(val, 0.10)
}
if val, ok := randomized[http2.SettingInitialWindowSize]; ok {
randomized[http2.SettingInitialWindowSize] = randomizeValue(val, 0.15)
}
if val, ok := randomized[http2.SettingMaxHeaderListSize]; ok {
randomized[http2.SettingMaxHeaderListSize] = randomizeValue(val, 0.10)
}
case H2RandomizationProfileMaximum:
randomized[http2.SettingHeaderTableSize] = randomizeValue(4096, 0.20)
randomized[http2.SettingEnablePush] = 0
randomized[http2.SettingInitialWindowSize] = randomizeValue(65535, 0.20)
randomized[http2.SettingMaxFrameSize] = randomizeValue(16384, 0.20)
randomized[http2.SettingMaxConcurrentStreams] = uint32(math.MaxUint32 - fastrand.IntN(1024))
default:
}
return randomized
}