-
Notifications
You must be signed in to change notification settings - Fork 0
/
attack.go
118 lines (102 loc) · 2.75 KB
/
attack.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
package utils
import (
"crypto/tls"
"fmt"
"github.com/fatih/color"
"net/http"
"net/url"
"runtime"
"strconv"
"sync"
"time"
)
// define global variables
var threads = 5
var timeout = 5 * time.Second // will eventually add in functionality to change this.
var wg sync.WaitGroup
func Pause() {
fmt.Println("You should be able to pause using interactive commands")
}
func Resume() {
fmt.Println("You should be able to resume using interactive commands")
}
func SetThreads(change int) {
threads = change
}
func GetThreads() (num string) {
return strconv.Itoa(threads)
}
func MakeRequest(payload string) {
if data.Item.Host.Text == "" {
color.Red("No data set. Import Data first. \n")
} else {
// keep the request from breaking by checking to see if Proxy address is empty
if PROXY_ADDR != "" {
// For control over proxies, TLS configuration, keep-alives, compression, and other settings, create a Transport
proxyUrl, _ := url.Parse(PROXY_ADDR)
tr := &http.Transport{
MaxIdleConns: 10,
IdleConnTimeout: timeout,
DisableCompression: true,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
Proxy: http.ProxyURL(proxyUrl),
}
// For control over HTTP client headers,redirect policy, and other settings use a Client
client := &http.Client{Transport: tr}
// build the request
req, err := http.NewRequest(data.Item.Method, data.Item.Protocol+"://"+data.Item.Host.Text+data.Item.Path+"/"+payload, nil)
if err != nil {
color.Red(err.Error())
}
// call the request.
resp, err := client.Do(req)
if err != nil {
color.Red(err.Error())
} else {
color.Green(resp.Status)
}
} else {
// exclude the Proxy Settings so that it doesn't break the request.
tr := &http.Transport{
MaxIdleConns: 10,
IdleConnTimeout: timeout,
DisableCompression: true,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
// For control over HTTP client headers,redirect policy, and other settings use a Client
client := &http.Client{Transport: tr}
// build the request
req, err := http.NewRequest(data.Item.Method, data.Item.Protocol+"://"+data.Item.Host.Text+data.Item.Path+"/"+payload, nil)
if err != nil {
color.Red(err.Error())
}
//// call the request.
resp, err := client.Do(req)
if err != nil {
color.Red(err.Error())
} else {
color.Green(resp.Status)
}
}
}
time.Sleep(10 * time.Second)
defer wg.Done()
}
func SingleRequest() {
wg.Add(1)
go MakeRequest("")
wg.Wait()
}
func Attack() {
// build options here
runtime.GOMAXPROCS(threads)
if GetPayloadLen() <= 0 {
color.Red("No Payloads imported yet.")
} else {
for _, attack := range payloads {
wg.Add(1)
go MakeRequest(attack)
}
wg.Wait()
}
}