From f041a48733e079a0c7f53ad7166a9cb403d47ee6 Mon Sep 17 00:00:00 2001 From: "Alex Munene (@enenumxela)" <62714471+enenumxela@users.noreply.github.com> Date: Sun, 25 Jun 2023 14:31:42 +0300 Subject: [PATCH] feat: Add censys source --- pkg/xsubfind3r/sources/censys/censys.go | 102 ++++++++++++++++++++++++ pkg/xsubfind3r/sources/configuration.go | 1 + pkg/xsubfind3r/xsubfind3r.go | 3 + 3 files changed, 106 insertions(+) create mode 100644 pkg/xsubfind3r/sources/censys/censys.go diff --git a/pkg/xsubfind3r/sources/censys/censys.go b/pkg/xsubfind3r/sources/censys/censys.go new file mode 100644 index 0000000..cfedea9 --- /dev/null +++ b/pkg/xsubfind3r/sources/censys/censys.go @@ -0,0 +1,102 @@ +package censys + +import ( + "encoding/json" + "fmt" + "strconv" + "strings" + + "github.com/hueristiq/xsubfind3r/pkg/xsubfind3r/httpclient" + "github.com/hueristiq/xsubfind3r/pkg/xsubfind3r/sources" + "github.com/valyala/fasthttp" +) + +type response struct { + Results []resultsq `json:"results"` + Metadata struct { + Pages int `json:"pages"` + } `json:"metadata"` +} + +type resultsq struct { + Data []string `json:"parsed.extensions.subject_alt_name.dns_names"` + Data1 []string `json:"parsed.names"` +} + +type Source struct{} + +const maxCensysPages = 10 + +func (source *Source) Run(config *sources.Configuration) (subdomains chan sources.Subdomain) { + subdomains = make(chan sources.Subdomain) + + go func() { + defer close(subdomains) + + var ( + key string + err error + res *fasthttp.Response + headers = map[string]string{ + "Content-Type": "application/json", + "Accept": "application/json", + } + ) + + key, err = sources.PickRandom(config.Keys.Censys) + if key == "" || err != nil { + return + } + + parts := strings.Split(key, ":") + username := parts[0] + password := parts[1] + + if username == "" || password == "" { + return + } + + currentPage := 1 + for { + var reqData = []byte(`{"query":"` + config.Domain + `", "page":` + strconv.Itoa(currentPage) + `, "fields":["parsed.names","parsed.extensions.subject_alt_name.dns_names"], "flatten":true}`) + + reqURL := fmt.Sprintf("https://%s:%s@search.censys.io/api/v1/search/certificates", username, password) + + res, err = httpclient.Request(fasthttp.MethodPost, reqURL, "", headers, reqData) + fmt.Println(res) + if err != nil { + return + } + + body := res.Body() + + var results response + + if err = json.Unmarshal(body, &results); err != nil { + return + } + + for _, i := range results.Results { + for _, part := range i.Data { + subdomains <- sources.Subdomain{Source: source.Name(), Value: part} + } + for _, part := range i.Data1 { + subdomains <- sources.Subdomain{Source: source.Name(), Value: part} + } + } + + // Exit the censys enumeration if max pages is reached + if currentPage >= results.Metadata.Pages || currentPage >= maxCensysPages { + break + } + + currentPage++ + } + }() + + return +} + +func (source *Source) Name() string { + return "censys" +} diff --git a/pkg/xsubfind3r/sources/configuration.go b/pkg/xsubfind3r/sources/configuration.go index 17e8ab6..74972b5 100644 --- a/pkg/xsubfind3r/sources/configuration.go +++ b/pkg/xsubfind3r/sources/configuration.go @@ -13,6 +13,7 @@ type Configuration struct { type Keys struct { Bevigil []string `yaml:"bevigil"` + Censys []string `yaml:"censys"` Chaos []string `yaml:"chaos"` GitHub []string `yaml:"github"` Intelx []string `yaml:"intelx"` diff --git a/pkg/xsubfind3r/xsubfind3r.go b/pkg/xsubfind3r/xsubfind3r.go index dc6410e..e2f514c 100644 --- a/pkg/xsubfind3r/xsubfind3r.go +++ b/pkg/xsubfind3r/xsubfind3r.go @@ -11,6 +11,7 @@ import ( "github.com/hueristiq/xsubfind3r/pkg/xsubfind3r/sources/bevigil" "github.com/hueristiq/xsubfind3r/pkg/xsubfind3r/sources/bufferover" "github.com/hueristiq/xsubfind3r/pkg/xsubfind3r/sources/cebaidu" + "github.com/hueristiq/xsubfind3r/pkg/xsubfind3r/sources/censys" "github.com/hueristiq/xsubfind3r/pkg/xsubfind3r/sources/certspotterv0" "github.com/hueristiq/xsubfind3r/pkg/xsubfind3r/sources/chaos" "github.com/hueristiq/xsubfind3r/pkg/xsubfind3r/sources/commoncrawl" @@ -69,6 +70,8 @@ func New(options *Options) (finder *Finder) { finder.Sources[source] = &bufferover.Source{} case "cebaidu": finder.Sources[source] = &cebaidu.Source{} + case "censys": + finder.Sources[source] = &censys.Source{} case "certspotterv0": finder.Sources[source] = &certspotterv0.Source{} case "chaos":