forked from gaulliath/operative-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewdns_search.go
128 lines (111 loc) · 3.09 KB
/
viewdns_search.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package viewdns_search
import (
"net/http"
"os"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/jedib0t/go-pretty/table"
"github.com/Oni-kuki/operative-framework/session"
)
type VDNSearch struct {
session.SessionModule
sess *session.Session `json:"-"`
Stream *session.Stream `json:"-"`
}
func PushWSearchModule(sess *session.Session) *VDNSearch {
mod := VDNSearch{
sess: sess,
Stream: &sess.Stream,
}
mod.CreateNewParam("TARGET", "Email Address", "", true, session.STRING)
return &mod
}
func (module *VDNSearch) Name() string {
return "email_to_domain"
}
func (module *VDNSearch) Description() string {
return "Find possible linked website with email address"
}
func (module *VDNSearch) Author() string {
return "Tristan Granier"
}
func (module *VDNSearch) GetType() []string {
return []string{
session.T_TARGET_EMAIL,
}
}
func (module *VDNSearch) GetInformation() session.ModuleInformation {
information := session.ModuleInformation{
Name: module.Name(),
Description: module.Description(),
Author: module.Author(),
Type: module.GetType(),
Parameters: module.Parameters,
}
return information
}
func (module *VDNSearch) Start() {
targetId, err := module.GetParameter("TARGET")
if err != nil {
module.Stream.Error(err.Error())
return
}
target, err := module.sess.GetTarget(targetId.Value)
if err != nil {
module.Stream.Error(err.Error())
return
}
separator := target.GetSeparator()
url := "https://viewdns.info/reversewhois/?q=" + target.GetName()
client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36")
res, _ := client.Do(req)
defer res.Body.Close()
if res.StatusCode != 200 {
module.Stream.Error("Argument 'URL' can't be reached.")
return
}
doc, err := goquery.NewDocumentFromReader(res.Body)
if err != nil {
module.Stream.Error(err.Error())
return
}
headerReturn := "Domain Name" + separator + "Creation Date" + separator + "Registrar"
resultFound := 0
t := module.Stream.GenerateTable()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{
"Domain Name",
"Creation Date",
"Registrar",
})
doc.Find("table").Each(func(i int, s *goquery.Selection) {
val, exist := s.Attr("border")
if exist && val == "1" {
s.Find("tr").Each(func(i int, tr *goquery.Selection) {
valueReturn := ""
resRow := table.Row{}
tr.Find("td").Each(func(i int, td *goquery.Selection) {
element := strings.TrimSpace(td.Text())
if element != "Domain Name" && element != "Creation Date" && element != "Registrar" {
if valueReturn == "" {
valueReturn = valueReturn + element
} else {
valueReturn = valueReturn + separator + element
}
resRow = append(resRow, element)
}
})
if valueReturn != "" {
result := target.NewResult()
result.Set(headerReturn, valueReturn)
result.Save(module, target)
t.AppendRow(resRow)
resultFound = resultFound + 1
}
})
}
})
module.Stream.Render(t)
}