Skip to content

Commit 5963a5f

Browse files
author
Wintrmvte
committed
Add Ngrok tunnels integration
1 parent 7de4244 commit 5963a5f

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

godspeed.go

+48-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import (
88
"strconv"
99
"strings"
1010
"time"
11+
"io/ioutil"
12+
"net/http"
13+
1114

1215
"github.com/akamensky/argparse"
16+
"github.com/savaki/jq"
1317
"github.com/olekukonko/tablewriter"
1418
"github.com/atotto/clipboard"
1519
"github.com/c-bata/go-prompt"
@@ -268,6 +272,7 @@ func StartCommandPrompt() {
268272
}
269273
case "exit":
270274
PrintInfo("Exiting...")
275+
CmdBlind("pkill -9 ngrok")
271276
os.Exit(0)
272277
case "check":
273278
parser := argparse.NewParser("check", "Check connectivity of active hosts") //, usage_prologue)
@@ -332,6 +337,41 @@ func StartCommandPrompt() {
332337
}
333338
}
334339

340+
func StartTunnel(port string) (string, string) {
341+
//regions := []string{"us", "eu", "ap", "au", "sa", "jp", "in"}
342+
//selected_region := RandomSelectStr(regions)
343+
go CmdBlind("ngrok tcp "+port)
344+
time.Sleep(2 * time.Second)
345+
local_url := "http://localhost:4040/api/tunnels"
346+
resp, err := http.Get(local_url)
347+
if err != nil {
348+
PrintError("Cannot obtain tunnel's address -> "+err.Error())
349+
os.Exit(0)
350+
}
351+
defer resp.Body.Close()
352+
json, err := ioutil.ReadAll(resp.Body)
353+
if err != nil {
354+
PrintError("Cannot obtain tunnel's address -> "+err.Error())
355+
os.Exit(0)
356+
}
357+
jq_op_1, _ := jq.Parse(".tunnels")
358+
json_1, _ := jq_op_1.Apply(json)
359+
jq_op_2, _ := jq.Parse(".[0]")
360+
json_2, _ := jq_op_2.Apply(json_1)
361+
jq_op_3, _ := jq.Parse(".public_url")
362+
json_3, _ := jq_op_3.Apply(json_2)
363+
main_url := strings.Replace(string(json_3), `"`, "", -1)
364+
main_url = strings.Replace(main_url, `tcp://`, "", -1)
365+
tunnel_addr := strings.Split(main_url, ":")[0]
366+
tunnel_port := strings.Split(main_url, ":")[1]
367+
t_ip, err := DnsLookup(tunnel_addr)
368+
tunnel_ip := t_ip[0]
369+
if err != nil {
370+
PrintError(F("Cannot perform DNS lookup for %s: %s", Red(tunnel_ip), err.Error()))
371+
}
372+
return tunnel_ip, tunnel_port
373+
}
374+
335375
func StartServer(proto, port string) {
336376
go StartCommandPrompt()
337377
listener, _ := net.Listen(proto, "0.0.0.0:"+port)
@@ -371,15 +411,22 @@ func main() {
371411
parser := argparse.NewParser("godspeed", "")
372412
var port *string = parser.String("p", "port", &argparse.Options{Default: "4444", Help: "Local port to listen on"})
373413
var clip *bool = parser.Flag("c", "clip", &argparse.Options{Required: false, Help: "Copy listening C2 address to clipboard"})
414+
var tunnel *bool = parser.Flag("t", "tunnel", &argparse.Options{Required: false, Help: "Expose C2 server using Ngrok tunnel"})
374415
err := parser.Parse(os.Args)
375416
ExitOnError(err)
376417
c2_addr := GetLocalIp() + ":" + *port
418+
if *tunnel{
419+
t_addr, t_port := StartTunnel(*port)
420+
c2_addr = t_addr + ":" + t_port
421+
PrintInfo("Started tunnel")
422+
}
377423
p()
378-
PrintInfo(F("Started server on port %s", green(bold(*port))))
424+
PrintInfo(F("Started reverse handler %s", cyan(bold("["+c2_addr+"]"))))
379425
p()
380426
if *clip {
381427
clipboard.WriteAll(c2_addr)
382428
PrintInfo("Copied server address to clipboard")
429+
p()
383430
}
384431
StartServer("tcp", *port)
385432
}

0 commit comments

Comments
 (0)