/
threatcrowd.go
44 lines (34 loc) · 955 Bytes
/
threatcrowd.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 (
ThreatCrowdSourceString string = "ThreatCrowd"
)
func ThreatCrowdQuery(domain, sub string, l *log.Logger) []string {
var unique []string
if domain != sub {
return unique
}
re := utils.SubdomainRegex(domain)
url := threatCrowdURL(domain)
page, err := utils.GetWebPage(url, nil)
if err != nil {
l.Printf("ThreatCrowd 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 threatCrowdURL(domain string) string {
format := "https://www.threatcrowd.org/searchApi/v2/domain/report/?domain=%s"
return fmt.Sprintf(format, domain)
}