forked from gaulliath/operative-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_twitter.go
130 lines (113 loc) · 3.46 KB
/
google_twitter.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
129
130
package google
import (
"net/http"
u "net/url"
"os"
"strconv"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/jedib0t/go-pretty/table"
"github.com/Oni-kuki/operative-framework/session"
)
type GoogleTwitterModule struct {
session.SessionModule
sess *session.Session `json:"-"`
Stream *session.Stream `json:"-"`
}
func PushGoogleTwitterModule(s *session.Session) *GoogleTwitterModule {
mod := GoogleTwitterModule{
sess: s,
Stream: &s.Stream,
}
mod.CreateNewParam("TARGET", "Search text", "", true, session.STRING)
mod.CreateNewParam("LIMIT", "Limit search", "10", false, session.STRING)
return &mod
}
func (module *GoogleTwitterModule) Name() string {
return "google.twitter"
}
func (module *GoogleTwitterModule) Author() string {
return "Tristan Granier"
}
func (module *GoogleTwitterModule) Description() string {
return "Find result from google search engine"
}
func (module *GoogleTwitterModule) GetType() []string {
return []string{
session.T_TARGET_SEARCH,
}
}
func (module *GoogleTwitterModule) 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 *GoogleTwitterModule) Start() {
paramEnterprise, _ := module.GetParameter("TARGET")
target, err := module.sess.GetTarget(paramEnterprise.Value)
if err != nil {
module.sess.Stream.Error(err.Error())
return
}
paramLimit, _ := module.GetParameter("LIMIT")
url := "https://www.google.com/search?num=" + paramLimit.Value + "&start=0&hl=en&q=" + u.QueryEscape(target.GetName()+" site:twitter.com")
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.SetAllowedColumnLengths([]int{60, 100})
t.AppendHeader(table.Row{"Link", "Username"})
resultFound := 0
doc.Find(".g").Each(func(i int, s *goquery.Selection) {
link, _ := s.Find("a[href]").First().Attr("href")
if strings.Contains(link, "twitter") {
var username string
if strings.Contains(link, "://") {
username = strings.Split(link, "://")[1]
}
if strings.Contains(link, "twitter.com ›") {
checking := strings.Split(link, "›")
username = strings.TrimSpace(checking[1])
}
if username == "" {
username = link
}
if strings.Contains(username, "/") {
splitting := strings.Split(username, "/")
if len(splitting) > 1 {
username = strings.Split(username, "/")[1]
}
}
t.AppendRow([]interface{}{link, username})
result := target.NewResult()
result.Set("LINK", link)
result.Set("USERNAME", username)
result.Save(module, target)
resultFound = resultFound + 1
module.Results = append(module.Results, link)
}
})
module.Stream.Render(t)
module.Stream.Success(strconv.Itoa(resultFound) + " result(s) found with a google search engine.")
}