-
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.
- Loading branch information
1 parent
5eee087
commit 3822412
Showing
2 changed files
with
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ximcx | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
jsoniter "github.com/json-iterator/go" | ||
"github.com/projectdiscovery/subfinder/pkg/subscraping" | ||
) | ||
|
||
// Source is the passive scraping agent | ||
type Source struct{} | ||
|
||
type domain struct { | ||
Domain string `json:"domain"` | ||
} | ||
|
||
type ximcxResponse struct { | ||
Code int64 `json:"code"` | ||
Message string `json:"message"` | ||
Data []domain `json:"data"` | ||
} | ||
|
||
// 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() { | ||
defer close(results) | ||
|
||
resp, err := session.SimpleGet(ctx, fmt.Sprintf("http://sbd.ximcx.cn/DomainServlet?domain=%s", domain)) | ||
if err != nil { | ||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} | ||
session.DiscardHTTPResponse(resp) | ||
return | ||
} | ||
|
||
var response ximcxResponse | ||
err = jsoniter.NewDecoder(resp.Body).Decode(&response) | ||
if err != nil { | ||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} | ||
resp.Body.Close() | ||
return | ||
} | ||
resp.Body.Close() | ||
|
||
if response.Code > 0 { | ||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf("%d, %s", response.Code, response.Message)} | ||
return | ||
} | ||
|
||
for _, result := range response.Data { | ||
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: result.Domain} | ||
} | ||
}() | ||
|
||
return results | ||
} | ||
|
||
// Name returns the name of the source | ||
func (s *Source) Name() string { | ||
return "ximcx" | ||
} |