🔗 过滤 Telegram Messenger
作者:Yuri Voinov
🔗 如何放行 Telegram
从 0.10.11 版本(针对 tdesktop)开始,Telegram 客户端在连接网络进行初始连接时,使用不标准的 TLS 握手方式进行 TLS 连接。
149.154.164.0/22
149.154.172.0/22
91.108.4.0/22
91.108.56.0/24
2001:67c:4e8::/48
2001:b28:f23d::/48
此外,它还可以通过推送通知,利用亚马逊/谷歌/Azure 等相对较大的网络进行 Web 前置。
因此,必须配置 SSL-Bump 代理,以便将 Telegram 的初始连接“切入”到服务器。
# SSL-bump rules
acl DiscoverSNIHost at_step SslBump1
# Splice specified servers
acl NoSSLIntercept ssl::server_name_regex "/usr/local/squid/etc/acl.url.nobump"
ssl_bump peek DiscoverSNIHost
ssl_bump splice NoSSLIntercept
ssl_bump bump all
将此添加到 acl.url.nobump
# Telegram
149\.154\.1(6[0-9]|7[0-5])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])
91\.108\.([4-7]|5[6|7])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])
这是 Telegram 连接所需的最小访问权限。
这仅影响使用 HTTP 代理设置的 Telegram 客户端。在拦截代理上,它同样适用于 Telegram 客户端的 AUTO 模式(默认设置)。
注意:通常最新的 Telegram 客户端可以通过代理连接而没有问题。但是,如果您的客户端遇到困难,请使用上述配置。此外,如果您使用 ufdbguard,可能需要将 Telegram 的 IP 地址添加到排除 ACL 中,以便绕过 ufdbguard 的连接探测(取决于 ufdbguard 的版本)。
🔗 如何阻止 Telegram
为了进行初始连接,Telegram 在第一阶段使用 HTTP POST 请求到上述网络的 http://A.B.C.D/api,然后对这些地址发出不带 SNI 的 CONNECT 调用。
要因为任何原因阻止 Telegram,只需编写如下配置片段即可
# Block Telegram
acl Telegram url_regex ^http:\/\/149\.154\.1(6[0-9]|7[0-5])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\/api$
acl Telegram url_regex ^http:\/\/91\.108\.([4-7]|5[6|7])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\/api$
http_access deny Telegram
deny_info TCP_RESET Telegram
acl Telegram_api_terminate ssl::server_name_regex 149\.154\.1(6[0-9]|7[0-5])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])
acl Telegram_api_terminate ssl::server_name_regex 91\.108\.([4-7]|5[6|7])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])
# SSL bump rules
acl DiscoverSNIHost at_step SslBump1
ssl_bump peek DiscoverSNIHost
ssl_bump terminate Telegram_api_terminate
ssl_bump splice all
您可以轻松扩展规则以覆盖 IPv6 网络。
如果 Telegram 开始将其初始连接隐藏在全球 CDN 之后,只需将上述规则扩展到 http://0.0.0.0/api 模式。
注意:如果您还想禁止 **MTProto 代理**,请记住它使用非 TLS 握手,并且不呈现任何由知名 CA(如 Telegram)签名的合法证书。因此,可以使用 Ufdbguard 或编写 Squid 的证书测试助手轻松禁止。
⚠️ 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
导航: 站点搜索, 站点页面, 分类, 🔼 向上