@@ -8,8 +8,12 @@ import (
8
8
"strconv"
9
9
"strings"
10
10
"time"
11
+ "io/ioutil"
12
+ "net/http"
13
+
11
14
12
15
"github.com/akamensky/argparse"
16
+ "github.com/savaki/jq"
13
17
"github.com/olekukonko/tablewriter"
14
18
"github.com/atotto/clipboard"
15
19
"github.com/c-bata/go-prompt"
@@ -268,6 +272,7 @@ func StartCommandPrompt() {
268
272
}
269
273
case "exit" :
270
274
PrintInfo ("Exiting..." )
275
+ CmdBlind ("pkill -9 ngrok" )
271
276
os .Exit (0 )
272
277
case "check" :
273
278
parser := argparse .NewParser ("check" , "Check connectivity of active hosts" ) //, usage_prologue)
@@ -332,6 +337,41 @@ func StartCommandPrompt() {
332
337
}
333
338
}
334
339
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
+
335
375
func StartServer (proto , port string ) {
336
376
go StartCommandPrompt ()
337
377
listener , _ := net .Listen (proto , "0.0.0.0:" + port )
@@ -371,15 +411,22 @@ func main() {
371
411
parser := argparse .NewParser ("godspeed" , "" )
372
412
var port * string = parser .String ("p" , "port" , & argparse.Options {Default : "4444" , Help : "Local port to listen on" })
373
413
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" })
374
415
err := parser .Parse (os .Args )
375
416
ExitOnError (err )
376
417
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
+ }
377
423
p ()
378
- PrintInfo (F ("Started server on port %s" , green (bold (* port ))))
424
+ PrintInfo (F ("Started reverse handler %s" , cyan (bold ("[" + c2_addr + "]" ))))
379
425
p ()
380
426
if * clip {
381
427
clipboard .WriteAll (c2_addr )
382
428
PrintInfo ("Copied server address to clipboard" )
429
+ p ()
383
430
}
384
431
StartServer ("tcp" , * port )
385
432
}
0 commit comments