-
Notifications
You must be signed in to change notification settings - Fork 1.5k
add RSECloud #1604
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
add RSECloud #1604
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| package rsecloud | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| jsoniter "github.com/json-iterator/go" | ||
|
|
||
| "github.com/projectdiscovery/subfinder/v2/pkg/subscraping" | ||
| ) | ||
|
|
||
| type response struct { | ||
| Count int `json:"count"` | ||
| Data []string `json:"data"` | ||
| Page int `json:"page"` | ||
| PageSize int `json:"pagesize"` | ||
| TotalPages int `json:"total_pages"` | ||
| } | ||
|
|
||
| // Source is the passive scraping agent | ||
| type Source struct { | ||
| apiKeys []string | ||
| timeTaken time.Duration | ||
| errors int | ||
| results int | ||
| skipped bool | ||
| } | ||
|
|
||
| // 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 | ||
| } | ||
|
|
||
| headers := map[string]string{"Content-Type": "application/json", "X-API-Key": randomApiKey} | ||
|
|
||
| fetchSubdomains := func(endpoint string) { | ||
| page := 1 | ||
| for { | ||
| resp, err := session.Get(ctx, fmt.Sprintf("https://api.rsecloud.com/api/v2/subdomains/%s/%s?page=%d", endpoint, domain, page), "", headers) | ||
| if err != nil { | ||
| results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} | ||
| s.errors++ | ||
| session.DiscardHTTPResponse(resp) | ||
| return | ||
| } | ||
|
|
||
| var rseCloudResponse response | ||
| err = jsoniter.NewDecoder(resp.Body).Decode(&rseCloudResponse) | ||
| session.DiscardHTTPResponse(resp) | ||
| if err != nil { | ||
| results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} | ||
| s.errors++ | ||
| return | ||
| } | ||
|
|
||
| for _, subdomain := range rseCloudResponse.Data { | ||
| results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: subdomain} | ||
| s.results++ | ||
| } | ||
|
|
||
| if page >= rseCloudResponse.TotalPages { | ||
| break | ||
| } | ||
| page++ | ||
| } | ||
| } | ||
|
|
||
| fetchSubdomains("active") | ||
| fetchSubdomains("passive") | ||
| }() | ||
|
|
||
| return results | ||
| } | ||
|
|
||
| // Name returns the name of the source | ||
| func (s *Source) Name() string { | ||
| return "rsecloud" | ||
| } | ||
|
|
||
| func (s *Source) IsDefault() bool { | ||
| return true | ||
| } | ||
|
|
||
| func (s *Source) HasRecursiveSupport() bool { | ||
| return true | ||
| } | ||
|
|
||
| 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, | ||
| } | ||
| } | ||
Oops, something went wrong.
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.