Skip to content

Commit

Permalink
feat: Add censys source
Browse files Browse the repository at this point in the history
  • Loading branch information
enenumxela committed Jun 25, 2023
1 parent f513331 commit f041a48
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
102 changes: 102 additions & 0 deletions pkg/xsubfind3r/sources/censys/censys.go
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions pkg/xsubfind3r/sources/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
3 changes: 3 additions & 0 deletions pkg/xsubfind3r/xsubfind3r.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit f041a48

Please sign in to comment.