forked from neex/http2smugl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
detect_method.go
83 lines (70 loc) · 2.11 KB
/
detect_method.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
package main
import (
"fmt"
"net/url"
)
type DetectRequestParams struct {
AdditionalHeaders Headers
Body []byte
}
type DetectMethod int
const (
DetectContentLengthParsing DetectMethod = iota
DetectChunkedBodyValidation
DetectChunkedBodyConsumption
)
var DetectMethods = []DetectMethod{
DetectChunkedBodyConsumption,
DetectChunkedBodyValidation,
DetectContentLengthParsing,
}
func (d DetectMethod) GetRequests(sm SmugglingMethod, target *url.URL, smuggleVariant SmugglingVariant) (valid, invalid DetectRequestParams) {
switch d {
case DetectContentLengthParsing:
valid.AdditionalHeaders = Headers{{"content-length", "1"}}
invalid.AdditionalHeaders = Headers{{"content-length", "-1"}}
sm.Smuggle(&valid.AdditionalHeaders[0], target, smuggleVariant)
sm.Smuggle(&invalid.AdditionalHeaders[0], target, smuggleVariant)
case DetectChunkedBodyValidation:
valid.AdditionalHeaders = Headers{
{"content-length", "5"},
{"transfer-encoding", "chunked"},
}
sm.Smuggle(&valid.AdditionalHeaders[1], target, smuggleVariant)
invalid.AdditionalHeaders = valid.AdditionalHeaders
valid.Body = []byte("0\r\n\r\n")
invalid.Body = []byte("X\r\n\r\n")
case DetectChunkedBodyConsumption:
valid.AdditionalHeaders = Headers{
{"content-length", "5"},
{"transfer-encoding", "chunked"},
}
sm.Smuggle(&valid.AdditionalHeaders[1], target, smuggleVariant)
invalid.AdditionalHeaders = valid.AdditionalHeaders
valid.Body = []byte("0\r\n\r\n")
invalid.Body = []byte("999\r\n")
default:
panic(fmt.Errorf("unknown detect method: %#v", d))
}
return
}
func (d DetectMethod) AllowsSmugglingMethod(sm SmugglingMethod) bool {
switch d {
case DetectContentLengthParsing:
return sm != HeaderSmugglingUnicodeCharacters
default:
return sm != HeaderSmugglingNewlineLongerValue
}
}
func (d DetectMethod) String() string {
switch d {
case DetectContentLengthParsing:
return "detect content length parsing"
case DetectChunkedBodyConsumption:
return "detect chunked body consumption"
case DetectChunkedBodyValidation:
return "detect chunked body validation"
default:
return "unknown detect method"
}
}