forked from owasp-amass/amass
/
findsubdomains.go
80 lines (65 loc) · 1.8 KB
/
findsubdomains.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
// Copyright 2017 Jeff Foley. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package sources
import (
"fmt"
"github.com/OWASP/Amass/amass/core"
"github.com/OWASP/Amass/amass/utils"
)
// FindSubdomains is the Service that handles access to the FindSubdomains data source.
type FindSubdomains struct {
core.BaseService
SourceType string
}
// NewFindSubdomains returns he object initialized, but not yet started.
func NewFindSubdomains(config *core.Config, bus *core.EventBus) *FindSubdomains {
f := &FindSubdomains{SourceType: core.SCRAPE}
f.BaseService = *core.NewBaseService(f, "FindSubdomains", config, bus)
return f
}
// OnStart implements the Service interface
func (f *FindSubdomains) OnStart() error {
f.BaseService.OnStart()
go f.processRequests()
return nil
}
func (f *FindSubdomains) processRequests() {
for {
select {
case <-f.Quit():
return
case req := <-f.DNSRequestChan():
if f.Config().IsDomainInScope(req.Domain) {
f.executeQuery(req.Domain)
}
case <-f.AddrRequestChan():
case <-f.ASNRequestChan():
case <-f.WhoisRequestChan():
}
}
}
func (f *FindSubdomains) executeQuery(domain string) {
re := f.Config().DomainRegex(domain)
if re == nil {
return
}
f.SetActive()
url := f.getURL(domain)
page, err := utils.RequestWebPage(url, nil, nil, "", "")
if err != nil {
f.Config().Log.Printf("%s: %s: %v", f.String(), url, err)
return
}
for _, sd := range re.FindAllString(page, -1) {
f.Bus().Publish(core.NewNameTopic, &core.DNSRequest{
Name: cleanName(sd),
Domain: domain,
Tag: f.SourceType,
Source: f.String(),
})
}
}
func (f *FindSubdomains) getURL(domain string) string {
format := "https://findsubdomains.com/subdomains-of/%s"
return fmt.Sprintf(format, domain)
}