-
Notifications
You must be signed in to change notification settings - Fork 7
/
module.go
163 lines (136 loc) · 5.15 KB
/
module.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
Merlin is a post-exploitation command and control framework.
This file is part of Merlin.
Copyright (C) 2024 Russel Van Tuyl
Merlin is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
Merlin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Merlin. If not, see <http://www.gnu.org/licenses/>.
*/
package module
import (
"github.com/google/uuid"
)
// Module is a structure containing the base information or template for modules
type Module struct {
id uuid.UUID // id the unique identifier for this instance of the module
agent string // agent is the Agent the module will be executed on
name string // name is the name of the module
extended bool // extended is true if the module is an extended module or else it is a "standard" module
author []string // author is a list of module authors
credits []string // A list of people to credit for underlying tool or techniques
path []string // Path to the module (i.e., data/modules/powershell/powerview)
platform string // Platform that the module can run on (i.e., Windows, Linux, Darwin, or ALL)
arch string // The Architecture the module can run on (i.e., x86, x64, MIPS, ARM, or ALL)
lang string // What language does the module execute in (i.e., PowerShell, Python, or Perl)
priv bool // Does this module require a privileged level account like root or SYSTEM?
description string // A description of what the module does
notes string // Additional information or notes about the module
commands []string // A list of commands to be run on the agent
sourceRemote string // Online or remote source code for a module
sourceLocal []string // The local file path to the script or payload
options []Option // A list of configurable options/arguments for the module
originalOptions []Option // An original and unmodified list of configurable options/arguments for the module
}
// Option is a structure containing the keys for the object
type Option struct {
Name string `json:"name"` // Name of the option
Value string `json:"value"` // Value of the option
Required bool `json:"required"` // Is this a required option?
Flag string `json:"flag"` // The command line flag used for the option
Description string `json:"description"` // A description of the option
}
// NewModule instantiates a module object, assigns a unique identifier, and returns the object
func NewModule(name, platform, arch, lang, description, notes string, extended, priv bool, author, credits, path, commands []string, options []Option) *Module {
// TODO this is not the right way to make a new copy that doesn't point to the original
origOptions := make([]Option, len(options))
origOptions = append(origOptions, options...)
return &Module{
id: uuid.New(),
agent: "",
name: name,
extended: extended,
author: author,
credits: credits,
path: path,
platform: platform,
arch: arch,
lang: lang,
priv: priv,
description: description,
notes: notes,
commands: commands,
sourceRemote: "",
sourceLocal: nil,
options: options,
originalOptions: origOptions,
}
}
func (m *Module) Agent() string {
return m.agent
}
func (m *Module) Arch() string {
return m.arch
}
func (m *Module) Author() []string {
return m.author
}
func (m *Module) Commands() []string {
return m.commands
}
func (m *Module) Credits() []string {
return m.credits
}
func (m *Module) Description() string {
return m.description
}
func (m *Module) Extended() bool {
return m.extended
}
// ID returns the unique identifier for this instance of the module
func (m *Module) ID() uuid.UUID {
return m.id
}
func (m *Module) Lang() string {
return m.lang
}
func (m *Module) Name() string {
return m.name
}
func (m *Module) Notes() string {
return m.notes
}
func (m *Module) Options() []Option {
return m.options
}
// OptionsMap is used to generate a map containing module option names and values to be used with other functions
func (m *Module) OptionsMap() map[string]string {
optionsMap := make(map[string]string)
for _, v := range m.Options() {
optionsMap[v.Name] = v.Value
}
return optionsMap
}
func (m *Module) OriginalOptions() []Option {
return m.originalOptions
}
func (m *Module) Platform() string {
return m.platform
}
// String returns the name of the module
func (m *Module) String() string {
return m.name
}
func (m *Module) UpdateAgent(id string) {
m.agent = id
}
// UpdateOptions updates the options for the module
func (m *Module) UpdateOptions(options []Option) {
m.options = options
}