forked from rmada/tsunami
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflood_worker.go
59 lines (53 loc) · 1.26 KB
/
flood_worker.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
package main
import (
"bytes"
"crypto/tls"
"net/http"
)
type floodWorker struct {
dead bool
exitChan chan int
id int
RequestCounter int
}
func (fw *floodWorker) Start() {
go func() {
defer fw.Kill()
client := &http.Client{}
if scheme == "https" {
//Skip certificate verify for performance
secureTransport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: secureTransport}
}
for {
if fw.dead {
return
}
body := []byte(tokenizedBody.String())
req, _ := http.NewRequest(*method, tokenizedTarget.String(), bytes.NewBuffer(body))
req.Header.Set("User-Agent", getRandomUserAgent())
if *method == "POST" {
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
}
//Inject custom headers right before sending
injectHeaders(req)
resp, err := client.Do(req)
if err != nil {
lastErr = err.Error()
}
// Close body to prevent a "too many files open" error
err = resp.Body.Close()
if err != nil && lastErr == "" {
lastErr = err.Error()
}
fw.RequestCounter += 1 //Worker specific counter
requestChan <- true
}
}()
}
func (fw *floodWorker) Kill() {
fw.dead = true
fw.exitChan <- fw.id
}