{"id":25836,"date":"2020-04-03T15:28:59","date_gmt":"2020-04-03T09:58:59","guid":{"rendered":"https:\/\/www.armourinfosec.com\/?p=25836"},"modified":"2020-04-06T17:44:36","modified_gmt":"2020-04-06T12:14:36","slug":"spawning-interactive-reverse-shell","status":"publish","type":"post","link":"https:\/\/www.armourinfosec.com\/spawning-interactive-reverse-shell\/","title":{"rendered":"Spawning Interactive Reverse Shell"},"content":{"rendered":"
Often during pentests, you\u00a0have a non-tty-shell<\/strong> there are certain commands and stuff you can’t do. This can happen if you upload reverse shells on a web server, so that the shell you get is by the user www-data, or similar. These users are not meant to have shells as they don’t interact with the system as humans do. So if you don’t have a tty-shell<\/strong> you can’t run Python pty Module<\/p>\n Perl<\/p>\n 1. Python to spawn a PTY<\/p>\n 2. Put the shell in to background with Ctrl-Z<\/p>\n 3. Examine the current terminal and STTY info and match it<\/p>\n The information needed is the TERM type (\u201cxterm-256color\u201d<\/em>) and the size of the current TTY (\u201crows 37; columns 146\u201d<\/em>)<\/p>\n 4. Set the current STTY to type raw and tell it to echo the input characters<\/p>\n 5. Foreground the shell with fg and re-open the shell with reset<\/p>\n 6. stty size to match our current window<\/p>\n 7. Set PATH TERM and SHELL if missing<\/p>\n Often during pentests, you\u00a0have a non-tty-shell there are certain commands and stuff you can’t do. This can happen if you…<\/p>\n","protected":false},"author":1,"featured_media":846,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,90],"tags":[],"yoast_head":"\nsu<\/code><\/strong>,
sudo<\/code><\/strong> etc. This can be annoying if you manage to get a root password but you can’t use it. Here are some commands which will allow you to spawn a tty shell<\/strong>. Obviously some of this will depend on the system environment and installed packages. So, let’s start with Spawning Interactive Reverse Shell.<\/p>\n
Shell Spawning<\/strong><\/h2>\n
python -c 'import pty; pty.spawn(\"\/bin\/sh\")'<\/pre>\n
perl -e 'exec \"\/bin\/sh\";'\r\n<\/pre>\n
Simple Shells to Fully Interactive TTYs<\/h3>\n
$ python -c 'import pty; pty.spawn(\"\/bin\/bash\")'\r\n or\r\n$ python3 -c 'import pty; pty.spawn(\"\/bin\/bash\")'\r\n<\/pre>\n
$ Ctrl-Z<\/pre>\n
# echo $TERM\r\n# stty -a<\/pre>\n
# stty raw -echo<\/pre>\n
# fg\r\n reset<\/pre>\n
$ export SHELL=bash\r\n$ export TERM=xterm256-color\r\n$ stty rows 37 columns 146\r\n$ bash -i<\/pre>\n
$ export PATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin\r\n$ export TERM=xterm\r\n$ export SHELL=bash\r\n$ cat \/etc\/profile; cat \/etc\/bashrc; cat ~\/.bash_profile; cat ~\/.bashrc; cat ~\/.bash_logout; env; set\r\n$ export PS1='[\\u@\\h \\W]\\$ '<\/pre>\n","protected":false},"excerpt":{"rendered":"