-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
119 lines (102 loc) · 3.04 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
package main
import (
"bufio"
"fmt"
"net"
"os"
"sync"
)
func resolveSubdomain(subdomain string, domain string, results chan string, wg *sync.WaitGroup) {
defer wg.Done()
fullDomain := subdomain + "." + domain
_, err := net.LookupHost(fullDomain)
if err == nil {
// fmt.Println("[+] Found:", fullDomain)
fmt.Println(fullDomain)
results <- fullDomain
}
}
func worker(domain string, wordlist chan string, results chan string, wg *sync.WaitGroup) {
for subdomain := range wordlist {
wg.Add(1)
resolveSubdomain(subdomain, domain, results, wg)
}
}
func loadWordlist(wordlistPath string) ([]string, error) {
file, err := os.Open(wordlistPath)
if err != nil {
return nil, err
}
defer file.Close()
var wordlist []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
wordlist = append(wordlist, scanner.Text())
}
if err := scanner.Err(); err != nil {
return nil, err
}
return wordlist, nil
}
func printBanner() {
banner := `
██████ ██████ ██████ ████████ ███ ██ ███████ ██████
██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██
██ ███ ██ ██ ██████ ██ ██ ██ ██ █████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ██████ ██████ ██ ██ ████ ███████ ██ ██
`
author := "Author: Amit Agarwal"
fmt.Fprintln(os.Stderr, banner) // Print banner to stderr
fmt.Fprintln(os.Stderr, author) // Print author name to stderr
}
func main() {
// Print the banner to stderr
printBanner()
if len(os.Args) != 4 {
fmt.Println("Usage: go run main.go <domain> <wordlist> <threads>")
os.Exit(1)
}
domain := os.Args[1]
wordlistPath := os.Args[2]
threadCount := 0
// Parse thread count
_, err := fmt.Sscanf(os.Args[3], "%d", &threadCount)
if err != nil || threadCount <= 1 {
fmt.Println("Invalid number of threads. Provide a positive integer greater than 1.")
os.Exit(1)
}
// Load the wordlist
wordlist, err := loadWordlist(wordlistPath)
if err != nil {
fmt.Println("Error loading wordlist:", err)
os.Exit(1)
}
// Channels for wordlist distribution and result collection
wordlistChan := make(chan string, len(wordlist))
resultsChan := make(chan string)
var wg sync.WaitGroup
// Start workers
for i := 0; i < threadCount; i++ {
go worker(domain, wordlistChan, resultsChan, &wg)
}
// Feed wordlist into the channel
for _, word := range wordlist {
wordlistChan <- word
}
close(wordlistChan)
// Wait for all goroutines to finish
go func() {
wg.Wait()
close(resultsChan)
}()
// Collect results
found := make([]string, 0)
for result := range resultsChan {
found = append(found, result)
}
// fmt.Println("\nValid Subdomains Found:")
// for _, subdomain := range found {
// fmt.Println(subdomain)
// }
}