🔗 Torified Squid
- 作者:Yuri Voinov
🔗 目录
此配置通过 ACL 将选定的 HTTP/HTTPS 流量(端口 80 和 443)传递到级联的 Privoxy,然后再传递到 Tor 隧道。
🔗 用法
当 ISP 阻止用户所需的某些资源时,此配置非常有用。
🔗 法律声明
![]()
![]()
注意,此配置在某些国家/地区可能非法。这样做可能会触犯法律。请记住,您承担由此产生的所有责任。
🔗 概述
此配置的构想最早于 2011 年在此 处描述。然而,原始配置在某些方面过于冗余,并且存在一个严重缺点——它无法正确处理 HTTPS 流量。经过一些实验,已经创建了一个正确的配置,该配置在具有 Squid-3.5 的生产服务器上成功运行了两年多。此配置也可以与 Squid-4 一起使用。
注意:我们必须使用 Privoxy 作为中间代理,因为 Tor 是 SOCKS 代理而不是 HTTP 代理,无法直接与 Squid 链式连接。
🔗 构建 Tor
从 此处下载 Tor,解压缩并构建。
# 32 bit GCC
configure --with-tor-user=tor --with-tor-group=tor --prefix=/usr/local 'CXXFLAGS=-O3 -m32 -mtune=native -pipe' 'CFLAGS=-O3 -m32 -mtune=native -pipe' --disable-asciidoc --with-libevent-dir=/usr/local
# 64 bit GCC
configure --with-tor-user=tor --with-tor-group=tor --prefix=/usr/local 'CXXFLAGS=-O3 -m64 -mtune=native -pipe' 'CFLAGS=-O3 -m64 -mtune=native -pipe' --disable-asciidoc --with-libevent-dir=/usr/local
gmake
gmake install-strip
🔗 配置和运行 Tor
如下编辑 torrc
SocksPort 9050
## Entry policies to allow/deny SOCKS requests based on IP address.
## First entry that matches wins. If no SocksPolicy is set, we accept
## all (and only) requests that reach a SocksPort. Untrusted users who
## can access your SocksPort may be able to learn about the connections
## you make.
SocksPolicy accept 127.0.0.0/8
#SocksPolicy accept 192.168.0.0/16
SocksPolicy reject *
注意:出于安全原因,请注意,Tor 应从非特权用户运行。
我建议使用带有混淆桥接器(obfs3/4)的配置,这是最难被 DPI 阻止的。桥接器配置由您自行选择。我强烈建议在此之前仔细阅读 Tor 手册。
可以从 此处或通过电子邮件(在最困难的情况下)获取桥接器。
完成后,运行 Tor 并检查 tor.log 以查找错误。
![]()
![]()
重要提示
![]()
![]()
Starting from Tor 0.3.2 you [can use it directly as HTTPS tunneling
proxy](https://twitter.com/torproject/status/912708766084292608). For
this, you can add this to torrc:
# Starting from Tor 0.3.2
HTTPTunnelPort 8118
In this case Privoxy no more requires in theory. Unfortunately, this
does not work for connections starts with HTTP (i.e., when user type
"archive.org" in browser command line) and you'll get empty string with
[this error in Tor log](https://tor.stackexchange.com/questions/16095/405-method-connection-mark-unattached-ap).
因此,您仍然需要构建和配置 Privoxy。
🔗 Privoxy
配置和构建 Privoxy。
# 32 bit GCC
./configure --prefix=/usr/local/privoxy --enable-large-file-support --with-user=privoxy --with-group=privoxy --disable-force --disable-editor --disable-toggle 'CFLAGS=-O3 -m32 -mtune=native -pipe'
# 64 bit GCC
./configure --prefix=/usr/local/privoxy --with-user=privoxy --with-group=privoxy --disable-force --disable-editor --disable-toggle 'CFLAGS=-O3 -m64 -mtune=native -pipe' 'LDFLAGS=-m64'
gmake
gmake install-strip
将此添加到 Privoxy 配置中。
listen-address 127.0.0.1:8118
forward-socks5t / 127.0.0.1:9050 .
同时检查和配置 Privoxy 的性能设置。
从非特权用户如下运行 Privoxy。
## To start:
privoxy --pidfile /tmp/privoxy.pid --user privoxy.privoxy /usr/local/privoxy/etc
🔗 Squid 配置文件
像这样粘贴配置文件
# Domains to be handled by Tor
acl tor_url url_regex "/etc/squid/url.tor"
# SSL bump rules
acl DiscoverSNIHost at_step SslBump1
acl NoSSLIntercept ssl::server_name_regex "/etc/squid/url.nobump"
acl NoSSLIntercept ssl::server_name_regex "/etc/squid/url.tor"
ssl_bump peek DiscoverSNIHost
ssl_bump splice NoSSLIntercept
ssl_bump bump all
# Tor access rules
never_direct allow tor_url
# Local Tor is cache parent
cache_peer 127.0.0.1 parent 8118 0 no-query no-digest default
cache_peer_access privoxy allow tor_url
cache_peer_access privoxy deny all
access_log daemon:/var/log/squid/access.log logformat=squid !tor_url
将配置片段适配到您的配置。
对于 squid 4.x+,如下调整 access_log 设置。
acl hasRequest has request
access_log daemon:/data/cache/log/access.log buffer-size=256KB logformat=squid hasRequest !tor_url
/etc/squid/url.tor 包含您需要隧道传输的内容。
torproject.*
archive\.org
#livejournal\.com
#wordpress\.com
#youtube.*
#ytimg.*
#googlevideo.*
#google.*
#googleapis.*
#googleusercontent.*
#gstatic.*
#gmodules.*
#blogger.*
#blogspot.*
#facebook.*
#fb.*
telegram.*
tg\.me.*
tdesktop.*
注意:在某些情况下,最好不要记录 Tor 隧道访问。
注意:目前您必须 **splice** Tor 隧道连接,因为 Squid 尚无法重新加密对等连接。建议在启用 bump 的设置中使用此配置。
注意:url.tor 和 url.nobump 是不同的列表。
注意:Tor 不再支持 obfs3 和更早版本的桥接器。
🔗 性能考虑
Tor 隧道传输的 HTTP 连接由于缓存而具有更好的性能。但是,HTTPS 连接仍然受到 Tor 性能的限制,因为需要 splice 并且它们在这种配置中无法以任何形式进行缓存。请注意这一点。
⚠️ Disclaimer: Any example presented here is provided "as-is" with no support
or guarantee of suitability. If you have any further questions about
these examples please email the squid-users mailing list.
类别: ConfigExample
导航:站点搜索、站点页面、分类、🔼 向上