-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
91 lines (75 loc) · 2.09 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
package main
import (
"bufio"
"context"
"flag"
"fmt"
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"
)
var delayBetweenRequests time.Duration
func main() {
subsFile := flag.String("file", "", "File containing subdomains")
externalFile := flag.String("wordlist", "", "File containing external services")
verbose := flag.Bool("v", false, "Enable verbose output")
check := flag.Bool("check", false, "Enable exploitability check")
workers := flag.Int("c", 10, "Number of concurrent workers")
timeout := flag.Int("t", 5, "Timeout for DNS lookups in seconds")
delay := flag.Int("d", 100, "Delay between requests in milliseconds")
flag.Parse()
if *subsFile == "" || *externalFile == "" {
fmt.Println("Usage: go run main.go -file=subs.txt -wordlist=external.txt [-v] [-check] [-c=10] [-t=5] [-d=100]")
os.Exit(1)
}
delayBetweenRequests = time.Duration(*delay) * time.Millisecond
externalServices, err := loadExternalServices(*externalFile)
if err != nil {
fmt.Printf("Error loading external services: %v\n", err)
os.Exit(1)
}
subs, err := os.Open(*subsFile)
if err != nil {
fmt.Printf("Error opening subdomains file: %v\n", err)
os.Exit(1)
}
defer subs.Close()
// Setup channels and wait group
subdomains := make(chan string, *workers)
results := make(chan string, *workers)
var wg sync.WaitGroup
ctx, cancel := context.WithCancel(context.Background())
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
go func() {
<-signalChan
fmt.Println("\n[INFO] Received interrupt signal. Shutting down...")
cancel()
}()
for i := 0; i < *workers; i++ {
wg.Add(1)
go worker(ctx, subdomains, externalServices, results, &wg, *verbose, *check, time.Duration(*timeout)*time.Second)
}
go func() {
wg.Wait()
close(results)
}()
// Read subdomains and send them to workers
go func() {
scanner := bufio.NewScanner(subs)
for scanner.Scan() {
select {
case <-ctx.Done():
break
case subdomains <- strings.TrimSpace(scanner.Text()):
}
}
close(subdomains)
}()
for result := range results {
fmt.Println(result)
}
}