这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions v2/pkg/passive/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/waybackarchive"
"github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/whoisxmlapi"
"github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/zoomeyeapi"
"github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/digitalyama"
mapsutil "github.com/projectdiscovery/utils/maps"
)

Expand Down Expand Up @@ -94,6 +95,7 @@ var AllSources = [...]subscraping.Source{
// &reconcloud.Source{}, // failing due to cloudflare bot protection
&builtwith.Source{},
&hudsonrock.Source{},
&digitalyama.Source{},
}

var sourceWarnings = mapsutil.NewSyncLockMap[string, string](
Expand Down
2 changes: 2 additions & 0 deletions v2/pkg/passive/sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var (
// "reconcloud",
"builtwith",
"hudsonrock",
"digitalyama",
}

expectedDefaultSources = []string{
Expand Down Expand Up @@ -89,6 +90,7 @@ var (
// "threatminer",
// "reconcloud",
"builtwith",
"digitalyama",
}

expectedDefaultRecursiveSources = []string{
Expand Down
128 changes: 128 additions & 0 deletions v2/pkg/subscraping/sources/digitalyama/digitalyama.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package digitalyama

import (
"context"
"fmt"
"time"

jsoniter "github.com/json-iterator/go"

"github.com/projectdiscovery/subfinder/v2/pkg/subscraping"
)

// Source is the passive scraping agent
type Source struct {
apiKeys []string
timeTaken time.Duration
errors int
results int
skipped bool
}

type digitalYamaResponse struct {
Query string `json:"query"`
Count int `json:"count"`
Subdomains []string `json:"subdomains"`
UsageSummary struct {
QueryCost float64 `json:"query_cost"`
CreditsRemaining float64 `json:"credits_remaining"`
} `json:"usage_summary"`
}

// 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)
s.errors = 0
s.results = 0

go func() {
defer func(startTime time.Time) {
s.timeTaken = time.Since(startTime)
close(results)
}(time.Now())

randomApiKey := subscraping.PickRandom(s.apiKeys, s.Name())
if randomApiKey == "" {
s.skipped = true
return
}

searchURL := fmt.Sprintf("https://api.digitalyama.com/subdomain_finder?domain=%s", domain)
resp, err := session.Get(ctx, searchURL, "", map[string]string{"x-api-key": randomApiKey})
if err != nil {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
s.errors++
return
}
defer resp.Body.Close()

if resp.StatusCode != 200 {
var errResponse struct {
Detail []struct {
Loc []string `json:"loc"`
Msg string `json:"msg"`
Type string `json:"type"`
} `json:"detail"`
}
err = jsoniter.NewDecoder(resp.Body).Decode(&errResponse)
if err != nil {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf("unexpected status code %d", resp.StatusCode)}
s.errors++
return
}
if len(errResponse.Detail) > 0 {
errMsg := errResponse.Detail[0].Msg
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf("%s (code %d)", errMsg, resp.StatusCode)}
} else {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf("unexpected status code %d", resp.StatusCode)}
}
s.errors++
return
}

var response digitalYamaResponse
err = jsoniter.NewDecoder(resp.Body).Decode(&response)
if err != nil {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
s.errors++
return
}

for _, subdomain := range response.Subdomains {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: subdomain}
s.results++
}
}()

return results
}

// Name returns the name of the source
func (s *Source) Name() string {
return "digitalyama"
}

func (s *Source) IsDefault() bool {
return true
}

func (s *Source) HasRecursiveSupport() bool {
return false
}

func (s *Source) NeedsKey() bool {
return true
}

func (s *Source) AddApiKeys(keys []string) {
s.apiKeys = keys
}

func (s *Source) Statistics() subscraping.Statistics {
return subscraping.Statistics{
Errors: s.errors,
Results: s.results,
TimeTaken: s.timeTaken,
Skipped: s.skipped,
}
}
Loading