Add AlienVault
parent
0ae69573fd
commit
3c2e7fd005
|
@ -10,6 +10,7 @@ resolvers:
|
|||
- 208.67.222.222
|
||||
- 208.67.220.220
|
||||
sources:
|
||||
- alienvault
|
||||
- archiveis
|
||||
- binaryedge
|
||||
- bufferover
|
||||
|
|
|
@ -2,6 +2,7 @@ package passive
|
|||
|
||||
import (
|
||||
"github.com/projectdiscovery/subfinder/pkg/subscraping"
|
||||
"github.com/projectdiscovery/subfinder/pkg/subscraping/sources/alienvault"
|
||||
"github.com/projectdiscovery/subfinder/pkg/subscraping/sources/archiveis"
|
||||
"github.com/projectdiscovery/subfinder/pkg/subscraping/sources/binaryedge"
|
||||
"github.com/projectdiscovery/subfinder/pkg/subscraping/sources/bufferover"
|
||||
|
@ -30,6 +31,7 @@ import (
|
|||
|
||||
// DefaultSources contains the list of sources used by default
|
||||
var DefaultSources = []string{
|
||||
"alienvault",
|
||||
"archiveis",
|
||||
"binaryedge",
|
||||
"bufferover",
|
||||
|
@ -78,6 +80,8 @@ func New(sources []string, exclusions []string) *Agent {
|
|||
func (a *Agent) addSources(sources []string) {
|
||||
for _, source := range sources {
|
||||
switch source {
|
||||
case "alienvault":
|
||||
a.sources[source] = &alienvault.Source{}
|
||||
case "archiveis":
|
||||
a.sources[source] = &archiveis.Source{}
|
||||
case "binaryedge":
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package alienvault
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/projectdiscovery/subfinder/pkg/subscraping"
|
||||
)
|
||||
|
||||
type alienvaultResponse struct {
|
||||
PassiveDNS []struct {
|
||||
Hostname string `json:"hostname"`
|
||||
} `json:"passive_dns"`
|
||||
}
|
||||
|
||||
// Source is the passive scraping agent
|
||||
type Source struct{}
|
||||
|
||||
// Run function returns all subdomains found with the service
|
||||
func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Session) <-chan subscraping.Result {
|
||||
results := make(chan subscraping.Result)
|
||||
|
||||
go func() {
|
||||
resp, err := session.NormalGetWithContext(ctx, fmt.Sprintf("https://otx.alienvault.com/api/v1/indicators/domain/%s/passive_dns", domain))
|
||||
if err != nil {
|
||||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
|
||||
close(results)
|
||||
return
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf("invalid status code received: %d", resp.StatusCode)}
|
||||
io.Copy(ioutil.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
close(results)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
otxResp := &alienvaultResponse{}
|
||||
// Get the response body and decode
|
||||
err = json.NewDecoder(resp.Body).Decode(&otxResp)
|
||||
if err != nil {
|
||||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
|
||||
resp.Body.Close()
|
||||
close(results)
|
||||
return
|
||||
}
|
||||
|
||||
for _, record := range otxResp.PassiveDNS {
|
||||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: record.Hostname}
|
||||
}
|
||||
close(results)
|
||||
}()
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
// Name returns the name of the source
|
||||
func (s *Source) Name() string {
|
||||
return "alienvault"
|
||||
}
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/projectdiscovery/subfinder/pkg/subscraping"
|
||||
)
|
||||
|
||||
type dnsDBResp struct {
|
||||
type dnsdbResponse struct {
|
||||
Name string `json:"rrname"`
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
|
|||
close(results)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
// Get the response body
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
for scanner.Scan() {
|
||||
|
@ -49,7 +50,7 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
|
|||
if line == "" {
|
||||
continue
|
||||
}
|
||||
out := &dnsDBResp{}
|
||||
out := &dnsdbResponse{}
|
||||
err := json.Unmarshal([]byte(line), out)
|
||||
if err != nil {
|
||||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
|
||||
|
@ -60,7 +61,6 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
|
|||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: strings.TrimSuffix(out.Name, ".")}
|
||||
out = nil
|
||||
}
|
||||
resp.Body.Close()
|
||||
close(results)
|
||||
}()
|
||||
return results
|
||||
|
|
|
@ -22,6 +22,7 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
|
|||
close(results)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
var subdomains []string
|
||||
// Get the response body and unmarshal
|
||||
err = json.NewDecoder(resp.Body).Decode(&subdomains)
|
||||
|
@ -31,7 +32,6 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
|
|||
close(results)
|
||||
return
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
for _, subdomain := range subdomains {
|
||||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: subdomain}
|
||||
|
|
Loading…
Reference in New Issue