Codebase list subfinder / 68bece6
Merge pull request #314 from vzamanillo/threatbook-source Implemented ThreatBook source bauthard authored 3 years ago GitHub committed 3 years ago
4 changed file(s) with 88 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
2828 "github.com/projectdiscovery/subfinder/pkg/subscraping/sources/sitedossier"
2929 "github.com/projectdiscovery/subfinder/pkg/subscraping/sources/spyse"
3030 "github.com/projectdiscovery/subfinder/pkg/subscraping/sources/sublist3r"
31 "github.com/projectdiscovery/subfinder/pkg/subscraping/sources/threatbook"
3132 "github.com/projectdiscovery/subfinder/pkg/subscraping/sources/threatcrowd"
3233 "github.com/projectdiscovery/subfinder/pkg/subscraping/sources/threatminer"
3334 "github.com/projectdiscovery/subfinder/pkg/subscraping/sources/virustotal"
5859 "shodan",
5960 "spyse",
6061 "sublist3r",
62 "threatbook",
6163 "threatcrowd",
6264 "threatminer",
6365 "virustotal",
109111 "sitedossier",
110112 "spyse",
111113 "sublist3r",
114 "threatbook",
112115 "threatcrowd",
113116 "threatminer",
114117 "virustotal",
193196 a.sources[source] = &spyse.Source{}
194197 case "sublist3r":
195198 a.sources[source] = &sublist3r.Source{}
199 case "threatbook":
200 a.sources[source] = &threatbook.Source{}
196201 case "threatcrowd":
197202 a.sources[source] = &threatcrowd.Source{}
198203 case "threatminer":
4040 SecurityTrails []string `yaml:"securitytrails"`
4141 Shodan []string `yaml:"shodan"`
4242 Spyse []string `yaml:"spyse"`
43 ThreatBook []string `yaml:"threatbook"`
4344 URLScan []string `yaml:"urlscan"`
4445 Virustotal []string `yaml:"virustotal"`
4546 ZoomEye []string `yaml:"zoomeye"`
170171 if len(c.Spyse) > 0 {
171172 keys.Spyse = c.Spyse[rand.Intn(len(c.Spyse))]
172173 }
174 if len(c.ThreatBook) > 0 {
175 keys.ThreatBook = c.ThreatBook[rand.Intn(len(c.ThreatBook))]
176 }
173177 if len(c.URLScan) > 0 {
174178 keys.URLScan = c.URLScan[rand.Intn(len(c.URLScan))]
175179 }
0 package threatbook
1
2 import (
3 "context"
4 "fmt"
5 "strconv"
6
7 jsoniter "github.com/json-iterator/go"
8 "github.com/projectdiscovery/subfinder/pkg/subscraping"
9 )
10
11 type threatBookResponse struct {
12 ResponseCode int64 `json:"response_code"`
13 VerboseMsg string `json:"verbose_msg"`
14 Data struct {
15 Domain string `json:"domain"`
16 SubDomains struct {
17 Total string `json:"total"`
18 Data []string `json:"data"`
19 } `json:"sub_domains"`
20 } `json:"data"`
21 }
22
23 // Source is the passive scraping agent
24 type Source struct{}
25
26 // Run function returns all subdomains found with the service
27 func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Session) <-chan subscraping.Result {
28 results := make(chan subscraping.Result)
29
30 go func() {
31 defer close(results)
32
33 if session.Keys.ThreatBook == "" {
34 return
35 }
36
37 resp, err := session.SimpleGet(ctx, fmt.Sprintf("https://api.threatbook.cn/v3/domain/sub_domains?apikey=%s&resource=%s", session.Keys.ThreatBook, domain))
38 if err != nil && resp == nil {
39 results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
40 session.DiscardHTTPResponse(resp)
41 return
42 }
43
44 var response threatBookResponse
45 err = jsoniter.NewDecoder(resp.Body).Decode(&response)
46 if err != nil {
47 results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
48 resp.Body.Close()
49 return
50 }
51 resp.Body.Close()
52
53 if response.ResponseCode != 0 {
54 results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf("code %d, %s", response.ResponseCode, response.VerboseMsg)}
55 return
56 }
57
58 total, err := strconv.ParseInt(response.Data.SubDomains.Total, 10, 64)
59 if err != nil {
60 results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
61 return
62 }
63
64 if total > 0 {
65 for _, subdomain := range response.Data.SubDomains.Data {
66 results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: subdomain}
67 }
68 }
69 }()
70
71 return results
72 }
73
74 // Name returns the name of the source
75 func (s *Source) Name() string {
76 return "threatbook"
77 }
4949 Securitytrails string `json:"securitytrails"`
5050 Shodan string `json:"shodan"`
5151 Spyse string `json:"spyse"`
52 ThreatBook string `json:"threatbook"`
5253 URLScan string `json:"urlscan"`
5354 Virustotal string `json:"virustotal"`
5455 ZoomEyeUsername string `json:"zoomeye_username"`