File: crtsh.go

package info (click to toggle)
assetfinder 0.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 124 kB
  • sloc: sh: 55; makefile: 4
file content (37 lines) | stat: -rw-r--r-- 624 bytes parent folder | download
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
package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

type CrtShResult struct {
	Name string `json:"name_value"`
}

func fetchCrtSh(domain string) ([]string, error) {
	var results []CrtShResult

	resp, err := http.Get(
		fmt.Sprintf("https://crt.sh/?q=%%25.%s&output=json", domain),
	)
	if err != nil {
		return []string{}, err
	}
	defer resp.Body.Close()

	output := make([]string, 0)

	body, _ := ioutil.ReadAll(resp.Body)

	if err := json.Unmarshal(body, &results); err != nil {
		return []string{}, err
	}

	for _, res := range results {
		output = append(output, res.Name)
	}
	return output, nil
}