/
certdb.go
69 lines (58 loc) · 1.69 KB
/
certdb.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
// 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 (
"log"
"regexp"
"strings"
"time"
"github.com/caffix/amass/amass/internal/utils"
)
const (
CertDBSourceString string = "CertDB"
)
func CertDBQuery(domain, sub string, l *log.Logger) []string {
var unique []string
if domain != sub {
return unique
}
// Pull the page that lists all certs for this domain
url := "https://certdb.com/domain/" + domain
page, err := utils.GetWebPage(url, nil)
if err != nil {
l.Printf("CertDB error: %s: %v", url, err)
return unique
}
// Get the subdomain name the cert was issued to, and
// the Subject Alternative Name list from each cert
for _, rel := range certdbGetSubmatches(page) {
// Do not go too fast
time.Sleep(50 * time.Millisecond)
// Pull the certificate web page
url = "https://certdb.com" + rel
cert, err := utils.GetWebPage(url, nil)
if err != nil {
l.Printf("CertDB error: %s: %v", url, err)
continue
}
// Get all names off the certificate
unique = utils.UniqueAppend(unique, certdbGetMatches(cert, domain)...)
}
return unique
}
func certdbGetMatches(content, domain string) []string {
var results []string
re := utils.SubdomainRegex(domain)
for _, s := range re.FindAllString(content, -1) {
results = append(results, s)
}
return results
}
func certdbGetSubmatches(content string) []string {
var results []string
re := regexp.MustCompile("<a href=\"(/ssl-cert/[a-zA-Z0-9]*)\" class=\"see-more-link\">")
for _, subs := range re.FindAllStringSubmatch(content, -1) {
results = append(results, strings.TrimSpace(subs[1]))
}
return results
}