forked from gaulliath/operative-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_ipaddress.go
113 lines (95 loc) · 2.52 KB
/
get_ipaddress.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
package get_ipaddress
import (
"net"
"os"
"strings"
"github.com/graniet/go-pretty/table"
"github.com/Oni-kuki/operative-framework/session"
)
type GetIpAddressModule struct {
session.SessionModule
sess *session.Session `json:"-"`
Stream *session.Stream `json:"-"`
}
func PushGetIpAddressModule(s *session.Session) *GetIpAddressModule {
mod := GetIpAddressModule{
sess: s,
Stream: &s.Stream,
}
mod.CreateNewParam("TARGET", "Website domain target", "", true, session.STRING)
return &mod
}
func (module *GetIpAddressModule) Name() string {
return "get.ip_address"
}
func (module *GetIpAddressModule) Author() string {
return "Tristan Granier"
}
func (module *GetIpAddressModule) Description() string {
return "Get internet protocol address from specific target"
}
func (module *GetIpAddressModule) GetType() []string {
return []string{
session.T_TARGET_WEBSITE,
}
}
func (module *GetIpAddressModule) 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 *GetIpAddressModule) Start() {
trg, err := module.GetParameter("TARGET")
if err != nil {
module.sess.Stream.Error(err.Error())
return
}
target, err := module.sess.GetTarget(trg.Value)
if err != nil {
module.sess.Stream.Error(err.Error())
return
}
if strings.Contains(target.GetName(), "://") {
expProto := strings.Split(target.GetName(), "://")
proto := expProto[0]
expURL := ""
if strings.Contains(target.GetName(), "/") {
expURL = strings.Split(expProto[1], "/")[0]
target.Name = proto + "://" + expURL
}
} else {
if strings.Contains(target.GetName(), "/") {
expURL := strings.Split(target.GetName(), "/")[0]
target.Name = "https://" + expURL
}
}
if strings.Contains(target.GetName(), "://") {
target.Name = strings.Split(target.Name, "://")[1]
}
ipAddress, _ := net.LookupIP(target.GetName()) // take from 1st argument
if len(ipAddress) > 0 {
t := module.sess.Stream.GenerateTable()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{
"IP",
})
for _, ip := range ipAddress {
t.AppendRow(table.Row{
ip.String(),
})
result := target.NewResult()
result.Set("IP", ip.String())
result.Save(module, target)
module.Results = append(module.Results, ip.String())
}
module.sess.Stream.Render(t)
} else {
module.sess.Stream.Error("No result found")
return
}
}