This issue has ariseb because I use reverse shells quite a lot and often need to upgrade the shell to enable tab autocomplete or cursor use. The issue is not just on reverse shells though, even if I use the following input in my own terminal I get the same result. I use Terminator, but have also tried this in Terminal and get the same issue.
The first method I tried was:
<Ctrl-z>
stty raw -echo
fg
<enter>
<enter>
This would result in me being unable to enter text though (bad characters appear e.g. ^M for enter):
Suspend with Ctrl-z, "stty raw -echo", hit enter twice, then fg to resume (ignore the "whoami"...!):
Ctrl-z, stty raw -echo, (please ignore the "whoami"...)
At the bottom you can see, when fg is entered I can enter text but if I press ENTER I get ^M.
Having looked through other posts I have tried two things. One is to ensure icrnl is set to ON, it is. The other was to try "stty raw -echo; fg" as one command instead of two. This produced a different result. It works better, but the prompt then moves across the screen whenever I press enter:
I have tried to do this in bash instead of zsh, I get the same result. Does anyone know how I may be able to solve this? I'll attach my stty below for info:
└─$ stty -a
speed 38400 baud; rows 46; columns 116; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q;
stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
Thanks for any help.
Bizarelly, having had this issue for weeks, I've literally just fixed it...!
Prior to suspending and doing stty... Changing the python command has fixed it:
Original:
python -c "import pty; pty.spawn('/bin/bash')"New (works):
python -c 'import pty;pty.spawn("/bin/bash")'Removing the space between pty; pty has fixed it. Then do the commands as above but include ;fg after stty raw -echo. Tab autocomplete etc all works! –