-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
115 lines (87 loc) · 2.17 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
package main
import (
"bufio"
"flag"
"fmt"
"net/http"
"os"
"sync"
)
const (
GCP_URL = "https://www.googleapis.com/storage/v1/b/"
green = "\033[32m" // Green color
red = "\033[31m" // Red color
reset = "\033[0m" // Reset color
)
func getwords(filename string) []string {
file, err := os.Open(filename)
_ = file
if err != nil {
exit(fmt.Sprintf("Error Opening %s", filename))
}
var wordlist []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
word := scanner.Text()
wordlist = append(wordlist, word)
}
file.Close()
return wordlist
}
func main() {
jobs := make(chan string, 100)
key := flag.String("k", "", "keyword that you want to enumerate")
filename := flag.String("file", "", "File name containing the word list")
concurrency := flag.Int("c", 5, "Default concurrency value is 5 you can change the value using the c flag")
flag.Parse()
if *key == "" && *filename == "" {
flag.PrintDefaults()
exit("")
}
// function to get the words from the file
//fmt.Println(time.Since(start))
wordlist := getwords(*filename)
//fmt.Println(time.Since(start))
// function to generate the worldlist using the file key and words from the file
endpoints := mutate(*key, wordlist)
// fmt.Println(time.Since(start))
//fmt.Println(len(endpoints))
// go routine
var wg sync.WaitGroup
for i := 0; i < *concurrency; i++ {
wg.Add(1)
go enumerate(jobs, &wg)
}
for _, value := range endpoints {
jobs <- value
}
close(jobs)
wg.Wait()
}
func enumerate(jobs chan string, wg *sync.WaitGroup) {
defer wg.Done()
for job := range jobs {
// reading the permutaed world
url := fmt.Sprintf("https://www.googleapis.com/storage/v1/b/%s", job)
res, err := http.Head(url)
if err != nil {
panic(err)
}
if res.StatusCode != (400) && res.StatusCode != (404) {
fmt.Println(green + "Valid:" + job + reset)
} else {
fmt.Println(red + "Invalid:" + job + reset)
}
}
}
func mutate(key string, words []string) []string {
var ret []string
for _, word := range words {
ret = append(ret, key+"-"+word, word+"-"+key, key+"_"+word, word+"_"+key, key+word, word+key)
}
return ret
}
func exit(msg string) {
fmt.Println(msg)
os.Exit(1)
}