forked from projectdiscovery/cdncheck
-
Notifications
You must be signed in to change notification settings - Fork 3
/
other.go
61 lines (55 loc) · 1.69 KB
/
other.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
package cdncheck
import (
"strings"
"github.com/pkg/errors"
"github.com/weppos/publicsuffix-go/publicsuffix"
)
var suffixToSource map[string]string
// cdnWappalyzerTechnologies contains a map of wappalyzer technologies to cdns
var cdnWappalyzerTechnologies = map[string]string{
"imperva": "imperva",
"incapsula": "incapsula",
"cloudflare": "cloudflare",
"cloudfront": "amazon",
"akamai": "akamai",
}
// CheckFQDN checks if fqdns are known cloud ones
func (c *Client) CheckSuffix(fqdns ...string) (isCDN bool, provider string, itemType string, err error) {
c.Once.Do(func() {
suffixToSource = make(map[string]string)
for source, suffixes := range generatedData.Common {
for _, suffix := range suffixes {
suffixToSource[suffix] = source
}
}
})
for _, fqdn := range fqdns {
parsed, err := publicsuffix.Parse(fqdn)
if err != nil {
return false, "", "", errors.Wrap(err, "could not parse fqdn")
}
if discovered, ok := suffixToSource[parsed.TLD]; ok {
return true, discovered, "waf", nil
}
domain := parsed.SLD + "." + parsed.TLD
if discovered, ok := suffixToSource[domain]; ok {
return true, discovered, "waf", nil
}
}
return false, "", "", nil
}
// CheckWappalyzer checks if the wappalyzer detection are a part of CDN
func (c *Client) CheckWappalyzer(data map[string]struct{}) (isCDN bool, provider string, err error) {
for technology := range data {
if strings.Contains(technology, ":") {
if parts := strings.SplitN(technology, ":", 2); len(parts) == 2 {
technology = parts[0]
}
}
technology = strings.ToLower(technology)
if discovered, ok := cdnWappalyzerTechnologies[technology]; ok {
return true, discovered, nil
}
}
return false, "", nil
}