Spawning a TTY Shell
The first thing to do is use
python3 -c 'import pty;pty.spawn("/bin/bash")', which uses Python to spawn a better-featured bash shell. At this point, our shell will look a bit prettier, but we still won’t be able to use tab autocomplete or the arrow keys, and Ctrl + C will still kill the shell.Step two is:
export TERM=xterm– this will give us access to term commands such asclear.Finally (and most importantly) we will background the shell using
Ctrl + Z. Back in our own terminal we usestty raw -echo; fg. This does two things: first, it turns off our own terminal echo (which gives us access to tab autocompletes, the arrow keys, andCtrl + Cto kill processes). It then foregrounds the shell, thus completing the process.
python -c 'import pty; pty.spawn("/bin/sh")'
echo os.system('/bin/bash')
/bin/sh -i
perl —e 'exec "/bin/sh";'
perl: exec "/bin/sh";
ruby: exec "/bin/sh"
lua: os.execute('/bin/sh')
(From within IRB)
exec "/bin/sh"
(From within vi)
:!bash
(From within vi)
:set shell=/bin/bash:shell
(From within nmap)
!sh
# From netsec.wsLast updated
Was this helpful?