forked from owasp-amass/amass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
findsubdomains.go
50 lines (38 loc) · 1.02 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
// 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/internal/utils"
)
type FindSubdomains struct {
BaseDataSource
}
func NewFindSubdomains() DataSource {
f := new(FindSubdomains)
f.BaseDataSource = *NewBaseDataSource(SCRAPE, "FindSubDomains")
return f
}
func (f *FindSubdomains) Query(domain, sub string) []string {
var unique []string
if domain != sub {
return unique
}
url := f.getURL(domain)
page, err := utils.GetWebPage(url, nil)
if err != nil {
f.log(fmt.Sprintf("%s: %v", url, err))
return unique
}
re := utils.SubdomainRegex(domain)
for _, sd := range re.FindAllString(page, -1) {
if u := utils.NewUniqueElements(unique, sd); len(u) > 0 {
unique = append(unique, u...)
}
}
return unique
}
func (f *FindSubdomains) getURL(domain string) string {
format := "https://findsubdomains.com/subdomains-of/%s"
return fmt.Sprintf(format, domain)
}