-
Notifications
You must be signed in to change notification settings - Fork 8
/
uforall.go
312 lines (257 loc) · 7.17 KB
/
uforall.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
package main
import (
"bufio"
"flag"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"regexp"
"strings"
"sort"
)
// prints the version message
const version = "0.0.2"
func printVersion() {
fmt.Printf("Current uforall version %s\n", version)
}
// Prints the Colorful banner
func printBanner() {
banner := `
____ __ __
__ __ / __/____ _____ ____ _ / // /
/ / / // /_ / __ \ / ___// __ // // /
/ /_/ // __// /_/ // / / /_/ // // /
\__,_//_/ \____//_/ \__,_//_//_/
`
fmt.Printf("%s\n%50s\n\n", banner, "Current uforall version "+version)
}
func getArchiveUrls(domain string) {
url := fmt.Sprintf("http://web.archive.org/cdx/search/cdx?url=*.%s/*&output=text&fl=original&collapse=urlkey", domain)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Fprintln(os.Stderr, "Error creating request:", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Fprintln(os.Stderr, "Error making request:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Fprintln(os.Stderr, "HTTP error:", resp.Status)
return
}
scanner := bufio.NewScanner(resp.Body)
for scanner.Scan() {
line := scanner.Text()
fmt.Println(line)
}
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "Error reading response body:", err)
}
}
type OtxUrlData struct {
Url string `json:"url"`
}
type OtxResponseData struct {
FullSize int `json:"full_size"`
UrlList []OtxUrlData `json:"url_list"`
}
func getOtxUrls(domain string) {
url := fmt.Sprintf("https://otx.alienvault.com/api/v1/indicators/domain/%s/url_list", domain)
client := &http.Client{}
// Initial request to get total pages
resp, err := client.Get(url + "?limit=500&page=1")
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Fprintln(os.Stderr, "HTTP error:", resp.Status)
return
}
var data OtxResponseData
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
fmt.Fprintln(os.Stderr, "JSON decode error:", err)
return
}
totalUrls := data.FullSize
totalPages := (totalUrls + 499) / 500 // Using ceiling to calculate total pages
for i := 1; i <= totalPages; i++ {
resp, err := client.Get(fmt.Sprintf("%s?limit=500&page=%d", url, i))
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Fprintln(os.Stderr, "HTTP error:", resp.Status)
return
}
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
fmt.Fprintln(os.Stderr, "JSON decode error:", err)
return
}
for _, urlData := range data.UrlList {
fmt.Println(urlData.Url)
}
}
}
type UrlscanResult struct {
Page struct {
URL string `json:"url"`
} `json:"page"`
Task struct {
URL string `json:"url"`
} `json:"task"`
}
type UrlscanResponseData struct {
Results []UrlscanResult `json:"results"`
}
func getUrlscanUrls(domain string) {
url := fmt.Sprintf("https://urlscan.io/api/v1/search/?q=domain:%s&size=10000", domain)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Fprintln(os.Stderr, "Error creating request:", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Fprintln(os.Stderr, "Error making request:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Fprintln(os.Stderr, "HTTP error:", resp.Status)
return
}
var data UrlscanResponseData
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
fmt.Fprintln(os.Stderr, "JSON decode error:", err)
return
}
// Extract URLs
var urls []string
for _, result := range data.Results {
if result.Page.URL != "" {
urls = append(urls, result.Page.URL)
}
if result.Task.URL != "" {
urls = append(urls, result.Task.URL)
}
}
// Remove duplicates and sort URLs
urlSet := make(map[string]struct{})
for _, url := range urls {
urlSet[url] = struct{}{}
}
var uniqueUrls []string
for url := range urlSet {
uniqueUrls = append(uniqueUrls, url)
}
sort.Strings(uniqueUrls)
// Print URLs
for _, url := range uniqueUrls {
fmt.Println(url)
}
}
// Fetch URLs from Common Crawl
type CdxApi struct {
CDXAPI string `json:"cdx-api"`
}
func getCommonCrawlUrls(domain string) {
resp, err := http.Get("https://index.commoncrawl.org/collinfo.json")
if err != nil {
fmt.Fprintf(os.Stderr, "RequestException: %v\n", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading response body: %v\n", err)
return
}
var data []CdxApi
if err := json.Unmarshal(body, &data); err != nil {
fmt.Fprintf(os.Stderr, "JSON decode error: %v\n", err)
return
}
// Process each URL sequentially
for _, item := range data {
apiUrl := item.CDXAPI
urls := fetchCommonCrawlUrls(apiUrl, domain)
for _, url := range urls {
fmt.Println(url)
}
}
}
func fetchCommonCrawlUrls(apiUrl, domain string) []string {
var urls []string
param := fmt.Sprintf("?url=*.%s&fl=url&output=json", domain)
indexUrl := apiUrl + param
resp, err := http.Get(indexUrl)
if err != nil {
fmt.Fprintf(os.Stderr, "ConnectionError: %v\n", err)
return urls
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading response body: %v\n", err)
return urls
}
urlPattern := regexp.MustCompile(`"url": "([^"]+)"`)
matches := urlPattern.FindAllStringSubmatch(string(body), -1)
for _, match := range matches {
if len(match) > 1 {
urls = append(urls, match[1])
}
}
return urls
}
func main() {
toolFlag := flag.String("t", "all", "Comma-separated list of tools to run: 'otx', 'archive', 'urlscan', 'commoncrawl', or 'all'")
version := flag.Bool("version", false, "Print the version of the tool and exit.")
silent := flag.Bool("silent", false, "silent mode.")
flag.Parse()
// Print version and exit if -version flag is provided
if *version {
printBanner()
printVersion()
return
}
// Don't Print banner if -silnet flag is provided
if !*silent {
printBanner()
}
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
domain := strings.TrimSpace(scanner.Text())
// Handle each tool based on the flag
if *toolFlag == "all" || strings.Contains(*toolFlag, "archive") {
getArchiveUrls(domain)
}
if *toolFlag == "all" || strings.Contains(*toolFlag, "otx") {
getOtxUrls(domain)
}
if *toolFlag == "all" || strings.Contains(*toolFlag, "urlscan") {
getUrlscanUrls(domain)
}
if *toolFlag == "all" || strings.Contains(*toolFlag, "commoncrawl") {
getCommonCrawlUrls(domain)
}
}
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "Error reading input:", err)
}
}