-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.go
More file actions
261 lines (222 loc) · 6.73 KB
/
main.go
File metadata and controls
261 lines (222 loc) · 6.73 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
//
// @bp0lr - 10/02/2020
//
package main
import (
"bufio"
"crypto/tls"
"fmt"
"io/ioutil"
"math/rand"
"net"
"net/http"
"net/url"
"os"
"regexp"
"strconv"
"strings"
"sync"
"time"
"github.com/forestgiant/sliceutil"
flag "github.com/spf13/pflag"
)
var (
concurrencyArg int
HeaderArg []string
urlArg string
statusListArg string
proxyArg string
fingerPrintArg string
outputFileArg string
queryArg string
verboseArg bool
followRedirectArg bool
useRandomAgentArg bool
testHTTPArg bool
)
func main() {
flag.StringArrayVarP(&HeaderArg, "header", "H", nil, "Add custom Headers to the request")
flag.IntVarP(&concurrencyArg, "concurrency", "c", 50, "Concurrency level")
flag.StringVarP(&urlArg, "url", "u", "", "The url to check")
flag.StringVarP(&statusListArg, "status-code", "s", "", "List valid status codes (default 200)")
flag.BoolVarP(&verboseArg, "verbose", "v", false, "Display extra info about what is going on")
flag.BoolVarP(&followRedirectArg, "follow-redirect", "f", false, "Follow redirects (Default: false)")
flag.StringVarP(&proxyArg, "proxy", "p", "", "Add a HTTP proxy")
flag.StringVarP(&queryArg, "query", "q", "", "replace the query for each url")
flag.BoolVarP(&useRandomAgentArg, "random-agent", "r", false, "Set a random User Agent")
flag.StringVarP(&fingerPrintArg, "finger-print", "m", "", "Regex for a specific string on response")
flag.StringVarP(&outputFileArg, "output", "o", "", "Output file to save the results to")
flag.BoolVarP(&testHTTPArg, "test", "t", false, "Test http && https for a single url")
flag.Parse()
//concurrency
concurrency := 20
if concurrencyArg > 0 {
concurrency = concurrencyArg
}
//status code
status := strings.Split(statusListArg, ",")
if len(status[0]) < 1 {
status = status[:0]
status = append(status, "200")
}
client := newClient(proxyArg, followRedirectArg)
jobs := make(chan string)
var wg sync.WaitGroup
var outputFile *os.File
var err0 error
if outputFileArg != "" {
outputFile, err0 = os.OpenFile(outputFileArg, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644)
if err0 != nil {
fmt.Printf("cannot write %s: %s", outputFileArg, err0.Error())
return
}
defer outputFile.Close()
}
for i := 0; i < concurrency; i++ {
wg.Add(1)
go func() {
for raw := range jobs {
if len(queryArg) > 0 {
tmp_u, _ := url.Parse(raw)
raw = tmp_u.Scheme + "://" + tmp_u.Host + "/" + queryArg
}
u, err := url.ParseRequestURI(raw)
if err != nil {
if verboseArg {
fmt.Printf("[-] Invalid url: %s\n", raw)
}
continue
}
if testHTTPArg {
if strings.HasPrefix(u.String(), "http://") {
processRequest(u, client, status, outputFile)
alt, _ := url.ParseRequestURI(strings.Replace(u.String(), "http:", "https:", 1))
processRequest(alt, client, status, outputFile)
} else {
processRequest(u, client, status, outputFile)
alt, _ := url.ParseRequestURI(strings.Replace(u.String(), "https:", "http:", 1))
processRequest(alt, client, status, outputFile)
}
} else {
processRequest(u, client, status, outputFile)
}
}
wg.Done()
}()
}
if len(urlArg) < 1 {
sc := bufio.NewScanner(os.Stdin)
for sc.Scan() {
jobs <- sc.Text()
}
} else {
jobs <- urlArg
}
close(jobs)
wg.Wait()
}
func processRequest(u *url.URL, client *http.Client, status []string, outputFile *os.File) {
if verboseArg {
fmt.Printf("[+] Testing: %v\n", u.String())
}
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
if verboseArg {
fmt.Printf("[-] Error: %v\n", err)
}
return
}
if useRandomAgentArg {
req.Header.Set("User-Agent", getUserAgent())
} else {
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; wurl/1.0)")
}
// add headers to the request
for _, h := range HeaderArg {
parts := strings.SplitN(h, ":", 2)
if len(parts) != 2 {
continue
}
req.Header.Set(parts[0], parts[1])
}
// send the request
resp, err := client.Do(req)
if err != nil {
if verboseArg {
fmt.Printf("[-] Error: %v\n", err)
}
return
}
defer resp.Body.Close()
if sliceutil.Contains(status, strconv.Itoa(resp.StatusCode)) {
if verboseArg {
fmt.Printf("[+] %v [%v]\n", u.String(), resp.StatusCode)
} else {
if fingerPrintArg != "" {
data, _ := ioutil.ReadAll(resp.Body)
var re, _ = regexp.Compile(fingerPrintArg)
if re.MatchString(string(data)) == true {
if outputFileArg != "" {
outputFile.WriteString(u.String() + "\n")
} else {
fmt.Printf("%v\n", u.String())
}
}
} else {
if outputFileArg != "" {
outputFile.WriteString(u.String() + "\n")
} else {
fmt.Printf("%v\n", u.String())
}
}
}
} else {
if verboseArg {
fmt.Printf("[-] %v [%v]\n", u.String(), resp.StatusCode)
}
}
}
func newClient(proxy string, followRedirect bool) *http.Client {
tr := &http.Transport{
MaxIdleConns: 30,
IdleConnTimeout: time.Second,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DialContext: (&net.Dialer{
Timeout: time.Second * 5,
}).DialContext,
}
if proxy != "" {
if p, err := url.Parse(proxy); err == nil {
tr.Proxy = http.ProxyURL(p)
}
}
client := &http.Client{
Transport: tr,
Timeout: time.Second * 5,
}
if !followRedirect {
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
}
return client
}
func getUserAgent() string {
payload := []string{
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0",
"Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H321 Safari/600.1.4",
"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
"Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53",
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)",
}
rand.Seed(time.Now().UnixNano())
randomIndex := rand.Intn(len(payload))
pick := payload[randomIndex]
return pick
}