SSH tunnel (proxy) setup using Putty(SSH client) to a home router using Tomato (SSH server).

Engineer

Elite Member
Oct 9, 1999
39,230
701
126
Per request, I'm taking a stab at a guide to set up an SSH connection using Putty to a router (running Tomato with SSH Daemon (server)). The purpose of doing so is to have a strong encryption of ALL data while surfing using a strong encryption (1024 bit RSA in my case) and a private key for login and encryption purposes. This is very useful in using WiFi hotspots where "sniffers" look for data from people surfing those unsecured channels. (See firewall notes below). Oh, and yes, in some cases, this can provide anonymous surfing through firewalls and proxies, but that's not the intent of this guide. Besides, some (if not all) can be detected and blocked through corporate firewalls/proxies even on common ports like 443. Comments welcome! :)



Guide to using Putty with router flash with Tomato for an SSH tunneled connection.


Step 1: Download Putty.exe (Telnet and SSH client) and Puttygen.exe (SSH key generator) from here:

Click me (Putty.exe and Puttygen.exe).


These are stand alone applications (not zipped) so store them in a folder that you can use permanently (i.e. C:\Program Files\Putty or something similar to fit your needs). You probably want to create a shortcut to Putty.exe on your desktop.

Step 2: Generate and save your key using puttygen.exe:


PuttyGenerator.jpg


PuttyGeneratorwithkey.jpg




Open the program and select the <Generate> button. The program will instruct you to move the mouse randomly around the pad area. As you move the mouse around, you'll notice the green progress bar fill from left to right until complete. Once complete, the key screen will be displayed. If desired, you can type a "Key passphrase" into the box and confirm (recommended - the passphrase must be entered to use the key with Putty when running).

Hi-light the "Public key for pasting into OpenSSH authorized_keys file:" and copy (<CTRL><C> ).

Click on the <Save private key> file and enter the name you wish the save the .ppk file. This is your key file that will be used within Putty (or any other SSH client) to allow connection and encryption between the PC and the server (router in this case).

Step 3: Setup of SSH Daemon (server):

Server_router_setup.jpg


(No, that is not my key! :p )

