/
censys.go
44 lines (34 loc) · 897 Bytes
/
censys.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
// 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"
"log"
"github.com/caffix/amass/amass/internal/utils"
)
const (
CensysSourceString string = "Censys"
)
func CensysQuery(domain, sub string, l *log.Logger) []string {
var unique []string
if domain != sub {
return unique
}
re := utils.SubdomainRegex(domain)
url := censysURL(domain)
page, err := utils.GetWebPage(url, nil)
if err != nil {
l.Printf("Censys error: %s: %v", url, err)
return unique
}
for _, sd := range re.FindAllString(page, -1) {
if u := utils.NewUniqueElements(unique, sd); len(u) > 0 {
unique = append(unique, u...)
}
}
return unique
}
func censysURL(domain string) string {
format := "https://www.censys.io/domain/%s/table"
return fmt.Sprintf(format, domain)
}