How to get a remote desktop server (RDP) to automatically SSH back to a connecting client?

0

I am trying to automate the process of connecting to a Windows machine via RDP and then initiating an ssh tunnel back to the client machine.

The way I currently manually handle this:

  1. I log into the RDP server and run the following command to aid in helping me find the right IP address:

    netstat -a | find "3389" | find "ESTABLISHED"

    This spits out a line that contains the connection details for my computer's rdp connection. This IP is the IP that the server will be able to route through back to my computer.

  2. I manually open PuTTY and open an existing session that's properly configured with username and key, change the IP appropriately, and click connect.

At this point on my client machine I can now access some resources via the ssh port forwarding.

What I would like to do is figure out some way to automate this. The Microsoft remote desktop client has the ability to launch an program upon connection. What I don't know is what program or combination of programs to run.

mindless.panda

Posted 2012-02-06T21:31:43.357

Reputation: 6 642

Answers

0

Plink is a command line connection helper for Putty. Using Plink you can avoid the manual operations that you are performing in step 2

I manually open PuTTY and open an existing session that's properly configured with username and key, change the IP appropriately, and click connect.

For the arguments to Plink I'd suggest further piping the IP address you correctly obtained using netstat and find.

So in the end the command might look like

netstat -a | find "3389" | find "ESTABLISHED" > | plink -ssh

Remember to establish that plink is supposed to use SSH like in the above command, or better still set the windows environment variable PLINK_PROTOCOL to ssh.

Also ensure that the plink executable file's path is established in the PATH environment variable.

IUnknown

Posted 2012-02-06T21:31:43.357

Reputation: 2 018

The netstat line doesn't result in just a single IP, only one line out netstat output. – mindless.panda – 2012-02-07T00:57:38.003