forked from evilsocket/xray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrtsh.go
44 lines (36 loc) · 844 Bytes
/
crtsh.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
package xray
import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
"strings"
)
type CertSH struct {
}
func NewCertSH() *CertSH {
return &CertSH{}
}
func (me *CertSH) GetSubDomains(c *Context) []string {
url := fmt.Sprintf("https://crt.sh/?q=%%25.%s", c.Domain)
unique := make(map[string]bool)
if res, err := http.Get(url); err == nil {
defer res.Body.Close()
if raw_body, err := ioutil.ReadAll(res.Body); err == nil {
data := string(raw_body)
re := regexp.MustCompile(fmt.Sprintf(">([^<\\*%%]+)\\.%s<", regexp.QuoteMeta(c.Domain)))
if match := re.FindAllString(data, -1); match != nil {
for _, m := range match {
m = strings.Trim(m, "><")
sub := c.GetSubDomain(m)
unique[sub] = true
}
}
}
}
sub := make([]string, len(unique))
for k := range unique {
sub = append(sub, k)
}
return sub
}