Netcat reverse shell exiting immediately

I’m not sure what I’m doing wrong here, but every time I set up a listener with netcat, ie: nc -nlvp 1234, and I run code to create a reverse shell, it doesn’t stay open.

I will get a connection, (connect to [10.10.14.54] from (UNKNOWN) [10.10.10.5] 49160), but then as soon as I press enter it just goes back to my command prompt. Why is this happening?

This is happening on more than one machine, and I have successfully done this before. So I’m not sure what changed. Any suggestions? Thanks

Your command looks fine. What kind of reverse shell are you using? Possible reasons for this behavior that I can think of:

  • forgot the “-e” parameter (if the shell was also sent using nc)
  • using a staged payload (nc can only handle stageless payloads)
  • the process that you exploit to send the reverse shell is terminated (in this case you might need to use meterpreter and quickly migrate to another process)

Thanks, it was definitely the payload, I didn’t even think about that. Got a shell now, unfortunately I’m running into more issues when I try to upgrade my shell. I’m running python -c ‘import pty;pty.spawn("/bin/bash");’ then nothing happens and my shell actually becomes unresponsive, i.e. ls, pwd, etc. doesnt work and I need to exit and run my reverse shell again. Really frustrating as according to writeups and videos in which I see it working this is exactly what is done. But mine just hangs when they get a shell, I dont get it

Type your comment> @JWindy92 said:

Thanks, it was definitely the payload, I didn’t even think about that. Got a shell now, unfortunately I’m running into more issues when I try to upgrade my shell. I’m running python -c ‘import pty;pty.spawn("/bin/bash");’ then nothing happens and my shell actually becomes unresponsive, i.e. ls, pwd, etc. doesnt work and I need to exit and run my reverse shell again. Really frustrating as according to writeups and videos in which I see it working this is exactly what is done. But mine just hangs when they get a shell, I dont get it

If python doesn’t work try using python3
python3 -c “import pty;pty.spawn(’/bin/bash’)”

also this method works good enough for me
give these commands one after another
SHELL=/bin/bash script -q /dev/null
Press Ctrl-Z
stty raw -echo
fg
reset
xterm