-
Notifications
You must be signed in to change notification settings - Fork 1.5k
RedHunt Labs Attack Surface Recon API Integration #978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
236b037
added RedHunt Labs integration
4ab5686
improved error handling
8f60f7f
removed binary and updated README
22fccc2
added the suggested fixes
e36c4a5
added suggested fixes
d32761a
added fixes
d934672
added fixes
c8d0e5e
changed the error logging statements
d3d1509
fixed README
9a0d24e
resolved merge conflict issue
bb2de47
Merge branch 'dev' into main
umair-rhl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,137 @@ | ||
| // Package redhuntlabs logic | ||
| package redhuntlabs | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
| "time" | ||
|
|
||
| jsoniter "github.com/json-iterator/go" | ||
|
|
||
| "github.com/projectdiscovery/subfinder/v2/pkg/subscraping" | ||
| ) | ||
|
|
||
| type Response struct { | ||
| Subdomains []string `json:"subdomains"` | ||
| Metadata ResponseMetadata `json:"metadata"` | ||
| } | ||
|
|
||
| type ResponseMetadata struct { | ||
| ResultCount int `json:"result_count"` | ||
| PageSize int `json:"page_size"` | ||
| PageNumber int `json:"page_number"` | ||
| } | ||
|
|
||
| type Source struct { | ||
| apiKeys []string | ||
| timeTaken time.Duration | ||
| errors int | ||
| results int | ||
| skipped bool | ||
| } | ||
|
|
||
| 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 | ||
| pageSize := 1000 | ||
| go func() { | ||
| defer func(startTime time.Time) { | ||
| s.timeTaken = time.Since(startTime) | ||
| close(results) | ||
| }(time.Now()) | ||
|
|
||
| randomCred := subscraping.PickRandom(s.apiKeys, s.Name()) | ||
| if randomCred == "" || !strings.Contains(randomCred, ":") { | ||
| s.skipped = true | ||
| return | ||
| } | ||
|
|
||
| creds := strings.Split(randomCred, ":") | ||
| baseUrl := creds[0] + ":" + creds[1] | ||
| requestHeaders := map[string]string{"X-BLOBR-KEY": creds[2], "User-Agent": "subfinder"} | ||
| getUrl := fmt.Sprintf("%s?domain=%s&page=1&page_size=%d", baseUrl, domain, pageSize) | ||
| resp, err := session.Get(ctx, getUrl, "", requestHeaders) | ||
| if err != nil { | ||
dogancanbakir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf("encountered error: %v; note: if you get a 'limit has been reached' error, head over to https://devportal.redhuntlabs.com", err)} | ||
| session.DiscardHTTPResponse(resp) | ||
| s.errors++ | ||
| return | ||
| } | ||
| var response Response | ||
| err = jsoniter.NewDecoder(resp.Body).Decode(&response) | ||
| if err != nil { | ||
| results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} | ||
| resp.Body.Close() | ||
| s.errors++ | ||
| return | ||
| } | ||
|
|
||
| resp.Body.Close() | ||
| if response.Metadata.ResultCount > pageSize { | ||
| totalPages := (response.Metadata.ResultCount + pageSize - 1) / pageSize | ||
| for page := 1; page <= totalPages; page++ { | ||
| getUrl = fmt.Sprintf("%s?domain=%s&page=%d&page_size=%d", baseUrl, domain, page, pageSize) | ||
| resp, err := session.Get(ctx, getUrl, "", requestHeaders) | ||
| if err != nil { | ||
| results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf("encountered error: %v; note: if you get a 'limit has been reached' error, head over to https://devportal.redhuntlabs.com", err)} | ||
| session.DiscardHTTPResponse(resp) | ||
| s.errors++ | ||
| return | ||
| } | ||
|
|
||
| err = jsoniter.NewDecoder(resp.Body).Decode(&response) | ||
| if err != nil { | ||
| results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} | ||
| resp.Body.Close() | ||
| s.errors++ | ||
| continue | ||
| } | ||
|
|
||
| resp.Body.Close() | ||
|
|
||
| for _, subdomain := range response.Subdomains { | ||
| results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: subdomain} | ||
| s.results++ | ||
| } | ||
| } | ||
| } else { | ||
| for _, subdomain := range response.Subdomains { | ||
| results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: subdomain} | ||
| s.results++ | ||
| } | ||
| } | ||
|
|
||
| }() | ||
| return results | ||
| } | ||
|
|
||
| func (s *Source) Name() string { | ||
| return "redhuntlabs" | ||
| } | ||
|
|
||
| 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, | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.