这是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
62 changes: 43 additions & 19 deletions v2/pkg/subscraping/sources/rapiddns/rapiddns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package rapiddns

import (
"context"
"fmt"
"io"
"regexp"
"strconv"
"time"

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

var pagePattern = regexp.MustCompile(`class="page-link ">(\d+)</a></li>`)

// Source is the passive scraping agent
type Source struct {
timeTaken time.Duration
Expand All @@ -28,28 +33,47 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
close(results)
}(time.Now())

resp, err := session.SimpleGet(ctx, "https://rapiddns.io/subdomain/"+domain+"?full=1")
if err != nil {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
s.errors++
session.DiscardHTTPResponse(resp)
return
}
page := 1
maxPages := 1
for {
resp, err := session.SimpleGet(ctx, fmt.Sprintf("https://rapiddns.io/subdomain/%s?page=%d", domain, page))
if err != nil {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
s.errors++
session.DiscardHTTPResponse(resp)
return
}

body, err := io.ReadAll(resp.Body)
if err != nil {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
s.errors++
resp.Body.Close()
return
}

body, err := io.ReadAll(resp.Body)
if err != nil {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
s.errors++
resp.Body.Close()
return
}

resp.Body.Close()

src := string(body)
for _, subdomain := range session.Extractor.Extract(src) {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: subdomain}
s.results++
src := string(body)
for _, subdomain := range session.Extractor.Extract(src) {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: subdomain}
s.results++
}

if maxPages == 1 {
matches := pagePattern.FindAllStringSubmatch(src, -1)
if len(matches) > 0 {
lastMatch := matches[len(matches)-1]
if len(lastMatch) > 1 {
maxPages, _ = strconv.Atoi(lastMatch[1])
}
}
}

if page >= maxPages {
break
}
page++
}
}()

Expand Down
58 changes: 34 additions & 24 deletions v2/pkg/subscraping/sources/shodan/shodan.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type dnsdbLookupResponse struct {
Subdomains []string `json:"subdomains"`
Result int `json:"result"`
Error string `json:"error"`
More bool `json:"more"`
}

// Run function returns all subdomains found with the service
Expand All @@ -45,36 +46,45 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
return
}

searchURL := fmt.Sprintf("https://api.shodan.io/dns/domain/%s?key=%s", domain, randomApiKey)
resp, err := session.SimpleGet(ctx, searchURL)
if err != nil {
session.DiscardHTTPResponse(resp)
return
}
page := 1
for {

defer resp.Body.Close()
searchURL := fmt.Sprintf("https://api.shodan.io/dns/domain/%s?key=%s&page=%d", domain, randomApiKey, page)
resp, err := session.SimpleGet(ctx, searchURL)
if err != nil {
session.DiscardHTTPResponse(resp)
return
}

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

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

if response.Error != "" {
results <- subscraping.Result{
Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf("%v", response.Error),
}
s.errors++
return
}

for _, data := range response.Subdomains {
results <- subscraping.Result{
Source: s.Name(), Type: subscraping.Subdomain, Value: fmt.Sprintf("%s.%s", data, domain),
}
s.results++
}
s.errors++
return
}

for _, data := range response.Subdomains {
results <- subscraping.Result{
Source: s.Name(), Type: subscraping.Subdomain, Value: fmt.Sprintf("%s.%s", data, domain),
if !response.More {
break
}
s.results++
page++
}
}()

Expand Down