-
Notifications
You must be signed in to change notification settings - Fork 28
/
passive.go
56 lines (44 loc) · 1.42 KB
/
passive.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
package passive
import (
"context"
"fmt"
"sync"
"time"
"github.com/ZhuriLab/Starmap/pkg/subscraping"
)
// EnumerateSubdomains enumerates all the subdomains for a given domain
func (a *Agent) EnumerateSubdomains(domain string, keys *subscraping.Keys, proxy string, rateLimit, timeout int, maxEnumTime time.Duration) chan subscraping.Result {
results := make(chan subscraping.Result)
go func() {
session, err := subscraping.NewSession(domain, keys, proxy, rateLimit, timeout)
if err != nil {
results <- subscraping.Result{Type: subscraping.Error, Error: fmt.Errorf("could not init passive session for %s: %s", domain, err)}
}
ctx, cancel := context.WithTimeout(context.Background(), maxEnumTime)
timeTaken := make(map[string]string)
timeTakenMutex := &sync.Mutex{}
wg := &sync.WaitGroup{}
// Run each source in parallel on the target domain
for source, runner := range a.sources {
wg.Add(1)
now := time.Now()
go func(source string, runner subscraping.Source) {
for resp := range runner.Run(ctx, domain, session) {
results <- resp
}
duration := time.Since(now)
timeTakenMutex.Lock()
timeTaken[source] = fmt.Sprintf("Source took %s for enumeration\n", duration)
timeTakenMutex.Unlock()
wg.Done()
}(source, runner)
}
wg.Wait()
//for source, data := range timeTaken {
// gologger.Verbose().Label(source).Msg(data)
//}
close(results)
cancel()
}()
return results
}