-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
157 lines (129 loc) · 3.56 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
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"github.com/projectdiscovery/goflags"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/httpx/runner"
)
// for httpx's weird input requirement.
// returns a map split with spaces as a string, like "google.com tesla.com yahoo.com".
// input: map[string]bool, output: string
func mapToString(m map[string]bool) string {
var result string
for key := range m {
// Add space if result is not empty
if result != "" {
result += " "
}
result += key
}
return result
}
// return the list from stdin
// input: nothing, output: map[string]bool
func stdinput() map[string]bool {
var allUrls = make(map[string]bool)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
allUrls[scanner.Text()] = true
}
return allUrls
}
// filter a url, by only returning the subdomain name
// input: string, output: string
func filterURL(url string) string {
//remove parameters
url = strings.Split(url, "?")[0]
// remove http
if strings.Contains(url, "://") {
url = strings.Split(url, "://")[1]
}
// remove path
url = strings.Split(url, "/")[0]
url = strings.Split(url, "\\")[0]
if strings.Contains(url, "@") {
// remove anything before @ sign
url = strings.Split(url, "@")[1]
}
// remove port
url = strings.Split(url, ":")[0]
return url
}
// run httpx on all the filtered domains, return the live ones
// input: map[string]bool, output: map[string]bool
func getLiveDomains(allFilteredDomains map[string]bool) map[string]bool {
// change the allFilteredDomains map to a data type httpx accepts
// run httpx on all the filtered domains
result := make(map[string]bool)
domainSlice := strings.Split(mapToString(allFilteredDomains), " ")
// httpx options
gologger.DefaultLogger.SetMaxLevel(-1) // don't output anything
options := runner.Options{
Methods: "GET",
Timeout: 5,
Threads: 60,
Silent: true,
RandomAgent: true,
Retries: 3,
InputTargetHost: goflags.StringSlice(domainSlice),
OnResult: func(r runner.Result) {
// handle error
if r.Err != nil {
return
}
// if result exists, is not empty, and doesn't have a space
if r.Input != "" && r.Input != " " {
// if doesn't already exist in map
if !result[r.Input] {
// add filtered domain to map
result[filterURL(r.URL)] = true
}
}
},
}
if err := options.ValidateOptions(); err != nil {
log.Fatal(err)
}
httpxRunner, err := runner.New(&options)
if err != nil {
log.Fatal(err)
}
defer httpxRunner.Close()
httpxRunner.RunEnumeration()
// return all of the filtered domains as a map
return result
}
// return all the entries from the list with the live domains to stdout
// input: map[string]bool, map[string]bool , ouput: map[string]bool
func returnLiveURLS(allLiveDomains map[string]bool, stdin map[string]bool) map[string]bool {
var allLiveURLS = make(map[string]bool)
for url := range stdin {
for liveDomain := range allLiveDomains {
if strings.Contains(url, "://"+liveDomain) {
allLiveURLS[url] = true
}
}
}
return allLiveURLS
}
// start
func main() {
stdin := stdinput()
// filter all the URL's
var allFilteredDomains = make(map[string]bool)
for obj := range stdin {
allFilteredDomains[filterURL(obj)] = true
}
// get all the live domains
allLiveDomains := getLiveDomains(allFilteredDomains)
// get all the live URL's, according to the live domains
allLiveURLS := returnLiveURLS(allLiveDomains, stdin)
// print everything out
for obj := range allLiveURLS {
fmt.Println(obj) // print all the live urls
}
}