But the other day I ran across a network (at an airport) which allowed only port 80 - the regular http port. Even port 443 was banned (so not only could I not connect to my ssh server, but no facebook, gmail, etc...)
I already have stuff on port 80 - my webserver - so what could I do? I know ssh can be tunnelled through the http CONNECT method. Could I set that up so that my web server would serve web traffic as usual but allow me to CONNECT to the ssh server?
Turns out yes.
In the http server config - enable mod_proxy and mod_proxy_connect. Then this config in proxy.conf (or the main server config, I guess):
<IfModule mod_proxy.c> ProxyRequests On <Proxy *> AddDefaultCharset off Order deny,allow Deny from all </Proxy> <Proxy localhost> Allow from all </Proxy> AllowCONNECT 22 ProxyVia On </IfModule>
(If you're doing this yourself - be careful about what you allow - if you are too liberal you turn your server into an open spamming and hacking engine for the world to exploit. And it will be found. Automatically, and within days or maybe hours.)
On the client side, use netcat as a proxy command in SSH: (you can also put the proxy command in ~/.ssh/ssh_config)
ssh -o 'ProxyCommand nc -X connect -x myhost.example.com:80 localhost 22' myhost.example.com
Note that the ssh server now sees you connecting from localhost, and the http server is the one who logs the real IP address. A caveat here is if you have IP-based security policies that make localhost special, then anyone connecting through this proxy is also special.
Lots of the config for this came from http://mariobrandt.de/archives/technik/ssh-tunnel-bypassing-transparent-proxy-using-apache-170/
So that gets me a CONNECT proxy.
But does it work at the airport? No.
Turns out the airport is also running everything through a transparent proxy: when I connect to s0.barwen.ch port 80, I'm actually connected to the airport's transparent proxy. So an http CONNECT command to localhost:22 both points to the wrong place and is administratively prohibits.
It turns out I can http CONNECT to s0.barwen.ch port 80, though, and there issue another CONNECT command to get to localhost:22:
$ nc -4 -X connect -x s0.barwen.ch:80 s0.barwen.ch 80 CONNECT localhost:22 HTTP/1.0 200 Connection Established Proxy-agent: Apache/2.2.14 (Ubuntu) SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu5
So I can get to the server this way.
How can I get the ssh commandline to talk to the remote server, with the extra proxy step added?
$ cat t.sh ( echo "CONNECT localhost:22" ; cat ) | nc -X connect -x s0.barwen.ch:80 s0.barwen.ch 80 | ( read ; read ; read; cat) $ ssh -o 'ProxyCommand ./t.sh' s0.barwen.ch
Now once that's done, I can run a SOCKS proxy over the same ssh connection, and route my normal web browsing through that - giving me access to https sites, and anything else that can use SOCKS.