/
google.go
73 lines (61 loc) · 1.4 KB
/
google.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
67
68
69
70
71
72
73
// 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 Google struct {
BaseDataSource
quantity int
limit int
}
func NewGoogle() DataSource {
g := &Google{
quantity: 10,
limit: 160,
}
g.BaseDataSource = *NewBaseDataSource(SCRAPE, "Google")
return g
}
func (g *Google) Query(domain, sub string) []string {
var unique []string
if domain != sub {
return unique
}
re := utils.SubdomainRegex(domain)
num := g.limit / g.quantity
for i := 0; i < num; i++ {
u := g.urlByPageNum(domain, i)
page, err := utils.GetWebPage(u, nil)
if err != nil {
g.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 (g *Google) urlByPageNum(domain string, page int) string {
start := strconv.Itoa(g.quantity * page)
u, _ := url.Parse("https://www.google.com/search")
u.RawQuery = url.Values{
"q": {"site:" + domain},
"btnG": {"Search"},
"hl": {"en"},
"biw": {""},
"bih": {""},
"gbv": {"1"},
"start": {start},
"filter": {"0"},
}.Encode()
return u.String()
}