forked from gaulliath/operative-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
societe_com.go
112 lines (94 loc) · 2.8 KB
/
societe_com.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
package societe_com
import (
"net/http"
"os"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/jedib0t/go-pretty/table"
"github.com/Oni-kuki/operative-framework/session"
)
type SocieteComModule struct {
session.SessionModule
sess *session.Session `json:"-"`
Stream *session.Stream `json:"-"`
}
func PushSocieteComModuleModule(s *session.Session) *SocieteComModule {
mod := SocieteComModule{
sess: s,
Stream: &s.Stream,
}
mod.CreateNewParam("TARGET", "Person name eg: Jhon Doe", "", true, session.STRING)
mod.CreateNewParam("limit", "Limit search", "10", false, session.STRING)
return &mod
}
func (module *SocieteComModule) Name() string {
return "societe_com"
}
func (module *SocieteComModule) Description() string {
return "Search possible enterprise on french network"
}
func (module *SocieteComModule) Author() string {
return "Tristan Granier"
}
func (module *SocieteComModule) GetType() []string {
return []string{
session.T_TARGET_PERSON,
}
}
func (module *SocieteComModule) 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 *SocieteComModule) Start() {
paramPerson, _ := module.GetParameter("TARGET")
target, err := module.sess.GetTarget(paramPerson.Value)
if err != nil {
module.sess.Stream.Error(err.Error())
return
}
person := strings.Replace(target.Name, " ", "%20", -1)
paramLimit, _ := module.GetParameter("limit")
url := "https://www.google.com/search?num=" + paramLimit.Value + "&start=0&hl=en&q=intext%3A\"" + person + "\"+site%3Asociete.com+intext%3A\"siret\"+"
client := http.Client{}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
res, err := client.Do(req)
if err != nil {
module.Stream.Error("Argument 'URL' can't be reached.")
return
}
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("A error as been occurred with a target.")
return
}
t := module.Stream.GenerateTable()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{
"ENTERPRISE",
})
doc.Find(".g").Each(func(i int, s *goquery.Selection) {
line := s.Find("h3").Text()
line = strings.Split(line, "(")[0]
line = strings.TrimSpace(line)
result := target.NewResult()
result.Set("enterprise", line)
result.Save(module, target)
module.Results = append(module.Results, line)
t.AppendRow(table.Row{
line,
})
})
module.Stream.Render(t)
}