-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
151 lines (133 loc) · 3.48 KB
/
utils.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
package main
import (
"bufio"
"context"
"fmt"
"io"
"net"
"net/http"
"os"
"strings"
"sync"
"time"
)
// List of vulnerable indicators
var vulnerableIndicators = []string{
"No resources found",
"404 Not Found",
"Website not configured",
"This resource is not available",
"The requested site does not exist",
"Your app is ready to go!",
"GitHub",
"Domain not found",
"Error 404",
"Unknown domain",
"Site not found",
// More to be added
}
// Worker function to process subdomains
func worker(ctx context.Context, subdomains <-chan string, externalServices map[string]struct{}, results chan<- string, wg *sync.WaitGroup, verbose, check bool, timeout time.Duration) {
defer wg.Done()
for {
select {
case <-ctx.Done():
if verbose {
fmt.Println("[INFO] Worker shutting down")
}
return
case subdomain, ok := <-subdomains:
if !ok {
return
}
time.Sleep(delayBetweenRequests)
cleanedSubdomain := strings.TrimPrefix(strings.TrimPrefix(subdomain, "http://"), "https://")
cname, err := lookupCNAME(ctx, cleanedSubdomain, timeout)
if err != nil {
if verbose {
fmt.Printf("[NO CNAME] %s: %v\n", cleanedSubdomain, err)
}
continue
}
vulnerable := false
for extService := range externalServices {
if strings.HasSuffix(cname, extService) {
vulnerable = true
break
}
}
if vulnerable {
if check && checkServiceVulnerability(cleanedSubdomain, verbose) {
results <- fmt.Sprintf("[VULNERABLE] %s -> %s", cleanedSubdomain, cname)
} else if !check {
results <- fmt.Sprintf("[POTENTIALLY VULNERABLE] %s -> %s", cleanedSubdomain, cname)
} else if verbose {
results <- fmt.Sprintf("[SAFE] %s -> %s (Not exploitable)", cleanedSubdomain, cname)
}
} else if verbose {
results <- fmt.Sprintf("[SAFE] %s -> %s", cleanedSubdomain, cname)
}
}
}
}
// Lookup CNAME with context and timeout
func lookupCNAME(ctx context.Context, subdomain string, timeout time.Duration) (string, error) {
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
cname, err := net.DefaultResolver.LookupCNAME(ctx, subdomain)
if err != nil {
return "", err
}
return strings.TrimSuffix(cname, "."), nil
}
// Check if the service is actually vulnerable
func checkServiceVulnerability(subdomain string, verbose bool) bool {
url := fmt.Sprintf("https://%s", subdomain)
resp, err := http.Get(url)
if err != nil {
if verbose {
fmt.Printf("[ERROR] Failed to fetch %s: %v\n", url, err)
}
return false
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
if verbose {
fmt.Printf("[ERROR] Failed to read response body for %s: %v\n", url, err)
}
return false
}
bodyStr := strings.ToLower(string(body))
for _, indicator := range vulnerableIndicators {
if strings.Contains(bodyStr, strings.ToLower(indicator)) {
if verbose {
fmt.Printf("[DEBUG] Found vulnerable indicator '%s' in %s\n", indicator, subdomain)
}
return true
}
}
if verbose {
fmt.Printf("[DEBUG] No vulnerable indicators found for %s\n", subdomain)
}
return false
}
func loadExternalServices(file string) (map[string]struct{}, error) {
services := make(map[string]struct{})
f, err := os.Open(file)
if err != nil {
return nil, err
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
service := strings.TrimSpace(scanner.Text())
if service != "" {
services[service] = struct{}{}
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
return services, nil
}