Total Pageviews

Sunday 10 April 2016

简单的翻墙术-一个基于perl的脚本

苹果移动设备蹿墙可选择的技术很少(不越狱的话)。看到一个零配置的新思路:建一个网站 phuckgfw.com;在DNS上把所有*.phuckgfw.com都解析过来;从HTTP头的HOST里获取实际要访问的服务器。譬如要访问 www.blocked.com,在浏览器里输入www.blocked.com.phuckgfw.com就可以了。比cgi代理效果和体验都好。
还算比较有意思的东西,其实和我以前想的连接ISP的wifi然后通过DNS Tunnel免费上网的办法有点类似——我想的这个DNS Tunnel和网上流传的不同,即使ISP配置了未认证的客户端只能访问指定的DNS服务器的UDP 53端口也没用,直接无视。前些时候无聊的时候我把协议都设计好了,只是后来因为别的事情耽搁了,没有写代码。
回来说正事儿。我把自己的域名icylife.net配置了一个泛解析,然后写一个perl运行在TCP 9090端口,访问http://www.youtube.com.icylife.net:1024就是在访问youtube。这个perl脚本才30多行代码,昨晚趁宝宝睡觉时候写的,不过不支持POST,然后替换返回页面内容中的链接地址时做得比较恶心,肯定是有bug的。如果要真正实用,建议使用nginx+perl来实现。
我应该有1年多没写过代码了,重温了一把coding的感觉。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl
use warnings;
use strict;
use LWP::UserAgent;
use Domain::PublicSuffix;
use AnyEvent::HTTPD;
 
my $httpd = AnyEvent::HTTPD->new (port => 1024);
$httpd->reg_cb (
        '' => sub {
                my ($httpd, $req) = @_;
 
                my $path = $req->url->as_string;
                my $host = $req->{hdr}->{host};
 
                $host =~ s/\.icylife.*//g;
                my $url = "http://$host$path";
                print $url,"\n";
 
                my $ua = LWP::UserAgent->new;
 
                my $response = $ua->get( $url );
                if ($response->is_success)
                {
                        my $raw_content = $response->content;
 
                        my $suffix = Domain::PublicSuffix->new( );
                        my $root = $suffix->get_root_domain( $host );
 
                        $raw_content =~ s/$root/$root\.icylife\.net:1024/g;
 
                        $req->respond( { content => [ $response->header('content-type'), $raw_content ] } );
                }
                else
                {
                        $req->respond( { content => ['text/html', "<html><body><h1>fuck !</h1></body></html>"] } );
                }
       },
);
 
$httpd->run;

from http://web.archive.org/web/20131031124154/http://www.icylife.net/blog/?p=847