Ssh – ‘Reversed shell’ – pull shell commands from remote host with human-controlled input

.ncssh

I would like to connect to a remote machine, ideally over SSH, and then pull the commands from there.

To be precise, I would like make a remote machine connect to my local machine, where I would have an interactive console, send commands and see the output.
Functionally it would be similar to Windows Remote Assistant or what's the name.

I can imagine I would implement a HTTP server that would have a GUI, and on request, it would keep the connection forever and send any line that I type to the GUI; and receive everything the other side sends as its output. I would only have to take care of the HTTP headers. However, that's not too elegant.

Is there some such ready-made solution? Or perhaps using nc or some tool that would connect the TTY with a listening port?

Best Answer

If you run:

socat "unix-listen:$HOME/.shell-access,mode=600,fork" \
      "exec:$SHELL,pty,stderr,setsid,ctty"

That allows you to do for instance:

socat -,raw,echo=0 "unix:$HOME/.shell-access"

locally, to connect and interact with that shell.

Then you can remote-port-forward it over ssh with:

ssh -R "/path/to/socket/on/host:$HOME/.shell-access" user@host

(assumes a relatively recent version of openssh (both client and server)).

And then user on host can interact with that shell by doing that

socat -,raw,echo=0 "unix:/path/to/socket/on/host"

Instead of running $SHELL, you could run screen -xRS some-screen-session to attach a given screen session so several people can see the same screen session.

Related Question