forked from owasp-amass/amass
/
wayback.go
78 lines (66 loc) · 1.76 KB
/
wayback.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
74
75
76
77
78
// 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 (
"github.com/OWASP/Amass/amass/core"
"github.com/OWASP/Amass/amass/utils"
)
// Wayback is the Service that handles access to the Wayback data source.
type Wayback struct {
core.BaseService
domain string
baseURL string
SourceType string
filter *utils.StringFilter
}
// NewWayback returns he object initialized, but not yet started.
func NewWayback(config *core.Config, bus *core.EventBus) *Wayback {
w := &Wayback{
domain: "web.archive.org",
baseURL: "http://web.archive.org/web",
SourceType: core.ARCHIVE,
filter: utils.NewStringFilter(),
}
w.BaseService = *core.NewBaseService(w, "Wayback", config, bus)
return w
}
// OnStart implements the Service interface
func (w *Wayback) OnStart() error {
w.BaseService.OnStart()
w.Bus().Subscribe(core.NameResolvedTopic, w.SendDNSRequest)
go w.processRequests()
return nil
}
func (w *Wayback) processRequests() {
for {
select {
case <-w.Quit():
return
case req := <-w.DNSRequestChan():
if w.Config().IsDomainInScope(req.Name) {
w.executeQuery(req.Name, req.Domain)
}
case <-w.AddrRequestChan():
case <-w.ASNRequestChan():
case <-w.WhoisRequestChan():
}
}
}
func (w *Wayback) executeQuery(sn, domain string) {
if sn == "" || domain == "" || w.filter.Duplicate(sn) {
return
}
names, err := crawl(w, w.baseURL, w.domain, sn, domain)
if err != nil {
w.Config().Log.Printf("%s: %v", w.String(), err)
return
}
for _, name := range names {
w.Bus().Publish(core.NewNameTopic, &core.DNSRequest{
Name: cleanName(name),
Domain: domain,
Tag: w.SourceType,
Source: w.String(),
})
}
}