Added working censys source
parent
1235003557
commit
8c55e4201a
|
@ -1,15 +1,18 @@
|
||||||
package shodan
|
package censys
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/subfinder/subfinder/pkg/subscraping"
|
"github.com/subfinder/subfinder/pkg/subscraping"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const maxCensysPages = 10
|
||||||
|
|
||||||
type resultsq struct {
|
type resultsq struct {
|
||||||
Data []string `json:"parsed.extensions.subject_alt_name.dns_names"`
|
Data []string `json:"parsed.extensions.subject_alt_name.dns_names"`
|
||||||
Data1 []string `json:"parsed.names"`
|
Data1 []string `json:"parsed.names"`
|
||||||
|
@ -30,20 +33,34 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
|
||||||
results := make(chan subscraping.Result)
|
results := make(chan subscraping.Result)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if session.Keys.Censys == "" {
|
if session.Keys.CensysToken == "" || session.Keys.CensysSecret == "" {
|
||||||
close(results)
|
close(results)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var response response
|
||||||
|
|
||||||
for currentPage := 0; currentPage <= 10; currentPage++ {
|
currentPage := 1
|
||||||
resp, err := session.NormalGet("https://api.shodan.io/shodan/host/search?query=hostname:" + domain + "&page=" + strconv.Itoa(currentPage) + "&key=" + session.Keys.Shodan)
|
for {
|
||||||
|
var request = []byte(`{"query":"` + domain + `", "page":` + strconv.Itoa(currentPage) + `, "fields":["parsed.names","parsed.extensions.subject_alt_name.dns_names"], "flatten":true}`)
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", "https://www.censys.io/api/v1/search/certificates", bytes.NewReader(request))
|
||||||
|
if err != nil {
|
||||||
|
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
|
||||||
|
close(results)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("%s %s\n", session.Keys.CensysToken, session.Keys.CensysSecret)
|
||||||
|
req.SetBasicAuth(session.Keys.CensysToken, session.Keys.CensysSecret)
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
resp, err := session.Client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
|
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
|
||||||
close(results)
|
close(results)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var response shodanResult
|
|
||||||
err = jsoniter.NewDecoder(resp.Body).Decode(&response)
|
err = jsoniter.NewDecoder(resp.Body).Decode(&response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
|
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
|
||||||
|
@ -52,22 +69,21 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
|
||||||
}
|
}
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
||||||
fmt.Printf("%v\n")
|
// Exit the censys enumeration if max pages is reached
|
||||||
if response.Error != "" {
|
if currentPage >= response.Metadata.Pages || currentPage >= maxCensysPages {
|
||||||
close(results)
|
break
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, block := range response.Matches {
|
for _, res := range response.Results {
|
||||||
for _, hostname := range block.Hostnames {
|
for _, part := range res.Data {
|
||||||
|
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: part}
|
||||||
if strings.Contains(hostname, "*.") {
|
}
|
||||||
hostname = strings.Split(hostname, "*.")[1]
|
for _, part := range res.Data1 {
|
||||||
}
|
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: part}
|
||||||
|
|
||||||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: hostname}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentPage++
|
||||||
}
|
}
|
||||||
close(results)
|
close(results)
|
||||||
}()
|
}()
|
||||||
|
@ -77,5 +93,5 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
|
||||||
|
|
||||||
// Name returns the name of the source
|
// Name returns the name of the source
|
||||||
func (s *Source) Name() string {
|
func (s *Source) Name() string {
|
||||||
return "shodan"
|
return "censys"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue