-
Notifications
You must be signed in to change notification settings - Fork 6
/
ggtfobins.go
207 lines (171 loc) · 5.53 KB
/
ggtfobins.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
203
204
205
206
207
package main
import (
"flag"
"fmt"
"log"
"net/http"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/gookit/color"
)
var (
badass = color.HEX("#bada55")
hotpink = color.HEX("#f06")
)
type Flags struct {
bins string
exploit string
}
func main() {
flag.Usage = func() {
printBanner()
}
flags := getFlags()
flag.Parse()
bins := flags.bins
exploit := flags.exploit
err := validateRequiredFlagValues(bins, exploit)
if err != nil {
printBanner()
color.Red.Println(err)
return
}
printFlagsBanner(exploit, bins)
binsList := strings.Split(bins, ",")
for _, bin := range binsList {
trimmedBin := strings.TrimSpace(bin)
url := fmt.Sprintf("https://gtfobins.github.io/gtfobins/%s", trimmedBin)
err = printBins(url, trimmedBin, exploit)
if err != nil {
log.Println(err)
}
}
printCredits()
}
func printBanner() {
badass.Print("\n ______ ______ ______ ______ ______ ______ __ __ __ ______ \n/\\ ___\\ /\\ ___\\ /\\__ _\\ /\\ ___\\ /\\ __ \\ /\\ == \\ /\\ \\ /\\ \"-.\\ \\ /\\ ___\\ \n\\ \\ \\__ \\ \\ \\ \\__ \\ \\/_/\\ \\/ \\ \\ __\\ \\ \\ \\/\\ \\ \\ \\ __< \\ \\ \\ \\ \\ \\-. \\ \\ \\___ \\ \n \\ \\_____\\ \\ \\_____\\ \\ \\_\\ \\ \\_\\ \\ \\_____\\ \\ \\_____\\ \\ \\_\\ \\ \\_\\\\\"\\_\\ \\/\\_____\\ \n \\/_____/ \\/_____/ \\/_/ \\/_/ \\/_____/ \\/_____/ \\/_/ \\/_/ \\/_/ \\/_____/")
fmt.Print("\n\n")
color.White.Print("Get info about a given exploit for given bins\n\n")
badass.Print("Usage: ggtfobins --exploit suid --bins bash,cat\n\n")
color.White.Print("Available exploits:\n\n- bind-shell\n- capabilities\n- bin\n- file-download\n- file-read\n- file-upload\n- file-write\n- library-load\n- limited-suid\n- non-interactive-bind-shell\n- non-interactive-reverse-shell\n- reverse-shell\n- shell\n- sudo\n- suid\n\n")
}
func getFlags() Flags {
binsPtr := flag.String("bins", "", "Comma-separated list of Bins to find given exploit for")
exploitPtr := flag.String("exploit", "", "Exploit type:\n- bind-shell\n- capabilities\n- bin\n- file-download\n- file-read\n- file-upload\n- file-write\n- library-load\n- limited-suid\n- non-interactive-bind-shell\n- non-interactive-reverse-shell\n- reverse-shell\n- shell\n- sudo\n- suid")
flag.Parse()
return Flags{
bins: *binsPtr,
exploit: *exploitPtr,
}
}
func validateRequiredFlagValues(bins, exploit string) error {
if bins == "" || exploit == "" {
return fmt.Errorf("Error: make sure you set bins and an exploit")
}
if !isValidExploit(exploit) {
return fmt.Errorf("Error: not a valid exploit")
}
return nil
}
func isValidExploit(exploit string) bool {
validExploits := []string{
"bind-shell",
"capabilities",
"bin",
"file-download",
"file-read",
"file-upload",
"file-write",
"library-load",
"limited-suid",
"non-interactive-bind-shell",
"non-interactive-reverse-shell",
"reverse-shell",
"shell",
"sudo",
"suid",
}
for _, valid := range validExploits {
if exploit == valid {
return true
}
}
return false
}
func printFlagsBanner(exploit, bins string) {
fmt.Print("\n")
fmt.Print("---------------------------------")
color.Note.Printf("\n EXPLOIT: %s", exploit)
color.Note.Printf("\n BINS: %s\n", bins)
fmt.Print("---------------------------------")
fmt.Print("\n")
}
func printBins(url, bin, exploit string) error {
resp, err := http.Get(url)
if err != nil {
return fmt.Errorf("failed to fetch URL: %s, status: %s", url, resp.Status)
}
defer resp.Body.Close()
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
return fmt.Errorf("error getting body: %w", err)
}
printContent(doc, bin, exploit, url)
return nil
}
func printContent(doc *goquery.Document, bin, exploit, url string) {
id := fmt.Sprintf("#%s", exploit)
section := doc.Find(id)
if section.Text() == "" {
color.Danger.Printf("\n✘ %s not found\n", bin)
return
}
printTitle(exploit, bin, url)
printDescription(doc, id)
printExamples(doc, id)
}
func printTitle(exploit, bin, url string) {
exploitId := strings.ReplaceAll(exploit, " ", "-")
hotpink.Printf("\n✔ %s %s/#%s\n", bin, url, exploitId)
}
func printDescription(doc *goquery.Document, id string) {
text := ""
doc.Find(id).NextUntil(".examples").Each(func(i int, s *goquery.Selection) {
textTrimmed := strings.TrimSpace(s.Text())
text += fmt.Sprintf("\n%s\n", textTrimmed)
})
fmt.Println(text)
}
func printExamples(doc *goquery.Document, id string) {
codes := make([][]string, 0)
doc.Find(id).NextFilteredUntil(".examples", "h2").Find("li").Each(func(i int, s *goquery.Selection) {
s.Find("p").Each(func(i int, s *goquery.Selection) {
liDescription := fmt.Sprintf("%s", strings.TrimSpace(s.Text()))
codes = append(codes, []string{liDescription, ""})
})
s.Find("pre code").Each(func(i int, s *goquery.Selection) {
code := fmt.Sprintf("%s\n", strings.TrimSpace(s.Text()))
if len(codes) == i+1 {
codes[i] = []string{codes[i][0], code}
} else {
codes = append(codes, []string{"", code})
}
})
})
for i, _ := range codes {
if codes[i][0] != "" {
fmt.Println(codes[i][0])
}
badass.Printf("%s\n", codes[i][1])
}
}
func printCredits() {
fmt.Print("\n")
fmt.Print("--------------------------------------------------------------------------------------------")
fmt.Print("\n\n")
fmt.Print("- contribute to GTFOBins https://gtfobins.github.io/contribute/")
fmt.Print("\n")
fmt.Print("- follow GTFOBins' creators https://twitter.com/norbemi https://twitter.com/cyrus_and")
fmt.Print("\n")
fmt.Print("- follow me https://twitter.com/nightshiftc")
}