-
Notifications
You must be signed in to change notification settings - Fork 3
/
crt_v4_dev.go
96 lines (84 loc) · 2.25 KB
/
crt_v4_dev.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
// Author: Eduardo Barbosa (@_anakein)
// Date: 07/06/2021
// anakein@protonmail.ch
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
)
var banner = `
_
___ _ __| |_ __ _ ___
/ __| '__| __| / _ |/ _ \
| (__| | | |_ | (_| | (_) |
\___ |_| \__(_)__, |\___/
|___/
[+] by @anakein
[+] https://github.com/an4kein
[-] Usage: crt.go <target>
`
type Crtsr struct {
CommonName string `json:"common_name"`
NameValue string `json:"name_value"`
}
func GetJsonFromCrt(domain string) ([]string, error) {
resp, err := http.Get(fmt.Sprintf("https://crt.sh/?q=%s&output=json", domain))
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
sb := []byte(body)
var subdomains []Crtsr
err = json.Unmarshal(sb, &subdomains)
if err != nil {
fmt.Println("error:", err)
}
output := make([]string, 0)
for _, subdomains := range subdomains {
output = append(output, subdomains.CommonName)
output = append(output, subdomains.NameValue)
}
return output, nil
}
func removeDuplicateValues(strSlice []string) []string {
// https://www.geeksforgeeks.org/how-to-remove-duplicate-values-from-slice-in-golang/
keys := make(map[string]bool)
list := []string{}
// If the key(values of the slice) is not equal
// to the already present value in new slice (list)
// then we append it. else we jump on another element.
for _, entry := range strSlice {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}
func main() {
fmt.Println(banner)
if os.Args != nil && len(os.Args) > 1 {
domain := os.Args[1]
if domain != "" {
fmt.Println("+---------------------=[Gathering Certificate Subdomains]=------------------------+")
subdom, err := GetJsonFromCrt(domain)
if err != nil {
fmt.Println("error: ", err)
}
removeDuplicateValuesSlice := removeDuplicateValues(subdom)
// Printing the filtered slice
// without duplicates
for _, uniquesubdomain := range removeDuplicateValuesSlice {
fmt.Println(uniquesubdomain)
}
fmt.Println("+--------------------------------=[Done!]=----------------------------------------+")
}
}
}