-
Notifications
You must be signed in to change notification settings - Fork 9
/
list.go
195 lines (151 loc) · 5.14 KB
/
list.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package cmd
import (
"fmt"
"io/fs"
"strings"
"path/filepath"
"github.com/guervild/uru/pkg/common"
"github.com/guervild/uru/pkg/encoder"
"github.com/guervild/uru/pkg/evasion"
"github.com/guervild/uru/pkg/injector"
"github.com/guervild/uru/pkg/logger"
"github.com/guervild/uru/data"
"github.com/spf13/cobra"
)
var listCmd = &cobra.Command{
Use: "list",
Short: "List basic options, and artifacts (encoders, evasions and injectors).",
Long: `List basic options, and artifacts (encoders, evasions and injectors).
usage:
./uru <artifact> <language>
Accepted artifacts: "encoders", "evasions", "injectors", or "options"
Accepted language: "go", "c"
Note: options does not need a language`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 || len(args) > 2 {
return fmt.Errorf("List need one to two arguments: ./uru list <articaft type> [language]. See --help")
}
return nil
},
Run: List,
}
func init() {
rootCmd.AddCommand(listCmd)
}
func List(cmd *cobra.Command, args []string) {
if strings.ToLower(args[0]) != "options" {
if len(args) != 2 {
fmt.Println("Need a second argument 'go' or 'c'")
return
}
if strings.ToLower(args[1]) != "go" && strings.ToLower(args[1]) != "c" {
fmt.Printf("language %s provided not supported\n", args[1])
return
}
}
switch strings.ToLower(args[0]) {
case "encoders":
printValue("Encoders", listEncoders(strings.ToLower(args[1])))
case "evasions":
printValue("Evasions", listEvasions(strings.ToLower(args[1])))
case "injectors":
printValue("Injectors", listInjectors(strings.ToLower(args[1])))
case "options":
printValue("Options", getOptions())
default:
fmt.Println("Argument must be encoders, evasions, injectors or options. For encoders, evasions and injectors, a second argument can be passed 'go' or 'c'.")
}
}
func createListOfModules(module string, langType string) []string {
dataTmpl := data.GetTemplates()
pathLang := filepath.Join("./templates", langType)
pathModule := filepath.Join(pathLang, module)
var lst = make([]string, 0)
err := fs.WalkDir(dataTmpl, pathModule,
func(path string, d fs.DirEntry, err error) error {
if err != nil {
logger.Logger.Fatal().Msg(err.Error())
}
if d.IsDir() {
if strings.ToLower(d.Name()) != "commons" && strings.ToLower(d.Name()) != strings.ToLower(module) {
if strings.ToLower(module) == "injector" {
lst = append(lst, path)
} else {
lst = append(lst, d.Name())
}
}
}
return nil
})
if err != nil {
logger.Logger.Fatal().Msg(err.Error())
}
return lst
}
func listEncoders(langType string) map[string]string {
mEncoders := make(map[string]string)
encoders := createListOfModules("encoders", langType)
for _, v := range encoders {
encoderValue, err := encoder.GetEncoder(strings.ToLower(v), langType)
if err != nil {
//logger.Logger.Info().Msg(err.Error())
} else {
name := common.GetField(encoderValue, "Name")
desc := common.GetField(encoderValue, "Description")
mEncoders[name] = desc
}
}
return mEncoders
}
func listEvasions(langType string) map[string]string {
mEvasions := make(map[string]string)
evasions := createListOfModules("evasions", langType)
for _, v := range evasions {
evasionValue, err := evasion.GetEvasion(strings.ToLower(v), langType)
if err != nil {
// logger.Logger.Info().Msg(err.Error())
} else {
name := common.GetField(evasionValue, "Name")
desc := common.GetField(evasionValue, "Description")
mEvasions[name] = desc
}
}
return mEvasions
}
func listInjectors(langType string) map[string]string {
mInjectors := make(map[string]string)
injectors := createListOfModules("injector", langType)
for _, v := range injectors {
path := strings.ReplaceAll(v, fmt.Sprintf("templates/%s/injector/", langType), "")
injectorValue, err := injector.GetInjector(strings.ToLower(path), langType)
if err != nil {
//logger.Logger.Info().Msg(err.Error())
} else {
name := common.GetField(injectorValue, "Name")
desc := common.GetField(injectorValue, "Description")
mInjectors[name] = desc
}
}
return mInjectors
}
func printValue(title string, value map[string]string) {
fmt.Println(fmt.Sprintf("========== %s ==========\n", title))
for k, v := range value {
n := fmt.Sprintf(" Name : %s", k)
d := fmt.Sprintf(" Description: %s\n", v)
fmt.Println(n)
fmt.Println(d)
}
}
func getOptions() map[string]string {
mOptions := make(map[string]string)
mOptions["arch"] = "Architecture of the compiled program: x64 or x86. (mandatory)"
mOptions["type"] = "Type of payload to compiled. Can be exe, pie or dll. (mandatory)"
//[SGN] - DECOMMENT TO USE SGN
//mOptions["sgn"] = "Apply SGN on the provided payload file (might not work with all shellcode/executable)."
mOptions["debug"] = "Add print and debug functions to the compiled program."
mOptions["obfuscation"] = "Obfuscate the code before compilation (Use garble to obfuscate the code)."
mOptions["append"] = "Append the provided string at the end of the payload file. Must be hexadecimal ex: 90909090"
mOptions["preprend"] = "Prepend the payload file with the provided string. Must be hexadecimal ex: 90909090"
return mOptions
}