January 27, 2010

SSH - Subverting Corporate Insanity

To quote someone much wiser, ‘developing good software is hard enough without having to deal with this shit’. High up on this list is having to deal with poor network infrastructure. SSH to the rescue.

Using ssh port forwarding / tunnels we can circumvent firewalls and other blockers inside corporate networks that provide no security value and basically make it hard for people to get their job done.

The simplest, yet most used command will allow you to forward a port on one network to a local port using an intermediary that you have ssh access to.

As a common example, say there are two networks in operation. All traffic is funnelled through some gateway. This is annoying, you have to first ssh into the gateway, then ssh again into your remote environment. This is even more annoying if you have to do something like push a file to that remote machine.

The solution: forward a local port to the target server via your gateway.

ssh -f -L 10022:secretsquirrel.evil.corp:22 gateway.evil.corp -N
To explain: Now to ssh to secretsquirrel you can just run:
ssh -p 10022 user@localhost
How this works:

So this works, and should work for any service not just ssh (say http if there is an app server hiding in there), however it is messy. To tidy this up ssh config is the key. For the example an ssh config entry can be added to make it more natural:

Host secretsquirrel
    Hostname  localhost
    Port      10022

Now you can just:

ssh user@secretsquirrel

There is a whole other post in how awesome ssh config is. As an exercise to the reader I will leave adding an entry to tidy up the initial port forward command. Hint: see LocalForward directive.

Ok, so the first example was pretty straight forward. It also assumes that you can ssh into somewhere on the network. Sometimes that is not possible. I will get around to showing you how to do that at somepoint in the future. For now some hints: