使用具有 SNI 过滤功能的鱿鱼透明地建立 HTTPS 隧道

xri*_*isk 3 squid

我的要求是:

  1. 代理应该是透明的。
  2. 我应该能够按域名过滤网站。
  3. 我不想解密流量。我正在寻找基于 SNI 嗅探的解决方案——无需在客户端上安装证书。

有很多答案,但它们要么不正确(声称您需要解密流量才能做到这一点),要么不完整。

xri*_*isk 5

实现这一点的方法是使用 Squid 3.5 中引入的 ssl peek 功能。请参阅此处了解详细说明。请注意,您需要使用--with-gnutls或进行编译--with-openssl(检查squid -v)。有些发行版将它们排除在外。

简而言之,相关的squid配置如下所示。

acl denylist_ssl ssl::server_name google.com # NOT dstdomain
acl step1 at_step SslBump1
ssl_bump peek step1
ssl_bump splice !denylist_ssl # allow everything not in the denylist
ssl_bump terminate all # block everything else
https_port 3129 intercept ssl-bump cert=/etc/squid/dummy.pem
Run Code Online (Sandbox Code Playgroud)

(旁白:我不知道为什么我们只需要查看步骤 1 而不是步骤 2,因为步骤 2 只涉及接收服务器证书。文档根本没有明确说明这一点。按照他们的建议使用会使ssl_bump peek all这完全停止工作)。

然后使用 iptables 将端口 443 重定向到 3129(或者如果您愿意,可以让鱿鱼直接监听 443)。

-A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 3129
Run Code Online (Sandbox Code Playgroud)

您可以为虚拟对象使用任何证书,我们实际上从不使用它(因为我们不解密流量)。

像这样的东西有效。

openssl req -new -newkey rsa:4096 -sha256 -days 365 -nodes -x509 -keyout dummy.pem -out dummy.pem
Run Code Online (Sandbox Code Playgroud)

资料来源:

[1] https://unix.stackexchange.com/questions/613359/setting-up-squid-transparent-proxy-with-ssl-bumping-on-debian-10

[2] https://web.archive.org/web/20210128152111/https://www.cammckenzie.com/blog/index.php/2018/07/19/squid-https-interception-and-filtering-without -客户证书/

[3] https://wiki.squid-cache.org/Features/SslPeekAndSplice