I used to debug my style sheet with Opera, it is really a fast browser, however, I am surprised to see opera doesn't support socks proxy (powered by ssh -D) even in latest version 9.5. I googled for a while and found this great workaround. I am shocked to see that two years have passed since the post was written and opera still doesn't support socks proxy yet! What's the difficult for the opera developers' to implement the feature?
I like the tinyproxy solution since ssh tunneling is exactly how I access internet from company inside network.
The steps:
- Install tinyproxy on my
debian vps server, quite easy beacuse tinyproxy is in the debian
package repository, just type apt-get install tinyproxy. - Edit /etc/tinyproxy/tinyproxy.conf, change listen address to
127.0.0.1, set allow IP address to 127.0.0.1 since I will use ssh
tunnel to access tinyproxy only, tune MaxClients, MinSpareServers,
MaxSpareServers and StartServers, then run /usr/sbin/tinyproxy to
start the daemon. - Use ssh client to connect the my vps box with a local forwarding
rule, ssh -fN -D 7070 -L 8888:localhost:8888 user@vps.example.org - Set opera to use localhost:8888 as http proxy, enjoy surfing
internet!
Following graph should let you understand the solution easier.
.----------------------. .----------------------.
| http | ssh | |
|Opera ===> ssh client +========> sshd:22 -> tinyproxy ==> internet sites
| :8888 | tunnel | :8888 |
`----------------------' `----------------------'
local box vps.example.org
Jun 24, 2008 at 12:50am | 1 Comment
Tags: opera, ssh and tinyproxy
公司查封了端口 22,除了 80 和 443 也只有少数端口开放,ssh 登陆远程主机成了奢侈的愿望。依靠代理是不能想的,free vpn 也没戏,tor?开放的 tor 服务器早就被掐了。当然远程管理有很多 web 程序,但我的最终目的是要用 ssh -D 做 socks proxy。
为此我想了一个途径,就是 web 服务器上放一个 cgi,通过 HTTP POST 发送 ssh 数据包,大体上思路是这样:
SSH HTTP POST SSH
ssh client <=====> http agent <===========> web cgi <=====> sshd
其中 http agent 就是一个转换程序,listen 在 localhost 某个端口,接收 ssh client 的请求,再包成 HTTP POST 请求发送出去,接收应答发回给 ssh client,这个很简单,用 python 也就几十行就完工了。另一端一开始也不了解,边看资料边做,做着做着问题来了,cgi 是请求 - 响应工作模式,响应完了就结束了,就算 web 服务支持pipelining,也不能和 sshd 保持连接。
然后我要想了个土办法,web cgi 不直接和 sshd 打交道,实际上它也不能和其他进程打交道,鉴于 cgi 的生命周期特征,可以用原始的办法,那就是用文件和其他进程通信。cgi 把接收到的请求写到一个 input 文件,另外起一个 pickup 进程,和sshd 保持连接,轮询那个 input 文件,转发到 sshd,再把 sshd 应答写到 output 文件,cgi 从ouput 中取应答作为 http response 发回给 http agent。
想不到的土,但是总算完成了一个 proof of concept,用 python 做这种东西相当的方便,当然其中也有些地方很费脑筋了,比如这模型只是一个半双工的模式,要模拟成全双工的,http agent 还得用超时机制主动请求。
要做成一个真正可用的工具,至少还得解决这些问题:
- 文件要加 lock 机制,php 里面不知道有没有这功能
- 减少资源的占用,cgi 每次都要打开两个文件进行读写,有没有办法不用文件来通信?
- 性能。半双工模式有很多等待,如何在资源和性能之间平衡?
PS: 在 dreamhost 运行了一下下,马上被当作 DoS 了,大概是 pickup 进程 I/O 请求太多,给合租伙伴制造了麻烦,真是对不住。
PS again: 如果真要在跟我一样的苛刻环境下远程 ssh,用 http://webssh.org 吧,不过程序是装在别人主机上,谁知道是不是安全。
Apr 10, 2008 at 12:42am | 0 Comments
Tags: http and ssh
ssh forwarding 一直以为自己用得很熟了,却一直没有注意还有个 -D 选项可以动态转发,用来做 socks 代理再好不过了,最近也说得比较多了(#1, #2)。
下面这个其实是 Firefox 的 trick。
地址栏输入 about:config,查找 dns,将 network.proxy.socks_remote_dns 设置为 true。这是指定由 socks 代理服务器来解析域名,这就把 DNS 请求也加密转发了,DNS Spoofing 也没指望了,更加安全,在上班时间 blogging 也放心了。
其实我也是 google 来的,起因是公司里面所有的外部网络流量全经过 http 代理服务器,包括 DNS,不转发 DNS 请求的话这个 ssh socks 服务就等于废物。
至于其他的应用,需要就 google 看吧。
Oct 23, 2007 at 12:33am | 0 Comments
Tags: firefox and ssh
公司只能通过 http proxy 上网,Solaris 里面自带的 ssh-http-proxy-connect 命令不管用,想到 dreamhost 提供的 shell 中摆弄几下总也不成功。今天 google 到一个东西可以说是最好的解决办法:goto-san-connect 1.96,比以前发现的http tunnel方便多了。
源码:http://zippo.taiyo.co.jp/~gotoh/ssh/connect.c
编译方法源码里就有。
用于 openssh 时在 ~/.ssh/config 里用 ProxyCommand 命令,例如:
Host joyus
User fakename Hostname joyus.org
ProxyCommand connect -4 -H proxyserver:port %h %p
更多信息:
Using OpenSSH through a SOCKS compatible PROXY on your LANhttp://zippo.taiyo.co.jp/~gotoh/ssh/openssh-socks.html
Detailed usagehttp://zippo.taiyo.co.jp/~gotoh/ssh/connect.html
打包下载:http://joyus.org/pub/goto-san-connect-1.96.tar.gz
Jul 10, 2006 at 10:32pm | 0 Comments
Tags: opensource, ssh and tool
公司内部只能通过 http 代理进行外出访问,FTP 下载、Gaim 这种本身支持代理的东西虽然没有问题,但要想 ssh 或者 telnet 登陆外面的服务器就不好办了。Google 到了httptunnel,可以建立 HTTP 隧道跑任何 TCP 应用,支持 proxy,它由客户端 htc 和服务端 hts 两个程序组成,安装很简单:
wget http://ftp.gnu.org/gnu/httptunnel/httptunnel-3.3.tar.gz
tar xzvf ../tarball/httptunnel-3.3.tar.gz
cd httptunnel-3.3/
./configure
make
这就得到了 hts 和 htc,可以 make install 装到 /usr/local/bin,或者直接把 hts htc 复制到要的位置就好了。
假设要从内网 10.1.1.1 登陆外面的 234.5.6.7,在两台机器上分别装好 httptunnel,10.1.1.1 上要运行 htc,234.5.6.7 上要运行 hts(最初只好在能登陆的环境中操作啦),代理服务器为 222.188.125.66:3128,原理如下:
10.1.1.1 222.188.125.66 234.5.6.7
.------------------------. .-----------------. .-----------------------.
| [ssh client] | | [proxy :3128] | | [sshd] |
| | | | / | | ^ |
| | | | / | | | |
| `----> [htc :2222] -+--+->--' `-->--+--+-> [hts :4433] ---' |
`------------------------' `-----------------' `-----------------------'
在 234.5.6.7 上运行 hts:
hts -F localhost:22 -S 4433
在 10.1.1.1 上运行 htc 然后就可以 ssh 从本机穿过隧道:
htc -S -F 2222 234.5.6.7:4433 -P 222.188.125.66:3128
ssh -v localhost -p 4433 -l username
Cool!
Jan 12, 2006 at 5:37am | 0 Comments
Tags: opensource, ssh and tool