Open your browser and enter the Tomato setup page. Go to the Administration page and then select the "Admin Access" submenu. Under the SSH Daemon section, check the "Enable at Startup" box and then the "Remote Access" box. Enter the port that you wish to use from the Wan (Internet) into the "Remote Port" box. Check the "Remote Forwarding" box and leave the "Port" box at 22. Uncheck "Allow Password Login" and finally, paste your key (copied from step #2 above) into the Authorized Keys box. Select <Save> at the bottom of the page. After saving, you may wish to click on the <Start Now> box or you can simply reboot to start the SSH Daemon.

Your SSH Daemon (server) is now set up and functioning. Time to get the client running, set up the tunnel and then set your browser to use the proxy tunnel to surf the web encrypted.

Step 4: Setup of SSH authorization and proxy tunnel using Putty.exe.



Putty.jpg


Open Putty.exe. From the "Session" page, enter the Host Name (or IP) of your server (just set up in step 3 - External WAN Internet address). Set the Port to the "Remote Port" that you entered during Step #3. Make sure connection type is set to SSH.

Click on the "SSH" section and then on the "Auth" subsection. Click on the <Browse> button under "Private key file for authentication". Select the .ppk file that you created in step #2 above.

Click on the "Tunnels" subsection. You will now enter a local port (your choice) that will be used to proxy the PC (8080 for example).

1. Source Port: Fill in a port number that will be used locally, on the laptop, for this connection. For instance, you might use port 8080 for forwarded HTTP requests.

2. Destination: Leave the text field empty. Select the Dynamic and Auto options.

Now click the <Add> button to add the port for tunneling.

Return to the "Session" page and name your newly created SSH tunnel. Enter a name in the box "Saved Sessions" and click the <Save> button. Your tunnel configuration should now be ready to run.

Step 5: Set your browser to use the newly created SSH tunnel above (step 4).


Proxysettings.jpg




Open your browser, select the "Tools" menu and then "Options". Now select the "Connections" tab and click on the <LAN settings> button. Check the "Use a proxy server for your LAN" box. Now click on the <Advanced> button. From there, enter the following in the SOCKS field:

127.0.0.1 and port 8080 (as created above). Note: This is a SOCKS5 proxy if using Firefox (see guide below for FF details). Now click on <OK> and then <OK> until back to the broswer main page.

Your browser is now ready to use the SSH proxy tunnel.


Step 6: Start the SSH client (Putty) and get the tunnel started.

Open Putty.exe. Select the Saved Session that you created earlier and select <Load>. Now click on the <Open> button. This will open Putty and, if everything is OK, you should be greeted with a black box with a "Login" prompt. At the login, enter root. You should be greeted with the passphrase (if used during key generation). Enter your passphrase. If everything is OK, the box will indicate that you have now logged on and have a tunnel.

Puttyafterlogin.jpg



Note: You will need to do this each time you wish to start a connection. As long as you keep the connection (or don't lose signal), you will not need to repeat this step to browse.[/b]

Step 7: Browse


To have Firefox use the new proxy tunnel created above for DNS lookup, enter about:config in the FireFox URL entry and then search for network.proxy.socks_remote_dns and set it to true. This will force FireFox to use the SOCKS proxy for DNS lookup and avoid having DNS used from the wireless connection (open and possibly spoofed).

Looking for IE and other browser instructions....

If everything worked OK, you should now be browsing your newly created 1024 bit (or whatever you used when generating the key) SSH tunnel.




Good writeup on the "proxy" portion of Putty.


Please note: This is not intended to firewall your PC on a public connection from hacks. You still need a good firewall to make sure that your ports are closed down to the general public. A good virus checker is also a good idea. The use of the SSH tunnel is to encrypt all internet traffic by using the public wifi to tunnel to your router (SSH Daemon server) with 100&#37; encrypted traffic. If you have open ports that can be exploited, your PC will be at risk no matter the use of SSH or not. Please make sure that you are protected with a good firewall (not sure if windows firewall is good enough or not).
 
Last edited:

Engineer

Elite Member
Oct 9, 1999
39,230
701
126
Originally posted by: Gillbot
So this only routes browser traffic through SSH? What about HTTPS?

Anything that goes through your browser (HTTP, HTTPS, etc) will go through the SSH tunnel. If you have an FTP client that can be forced to use the proxy tunnel, it will also work. Is that the question?

HTTPS will be double protected, so to speak.
 

Gillbot

Lifer
Jan 11, 2001
28,830
17
81
Originally posted by: Engineer
Originally posted by: Gillbot
So this only routes browser traffic through SSH? What about HTTPS?

Anything that goes through your browser (HTTP, HTTPS, etc) will go through the SSH tunnel. If you have an FTP client that can be forced to use the proxy tunnel, it will also work. Is that the question?

HTTPS will be double protected, so to speak.

yes, basically.
 

Engineer

Elite Member
Oct 9, 1999
39,230
701
126
Originally posted by: n0cmonkey
How do you handle DNS traffic or is that an acceptable information leak?

Before the putty connection completes (i.e. if you use a name in the putty configuration, it has to be looked up via DNS before the connection) or after the SSH tunnel is setup?

That's a very good question. I assumed that after the connection, DNS was handled by putty but that may have to be set up as another tunnel in itself. I'll look into it tonight when I get back to the hotel (out of town on business).

Edit: From the looks of it, Firefox will use the SOCKS proxy for DNS if using the tunnel (SSH) as the proxy. Not sure of IE or other browsers. Still looking but difficult to find something "definite".

Edit #2: Looks like you have to turn it on for Firefox using the about:config menu. Look for network.proxy.socks_remote_dns and set it to true

One of the features that SSH is highlighted with (from many sites) is elimination of DNS spoofing (that seems like it is what we're talking about but it's vague to me).
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Engineer
Originally posted by: n0cmonkey
How do you handle DNS traffic or is that an acceptable information leak?

Before the putty connection completes (i.e. if you use a name in the putty configuration, it has to be looked up via DNS before the connection) or after the SSH tunnel is setup?

That's a very good question. I assumed that after the connection, DNS was handled by putty but that may have to be set up as another tunnel in itself. I'll look into it tonight when I get back to the hotel (out of town on business).

Edit: From the looks of it, Firefox will use the SOCKS proxy for DNS if using the tunnel (SSH) as the proxy. Not sure of IE or other browsers. Still looking but difficult to find something "definite".

Edit #2: Looks like you have to turn it on for Firefox using the about:config menu. Look for network.proxy.socks_remote_dns and set it to true

One of the features that SSH is highlighted with (from many sites) is elimination of DNS spoofing (that seems like it is what we're talking about but it's vague to me).

Awesome. Had no idea the browsers would be able to use the tunnel.
 

Engineer

Elite Member
Oct 9, 1999
39,230
701
126
Originally posted by: Gillbot
What about IE?

I haven't found anything on how to route DNS through SSH using IE. I was hoping that it was as simple as creating a new forward tunnel and forwarding UDP 53 (DNS) to the SSH server (router in this case) but haven't found enough information on it to let me know if it works or not. I may try it when I get to the hotel and see if IE still works. FireFox should work anyway as it has the setting to do it automatically.

We're getting closer and closer to turning SSH into a VPN! :p

Maybe I should get Tomato with theOpenVPN built in and play around with that the next time I go on the road! ;)
 

spidey07

No Lifer
Aug 4, 2000
65,469
5
76
Hi. Just providing the other side. The way you block this activity is TCP 22, just flat out drop it.

SSL VPNs/tunnels are also a severe security risk as they bypass all policy. If you want to block this use an SSL proxy enforced by a firewall.
 

Engineer

Elite Member
Oct 9, 1999
39,230
701
126
Originally posted by: spidey07
Hi. Just providing the other side. The way you block this activity is TCP 22, just flat out drop it.

SSL VPNs/tunnels are also a severe security risk as they bypass all policy. If you want to block this use an SSL proxy enforced by a firewall.

Since I'm not the most network savvy person in the world, are you talking about blocking SSH tunnels from the IT side of things (as port 22 is the "default" port for ssh)?

(I'm not using this for work tunneling by the way, just trying to provide more secure surfing while on "hot spots" without setting up a full blown vpn. Besides, it doesn't work at work (and I'm not using port 22 either) :p )

By the way Gillbot, I cannot find a way to map all DNS from IE through the tunnel. I used a packet sniffer and determined that no matter what I tried, it didn't work. Firefox worked as advertised though (with the setting above).
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Engineer
Originally posted by: Gillbot
What about IE?

I haven't found anything on how to route DNS through SSH using IE. I was hoping that it was as simple as creating a new forward tunnel and forwarding UDP 53 (DNS) to the SSH server (router in this case) but haven't found enough information on it to let me know if it works or not. I may try it when I get to the hotel and see if IE still works. FireFox should work anyway as it has the setting to do it automatically.

We're getting closer and closer to turning SSH into a VPN! :p

Maybe I should get Tomato with theOpenVPN built in and play around with that the next time I go on the road! ;)

If you're using OpenSSH as the server you can create and SSH based VPN. Look in the ssh manual for the section entitled: "SSH-BASED VIRTUAL PRIVATE NETWORKS"

Haven't played with it though, and I'm not sure if putty supports it. Haven't touched putty in a while.

EDIT: Wrong button, and putty comment.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Engineer
Since I'm not the most network savvy person in the world, are you talking about blocking SSH tunnels from the IT side of things (as port 22 is the "default" port for ssh)?

(I'm not using this for work tunneling by the way, just trying to provide more secure surfing while on "hot spots" without setting up a full blown vpn. Besides, it doesn't work at work (and I'm not using port 22 either) :p )

By the way Gillbot, I cannot find a way to map all DNS from IE through the tunnel. I used a packet sniffer and determined that no matter what I tried, it didn't work. Firefox worked as advertised though (with the setting above).

SSH traffic has some distinct qualities, especially during the connection. It shouldn't be too hard to drop on a reasonably managed network.
 

nhelder

Junior Member
Aug 8, 2010
1
0
0
Hi, all~

Well, I'm rather confused. I've followed the above steps and everything is working fine... right up until I actually try to browse using the SSH tunnel.

If I attempt to hit a web page with the proxy on and the SSH connection in place, I get a blank page.

This is different than if I attempt to hit a web page with the proxy on and the SSH connection -not- in place - in that case, I get the standard 404 error.

So the proxy appears to at least be resolving DNS entries... but that seems to be about it.

Any ideas what the problem might be or any additional troubleshooting steps I could take?

Thanks,

- Nathan

P.S. For whatever it's worth, I'm on Tomato 1.28 and FF 3.6.8. Also, the other tunnels for remote desktop that I have set up work fine...
 

infopost

Junior Member
Aug 10, 2010
1
0
0
Does anyone know why when I try to log into putty with a certain IP it always connects me to the root IP of my server? I have 32 different IPs but I always get connected to the main IP despite the fact I will log in with one of the other IPs.