-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathdetect_method.go
112 lines (97 loc) · 2.88 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"bytes"
"fmt"
"net/url"
"time"
)
type DetectRequestParams struct {
AdditionalHeaders Headers
Body [][]byte
BodyPartsDelay time.Duration
SkipBodyEndFlag bool
}
type DetectMethod int
const (
DetectContentLengthParsing DetectMethod = iota
DetectChunkedBodyValidation
DetectChunkedBodyConsumption
DetectZeroBodyFragementInterruptsChunkedBody
)
var DetectMethods = []DetectMethod{
DetectChunkedBodyConsumption,
DetectChunkedBodyValidation,
DetectContentLengthParsing,
DetectZeroBodyFragementInterruptsChunkedBody,
}
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{[]byte("0\r\n\r\n")}
invalid.Body = [][]byte{[]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{[]byte("0\r\n\r\n")}
invalid.Body = [][]byte{[]byte("999\r\n")}
case DetectZeroBodyFragementInterruptsChunkedBody:
valid.Body = [][]byte{
bytes.Repeat([]byte("a"), 65536),
[]byte("x"),
}
invalid.Body = [][]byte{
bytes.Repeat([]byte("a"), 65536),
[]byte("x"),
}
valid.BodyPartsDelay = 1 * time.Second
invalid.BodyPartsDelay = 1 * time.Second
valid.SkipBodyEndFlag = true
invalid.SkipBodyEndFlag = true
default:
panic(fmt.Errorf("unknown detect method: %#v", d))
}
return
}
func (d DetectMethod) AllowsSmugglingMethod(sm SmugglingMethod) bool {
switch d {
case DetectContentLengthParsing:
return sm != HeaderSmugglingUnicodeCharacters
case DetectZeroBodyFragementInterruptsChunkedBody:
return sm == HeaderSmugglingNone
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"
case DetectZeroBodyFragementInterruptsChunkedBody:
return "detect if zero body fragment interrupts chunked body"
default:
return "unknown detect method"
}
}