-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
83 lines (77 loc) · 1.89 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
package main
import (
"bufio"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"sync"
"time"
)
func main() {
input := flag.String("f", "", "path to list of urls, defaults to stdin if left empty")
domain := flag.String("d", "", "domain name")
concurrent := flag.Int("c", 10, "number of concurrent requests to make")
timeout := flag.Int("t", 5, "timeout in seconds")
cookies := flag.String("cookies", "", "cookies to send with the request")
flag.Parse()
var f io.ReadCloser
if *input == "" {
f = os.Stdin
} else {
file, err := os.Open(*input)
if err != nil {
log.Fatal(err)
}
f = file
}
defer f.Close()
work := make(chan string)
go func() {
s := bufio.NewScanner(f)
for s.Scan() {
work <- s.Text()
}
if s.Err() != nil {
log.Printf("error while scanning input: %v", s.Err())
}
close(work)
}()
wg := &sync.WaitGroup{}
client := &http.Client{Timeout: time.Second * time.Duration(*timeout)}
for i := 0; i < *concurrent; i++ {
wg.Add(1)
go check(client, *domain, *cookies, work, wg)
}
wg.Wait()
}
func check(client *http.Client, domain, cookies string, work chan string, wg *sync.WaitGroup) {
for url := range work {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
continue
}
if cookies != "" {
req.Header.Set("Cookie", cookies)
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
origins := []string{"https://asdf.com", "https://asdf" + domain, "https://" + domain + "asdf.com", "null", "https://asdf." + domain + "asdf.com"}
for _, v := range origins {
req.Header.Set("Origin", v)
resp, err := client.Do(req)
if err != nil {
continue
}
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
if resp.Header.Get("Access-Control-Allow-Origin") == v {
fmt.Println(url, v)
break
}
}
}
wg.Done()
}