forked from owasp-amass/amass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bing.go
66 lines (54 loc) · 1.34 KB
/
bing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2017 Jeff Foley. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package sources
import (
"fmt"
"net/url"
"strconv"
"time"
"github.com/OWASP/Amass/amass/internal/utils"
)
type Bing struct {
BaseDataSource
quantity int
limit int
}
func NewBing() DataSource {
b := &Bing{
quantity: 20,
limit: 200,
}
b.BaseDataSource = *NewBaseDataSource(SCRAPE, "Bing Scrape")
return b
}
func (b *Bing) Query(domain, sub string) []string {
var unique []string
if domain != sub {
return unique
}
re := utils.SubdomainRegex(domain)
num := b.limit / b.quantity
for i := 0; i < num; i++ {
u := b.urlByPageNum(domain, i)
page, err := utils.GetWebPage(u, nil)
if err != nil {
b.log(fmt.Sprintf("%s: %v", u, err))
break
}
for _, sd := range re.FindAllString(page, -1) {
if u := utils.NewUniqueElements(unique, sd); len(u) > 0 {
unique = append(unique, u...)
}
}
time.Sleep(1 * time.Second)
}
return unique
}
func (b *Bing) urlByPageNum(domain string, page int) string {
count := strconv.Itoa(b.quantity)
first := strconv.Itoa((page * b.quantity) + 1)
u, _ := url.Parse("http://www.bing.com/search")
u.RawQuery = url.Values{"q": {"domain:" + domain},
"count": {count}, "first": {first}, "FORM": {"PORE"}}.Encode()
return u.String()
}