-
Notifications
You must be signed in to change notification settings - Fork 142
/
process.go
132 lines (106 loc) · 3.22 KB
/
process.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
package runner
import (
"encoding/json"
"fmt"
"log"
"os"
"strings"
"sync"
"github.com/logrusorgru/aurora"
)
func Process(config *Config) error {
fingerprints, err := Fingerprints()
if err != nil {
return fmt.Errorf("Process: %v", err)
}
config.initHTTPClient()
config.loadFingerprints()
subdomains := getSubdomains(config)
fmt.Println("[ * ]", "Loaded", len(subdomains), "targets")
fmt.Println("[ * ]", "Loaded", len(fingerprints), "fingerprints")
if config.Output != "" {
fmt.Printf("[ * ] Output filename: %s\n", config.Output)
fmt.Println(isEnabled(config.OnlyVuln), "Save only vulnerable subdomains")
}
fmt.Println(isEnabled(config.HTTPS), "HTTPS by default (--https)")
fmt.Println("[", config.Concurrency, "]", "Concurrent requests (--concurrency)")
fmt.Println(isEnabled(config.VerifySSL), "Check target only if SSL is valid (--verify_ssl)")
fmt.Println("[", config.Timeout, "]", "HTTP request timeout (in seconds) (--timeout)")
fmt.Println(isEnabled(config.HideFails), "Show only potentially vulnerable subdomains (--hide_fails)")
subdomainCh := make(chan string, config.Concurrency+5)
resCh := make(chan *subdomainResult, config.Concurrency)
var wg sync.WaitGroup
wg.Add(config.Concurrency)
var results []*subdomainResult
go func() {
for r := range resCh {
if config.Output != "" {
if config.OnlyVuln && r.Status != ResultVulnerable {
continue
}
results = append(results, r)
}
}
}()
for i := 0; i < config.Concurrency; i++ {
go processor(subdomainCh, resCh, config, &wg)
}
go func() {
for _, subdomain := range subdomains {
subdomainCh <- subdomain
}
close(subdomainCh)
}()
wg.Wait()
close(resCh)
if config.Output != "" {
f, err := os.OpenFile(config.Output, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
}
defer f.Close()
enc := json.NewEncoder(f)
enc.SetIndent("", " ")
if err := enc.Encode(results); err != nil {
return err
}
fmt.Printf("[ * ] Saved output to %q\n", config.Output)
}
return nil
}
func processor(subdomainCh chan string, resCh chan *subdomainResult, c *Config, wg *sync.WaitGroup) {
defer wg.Done()
for subdomain := range subdomainCh {
result := c.checkSubdomain(subdomain)
resCh <- &subdomainResult{
Subdomain: subdomain,
Status: string(result.resStatus),
Engine: result.entry.Engine,
Documentation: result.entry.Documentation,
}
if result.status == aurora.Green("VULNERABLE") {
fmt.Print("-----------------\r\n")
fmt.Println("[ ", result.status, " ]", " - ", subdomain, " [ ", result.entry.Engine, " ] ")
fmt.Println("[ ", aurora.Blue("DISCUSSION"), " ]", " - ", result.entry.Discussion)
fmt.Println("[ ", aurora.Blue("DOCUMENTATION"), " ]", " - ", result.entry.Documentation)
fmt.Print("-----------------\r\n")
} else {
if !c.HideFails {
fmt.Println("[ ", result.status, " ]", " - ", subdomain)
}
}
}
}
func generator(subdomain string, subdomainCh chan string) {
subdomainCh <- subdomain
}
func getSubdomains(c *Config) []string {
if c.Target == "" {
subdomains, err := readSubdomains(c.Targets)
if err != nil {
log.Fatalf("Error reading subdomains: %s", err)
}
return subdomains
}
return strings.Split(c.Target, ",")
}