-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
202 lines (189 loc) · 5.63 KB
/
main.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
196
197
198
199
200
201
202
package main
import (
"flag"
"fmt"
"os"
"strings"
log "github.com/sirupsen/logrus"
"github.com/sudneo/gtfodora/pkg/binary"
"github.com/sudneo/gtfodora/pkg/gtfobins"
"github.com/sudneo/gtfodora/pkg/lolbas"
)
// Global Variables
var unixFunctions = []string{"shell", "upload", "download", "filewrite", "fileread", "libraryload", "sudo", "noninteractiverevshell", "command", "bindshell", "suid", "limitedsuid", "revshell", "noninteractivebindshell", "capabilities"}
var winFunctions = []string{"command", "awlbypass", "ADS", "download", "copy", "encode", "decode", "credentials", "compile", "dump", "uacbypass", "reconnaissance"}
func init() {
log.SetFormatter(&log.TextFormatter{
PadLevelText: true,
DisableTimestamp: true,
})
log.SetOutput(os.Stdout)
log.SetLevel(log.WarnLevel)
}
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func removeDuplicateValues(s []string) []string {
keys := make(map[string]bool)
list := []string{}
for _, entry := range s {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}
func listAll(b_list []binary.Binary) {
fmt.Println(">>> Unix binaries:")
for _, file := range b_list {
if file.Type == "unix" {
fmt.Println(file.Name)
}
}
fmt.Println(">>> Windows binaries:")
for _, file := range b_list {
if file.Type == "win" {
fmt.Println(file.Name)
}
}
}
func searchFunction(b_list []binary.Binary, function string) []string {
var binaries []string
for _, file := range b_list {
if has, _ := file.HasFunction(function); has {
binaries = append(binaries, file.Name)
}
}
return binaries
}
func binSearch(bin string, function string, b_list []binary.Binary) bool {
for _, file := range b_list {
if file.Name == bin {
if function != "" {
if has, details := file.HasFunction(function); has {
log.WithFields(log.Fields{
"Function": function,
"Binary": file.Name,
}).Info("The function is supported by the binary")
fmt.Printf("[+] %v:\n", function)
fmt.Println(strings.Repeat("-", len(function)+5))
for _, detail := range details {
detail.Print()
}
return true
} else {
log.WithFields(log.Fields{
"Binary": file.Name,
"Function": function,
}).Errorf("%q does not allow to perform function %q.\n", file.Name, function)
return false
}
}
file.Print()
return true
}
}
return false
}
func search(bin string, function string, b_list []binary.Binary) {
found := binSearch(bin, function, b_list)
if !found {
log.WithFields(log.Fields{
"Binary": bin,
}).Error("No results for the specified binary")
log.WithFields(log.Fields{
"Details": b_list,
}).Debug("Details")
}
}
func listFunctions(unix bool, win bool) {
var result []string
if unix {
result = append(result, unixFunctions...)
}
if win {
result = append(result, winFunctions...)
}
result = removeDuplicateValues(result)
fmt.Println("Functions available:")
for _, f := range result {
fmt.Printf("\t%v\n", f)
}
}
func validateFunction(a string) bool {
if !stringInSlice(a, unixFunctions) && !stringInSlice(a, winFunctions) {
return false
}
return true
}
func main() {
cloneDirPtr := flag.String("clone-path", "/tmp", "The path in which to clone the gtfobin and lolbas repos, defaults to \"/tmp.\"")
listFunctionsPtr := flag.Bool("list-functions", false, "List the functions for the binaries")
listAllPtr := flag.Bool("list-all", false, "List all the binaries in the collection")
unixFilterPtr := flag.Bool("unix", false, "Filter the search among only unix binaries (i.e., gtfobin)")
winFilterPtr := flag.Bool("win", false, "Filter the search among only windows binaries (i.e, lolbas)")
functionPtr := flag.String("f", "", "Filter the search only for the specified function")
searchBinPtr := flag.String("s", "", "Search for the binary specified and prints its details")
verbosePtr := flag.Bool("v", false, "Set loglevel to DEBUG")
flag.Parse()
if *verbosePtr {
log.SetLevel(log.DebugLevel)
}
win := *winFilterPtr || (!*unixFilterPtr && !*winFilterPtr)
unix := *unixFilterPtr || (!*unixFilterPtr && !*winFilterPtr)
var binary_list []binary.Binary
if win {
lolbas_location := fmt.Sprintf("%v/lolbas", *cloneDirPtr)
lolbas.Clone(lolbas_location)
binary_list = append(binary_list, lolbas.ParseAll(lolbas_location)...)
}
if unix {
gtfo_location := fmt.Sprintf("%v/gtfo", *cloneDirPtr)
gtfobins.Clone(gtfo_location)
binary_list = append(binary_list, gtfobins.ParseAll(gtfo_location)...)
}
if len(binary_list) == 0 {
log.Fatal("Error encountered getting information about binaries. Aborting")
}
// Processing of commandLine Args
switch {
case *listFunctionsPtr:
listFunctions(unix, win)
case *listAllPtr:
listAll(binary_list)
case *functionPtr != "":
valid := validateFunction(*functionPtr)
if !valid {
log.WithFields(log.Fields{
"Function": *functionPtr,
"Available Functions": append(unixFunctions, winFunctions...),
}).Error("The function selected is not available.")
return
}
if *searchBinPtr == "" {
bin_list := searchFunction(binary_list, *functionPtr)
if len(bin_list) > 0 {
fmt.Printf("List of all the binaries with function %v:\n", *functionPtr)
for _, s := range bin_list {
fmt.Println(s)
}
} else {
log.WithFields(log.Fields{
"Function": *functionPtr,
}).Error("No binary found with the specified function")
}
} else {
search(*searchBinPtr, *functionPtr, binary_list)
}
case *searchBinPtr != "":
search(*searchBinPtr, "", binary_list)
default:
log.Error("No necessary flags were specified")
}
}