This repository has been archived by the owner on Jul 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
main.go
182 lines (162 loc) · 4.16 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
package main
import (
"bufio"
"crypto/tls"
"flag"
"fmt"
"io"
"log"
"net"
"net/http"
"net/url"
"os"
"strings"
"sync"
"time"
"github.com/bp0lr/gauplus/output"
"github.com/bp0lr/gauplus/providers"
)
func run(config *providers.Config, domains []string) {
var providerList []providers.Provider
for _, toUse := range config.Providers {
switch toUse {
case "wayback":
wayback := providers.NewWaybackProvider(config)
providerList = append(providerList, wayback)
case "otx":
otx := providers.NewOTXProvider(config)
providerList = append(providerList, otx)
case "commoncrawl":
common, err := providers.NewCommonProvider(config)
if err == nil {
providerList = append(providerList, common)
}
default:
fmt.Fprintf(os.Stderr, "Error: %s is not a valid provider.\n", toUse)
}
}
if(len(providerList) == 0){
fmt.Fprintf(os.Stderr, "Error: All our providers are currently down.\nPlease try again later.\n")
return;
}
results := make(chan string)
var out io.Writer
// Handle results in background
if config.Output == "" {
out = os.Stdout
} else {
ofp, err := os.OpenFile(config.Output, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatalf("Could not open output file: %v\n", err)
}
defer ofp.Close()
out = ofp
}
writewg := &sync.WaitGroup{}
writewg.Add(1)
if config.JSON {
go func() {
output.WriteURLsJSON(results, out, config.Blacklist)
writewg.Done()
}()
} else {
go func() {
output.WriteURLs(results, out, config.Blacklist)
writewg.Done()
}()
}
exitStatus := 0
var i = 0
wg := &sync.WaitGroup{}
for _, domain := range domains {
if config.Verbose {
fmt.Printf("[+] Working on: %v\n", domain)
}
domain := domain
wg.Add(len(providerList))
i++
for _, provider := range providerList {
go func(provider providers.Provider) {
defer wg.Done()
if err := provider.Fetch(domain, results); err != nil {
if config.Verbose {
_, _ = fmt.Fprintln(os.Stderr, err)
}
}
}(provider)
}
if i >= config.MaxThreads {
i = 0
wg.Wait()
}
}
wg.Wait()
close(results)
// Wait for writer to finish
writewg.Wait()
os.Exit(exitStatus)
}
func main() {
var domains []string
verbose := flag.Bool("v", false, "enable verbose mode")
includeSubs := flag.Bool("subs", false, "include subdomains of target domain")
maxRetries := flag.Uint("retries", 5, "amount of retries for http client")
useProviders := flag.String("providers", "wayback,otx,commoncrawl", "providers to fetch urls for")
version := flag.Bool("version", false, "show gau version")
proxy := flag.String("p", "", "HTTP proxy to use")
output := flag.String("o", "", "filename to write results to")
jsonOut := flag.Bool("json", false, "write output as json")
randomAgent := flag.Bool("random-agent", false, "use random user-agent")
maxThreads := flag.Int("t", 5, "amount of parallel workers")
blacklist := flag.String("b","","extensions to skip, ex: ttf,woff,svg,png,jpg")
flag.Parse()
if *version {
fmt.Printf("gau version: %s\n", providers.Version)
os.Exit(0)
}
if *maxThreads > 100 {
*maxThreads = 100
}
if flag.NArg() > 0 {
domains = flag.Args()
} else {
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
domains = append(domains, s.Text())
}
}
tr := &http.Transport{
DialContext: (&net.Dialer{
Timeout: 5 * time.Second,
}).DialContext,
TLSHandshakeTimeout: 5 * time.Second,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
if *proxy != "" {
if p, err := url.Parse(*proxy); err == nil {
tr.Proxy = http.ProxyURL(p)
}
}
extensions := strings.Split(*blacklist,",")
extMap := make(map[string]struct{})
for _, ext := range extensions {
ext = strings.Replace(ext, ".", "", -1)
extMap[strings.ToLower(ext)] = struct{}{}
}
config := providers.Config{
Verbose: *verbose,
MaxThreads: *maxThreads,
RandomAgent: *randomAgent,
MaxRetries: *maxRetries,
IncludeSubdomains: *includeSubs,
Output: *output,
JSON: *jsonOut,
Blacklist: extMap,
Client: &http.Client{
Timeout: time.Second * 15,
Transport: tr,
},
Providers: strings.Split(*useProviders, ","),
}
run(&config, domains)
}