不知道什么原因,之前一直是直接在国外搭建sniproxy代理出去,最近突然不行了。所以在网上找到另外一个方法,通过stunnel + sniproxy的方式成功越狱。这里记录一下搭建的过程,供参考。说明:以下的程序都是运行在centos6操作系统下
1、sniproxy搭建
这个是实际代理出墙的代理软件,代理协议可以是http也可以是https
1.1 sniproxy的安装
之前写了一篇文章关于sniproxy的安装
详情见:sniproxy的安装
sniproxy配置
cd /usr/local/sniproxy
mkdir config
vim sniprxoy.conf
user nobody
pidfile /tmp/sniproxy.pid
error_log {
#syslog daemon
#priority notice
filename /usr/local/sniproxy/logs/error.log
}
access_log {
filename /usr/local/sniproxy/logs/access.log
}
listener 127.0.0.1:4433 { #https监听端口
protocol tls
table TableTls #https请求域名白名单
# Specify a server to use if the initial client request doesn't contain
# a hostname
# fallback 192.0.2.5:443
}
listener 127.0.0.1:8080 { #http监听端口
protocol http
table TableHttp #http请求域名白名单
}
table TableTls {
# Match exact request hostnames
# example.com 192.0.2.10:4343
# If port is not specified the listener port will be used
# example.net [2001:DB8::1:10]
# Or use regular expression to match
# .*\\.com [2001:DB8::1:11]:443
# Combining regular expression and wildcard will resolve the hostname
# client requested and proxy to it
# .*\\.edu *:443
# (.*.|)google.com$ *
.* *:443
}
table TableHttp {
.* *:80
}
table AllTable {
# Match exact request hostnames
# example.com 192.0.2.10:4343
# If port is not specified the listener port will be used
# example.net [2001:DB8::1:10]
# Or use regular expression to match
# .*\\.com [2001:DB8::1:11]:443
# Combining regular expression and wildcard will resolve the hostname
# client requested and proxy to it
# .*\\.edu *:443
# (.*.|)google.com$ *
.*\.google\.com$ *
.*\.google\.com\.hk$ *
google.com google.com
google.com.hk google.com.hk
.*\.gstatic\.com$ *
.*\.googleapis.com$ *
.*\.googleusercontent.com$ *
.*\.googlecode.com$ *
.*\.google-analytics.com$ *
.*\.ggpht.com$ *
.*\.googlevideo.com$ *
.*\.youtube.com$ *
youtube.com youtube.com
.*\.ytimg.com$ *
.*\.appspot.com$ *
.*\.blogger.com$ *
blogger.com blogger.com
.*\.twitter.com$ *
twitter.com twitter.com
.*\.twimg.com$ *
.*\.facebook.com$ *
facebook.com facebook.com
.*\.fbcdn.net$ *
# .* *:443
}
2、stunnel搭建
stunnel分为两部分,一部分在本地,属于客户端,即在办公区找一台服务器或者也可以用在公司的IDC找一台,反正原则上是办公网能直接访问的机器;
第二部分为服务端,部署在国外云服务器上。
2.1 客户端配置
安装stunnel
yum install stunnel -y
配置客户端
vi /etc/stunnel/stunnel-client.conf
client = yes pid = /etc/stunnel/stunnel-client.pid [http] accept = 80 connect = remote:8082 #remote替换为stunnel服务端IP地址 [https] accept = 443 connect = remote:4443 #remote替换为stunnel服务端IP地址
启动
stunnel /etc/stunnel/stunnel-client.conf
可以通过
ps -ef | grep stunnel 或 netstat -anp | grep 80 | grep -i listen
查看程序是否正常启动了
2.2 服务端配置
安装stunnel
yum install stunnel -y
生成stunnel证书
openssl genrsa -out key.pem 2048 openssl req -new -x509 -key key.pem -out cert.pem -days 1095 cat key.pem cert.pem >> /etc/stunnel/stunnel.pem
配置服务端
vim /etc/stunnel/stunnel.conf
client = no pid = /etc/stunnel/stunnel.pid [http] accept = 8082 #这个端口需要对应客户端的配置 connect = 127.0.0.1:8080 #8080 这个指定sniproxy http协议监听端口 cert = /etc/stunnel/stunnel.pem [https] accept = 4443 #这个端口需要对应客户端的配置 connect = 127.0.0.1:4433 #4433 这个指定sniproxy https协议监听端口 cert = /etc/stunnel/stunnel.pem
启动
stunnel /etc/stunnel/stunnel.conf
可以通过
ps -ef | grep stunnel 或 netstat -anp | grep 8082 | grep -i listen
查看程序是否正常启动了
3、测试
测试的方式可以通过绑定google的域名到stunnel客户端地址,也可以通过在DNS配置google域名A记录(stunnel客户端地址)。
4、安全(可选)
如果是为了安全,可以配置iptables,防止被其他人利用
-A INPUT ! -s {client ip}/32 -p tcp -m tcp --dport 4443 -j DROP
-A INPUT ! -s {client ip}/32 -p tcp -m tcp --dport 8082 -j DROP
注:client ip替换成stunnel客户端的出口IP