-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from lc/lc/add-modules
Add 4 Sources: AlienVault OTX, DNSDB, Sublist3r, ZoomEye
- Loading branch information
Showing
8 changed files
with
370 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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 | ||
} | ||
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 | ||
} | ||
resp.Body.Close() | ||
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package dnsdb | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"strings" | ||
|
||
"github.com/projectdiscovery/subfinder/pkg/subscraping" | ||
) | ||
|
||
type dnsdbResponse struct { | ||
Name string `json:"rrname"` | ||
} | ||
|
||
// 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) | ||
headers := map[string]string{ | ||
"X-API-KEY": session.Keys.DNSDB, | ||
"Accept": "application/json", | ||
"Content-Type": "application/json", | ||
} | ||
go func() { | ||
resp, err := session.Get(ctx, fmt.Sprintf("https://api.dnsdb.info/lookup/rrset/name/*.%s?limit=1000000000000", domain), "", headers) | ||
if err != nil { | ||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} | ||
close(results) | ||
return | ||
} | ||
// Check status code | ||
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() | ||
// Get the response body | ||
scanner := bufio.NewScanner(resp.Body) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if line == "" { | ||
continue | ||
} | ||
out := &dnsdbResponse{} | ||
err := json.Unmarshal([]byte(line), out) | ||
if err != nil { | ||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} | ||
resp.Body.Close() | ||
close(results) | ||
return | ||
} | ||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: strings.TrimSuffix(out.Name, ".")} | ||
out = nil | ||
} | ||
close(results) | ||
}() | ||
return results | ||
} | ||
|
||
// Name returns the name of the source | ||
func (s *Source) Name() string { | ||
return "DNSDB" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package sublist3r | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/projectdiscovery/subfinder/pkg/subscraping" | ||
) | ||
|
||
// 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://api.sublist3r.com/search.php?domain=%s", domain)) | ||
if err != nil { | ||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} | ||
close(results) | ||
return | ||
} | ||
defer resp.Body.Close() | ||
var subdomains []string | ||
// Get the response body and unmarshal | ||
err = json.NewDecoder(resp.Body).Decode(&subdomains) | ||
if err != nil { | ||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} | ||
resp.Body.Close() | ||
close(results) | ||
return | ||
} | ||
|
||
for _, subdomain := range subdomains { | ||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: subdomain} | ||
} | ||
close(results) | ||
}() | ||
|
||
return results | ||
} | ||
|
||
// Name returns the name of the source | ||
func (s *Source) Name() string { | ||
return "sublist3r" | ||
} |
Oops, something went wrong.