-
Notifications
You must be signed in to change notification settings - Fork 73
/
detect_multi.go
93 lines (80 loc) · 1.74 KB
/
detect_multi.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
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func detectMultipleTargets(targets []string,
connectTo string,
threads int,
timeout time.Duration,
csv *CSVLogWriter,
verbose bool) error {
if len(targets) == 0 {
return fmt.Errorf("no targets specified")
}
rand.Shuffle(len(targets),
func(i, j int) { targets[i], targets[j] = targets[j], targets[i] },
)
queue := make(chan *DetectParams, threads)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
defer close(queue)
pushDetectJobs(targets, queue)
}()
wg.Add(threads)
for i := 0; i < threads; i++ {
go func() {
defer wg.Done()
for job := range queue {
distinguishable, err := Detect(job, connectTo, timeout, verbose)
var verdict string
if err != nil {
verdict = err.Error()
} else {
verdict = distinguishable.String()
}
if distinguishable != Indistinguishable {
fmt.Printf("%s: %v\n", job, verdict)
}
if csv != nil {
_ = csv.Log(job, distinguishable)
}
}
}()
}
wg.Wait()
return nil
}
func pushDetectJobs(targets []string, queue chan<- *DetectParams) {
for _, dm := range DetectMethods {
for _, sm := range SmugglingMethods {
if !dm.AllowsSmugglingMethod(sm) {
continue
}
for _, pm := range PaddingMethods {
for _, rm := range []string{"POST", "OPTIONS", "GET"} {
variants := sm.GetVariants()
for _, v := range variants {
for _, target := range targets {
queue <- &DetectParams{
Target: target,
DetectMethod: dm,
SmugglingMethod: sm,
SmugglingVariant: v,
PaddingMethod: pm,
RequestMethod: rm,
}
}
}
}
}
}
}
}
func init() {
rand.Seed(time.Now().UnixNano())
}