Skip to content

Commit

Permalink
Merge pull request #477 from M09Ic/master
Browse files Browse the repository at this point in the history
Add source zoomeye subdomain api
  • Loading branch information
ehsandeep authored Dec 22, 2021
2 parents ae32c0d + 997e7a1 commit 37645f4
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
4 changes: 4 additions & 0 deletions v2/pkg/passive/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/virustotal"
"github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/waybackarchive"
"github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/zoomeye"
"github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/zoomeyeapi"
"github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/fullhunt"
)

Expand Down Expand Up @@ -119,6 +120,7 @@ var DefaultAllSources = []string{
"virustotal",
"waybackarchive",
"zoomeye",
"zoomeyeapi",
"fofa",
"fullhunt",
}
Expand Down Expand Up @@ -213,6 +215,8 @@ func (a *Agent) addSources(sources []string) {
a.sources[source] = &waybackarchive.Source{}
case "zoomeye":
a.sources[source] = &zoomeye.Source{}
case "zoomeyeapi":
a.sources[source] = &zoomeyeapi.Source{}
case "fofa":
a.sources[source] = &fofa.Source{}
case "fullhunt":
Expand Down
4 changes: 4 additions & 0 deletions v2/pkg/runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type ConfigFile struct {
URLScan []string `yaml:"urlscan"`
Virustotal []string `yaml:"virustotal"`
ZoomEye []string `yaml:"zoomeye"`
ZoomEyeApi []string `yaml:"zoomeyeapi"`
Fofa []string `yaml:"fofa"`
FullHunt []string `json:"fullhunt"`
// Version indicates the version of subfinder installed.
Expand Down Expand Up @@ -204,6 +205,9 @@ func (c *ConfigFile) GetKeys() subscraping.Keys {
keys.ZoomEyePassword = parts[1]
}
}
if len(c.ZoomEyeApi) > 0 {
keys.ZoomEyeKey = c.ZoomEyeApi[rand.Intn(len(c.ZoomEyeApi))]
}
if len(c.Fofa) > 0 {
fofaKeys := c.Fofa[rand.Intn(len(c.Fofa))]
parts := strings.Split(fofaKeys, ":")
Expand Down
1 change: 0 additions & 1 deletion v2/pkg/subscraping/sources/zoomeye/zoomeye.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: domain}
}
}
currentPage++
}
}()

Expand Down
76 changes: 76 additions & 0 deletions v2/pkg/subscraping/sources/zoomeyeapi/zoomeyeapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package zoomeyeapi

import (
"context"
"encoding/json"
"fmt"
"net/http"

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

// search results
type zoomeyeResults struct {
Status int `json:"status"`
Total int `json:"total"`
List []struct {
Name string `json:"name"`
Ip []string `json:"ip"`
} `json:"list"`
}

// 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() {
defer close(results)

if session.Keys.ZoomEyeKey == "" {
return
}

headers := map[string]string{
"API-KEY": session.Keys.ZoomEyeKey,
"Accept": "application/json",
"Content-Type": "application/json",
}
var pages = 1
for currentPage := 1; currentPage <= pages; currentPage++ {
api := fmt.Sprintf("https://api.zoomeye.org/domain/search?q=%s&type=1&s=1000&page=%d", domain, currentPage)
resp, err := session.Get(ctx, api, "", headers)
isForbidden := resp != nil && resp.StatusCode == http.StatusForbidden
if err != nil {
if !isForbidden {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
session.DiscardHTTPResponse(resp)
}
return
}

var res zoomeyeResults
err = json.NewDecoder(resp.Body).Decode(&res)

if err != nil {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
_ = resp.Body.Close()
return
}
_ = resp.Body.Close()
pages = int(res.Total/1000) + 1
for _, r := range res.List {
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: r.Name}
}
}
}()

return results
}

// Name returns the name of the source
func (s *Source) Name() string {
return "zoomeyeapi"
}
1 change: 1 addition & 0 deletions v2/pkg/subscraping/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Keys struct {
Virustotal string `json:"virustotal"`
ZoomEyeUsername string `json:"zoomeye_username"`
ZoomEyePassword string `json:"zoomeye_password"`
ZoomEyeKey string `json:"zoomeye_key"`
FofaUsername string `json:"fofa_username"`
FofaSecret string `json:"fofa_secret"`
FullHunt string `json:"fullhunt"`
Expand Down

0 comments on commit 37645f4

Please sign in to comment.