前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >「技术架构」设置Squid转发代理或者正向代理

「技术架构」设置Squid转发代理或者正向代理

作者头像
首席架构师智库
发布2019-11-11 18:47:44
1.8K0
发布2019-11-11 18:47:44
举报
文章被收录于专栏:超级架构师超级架构师

「技术架构」设置Squid转发代理或者正向代理

首席架构师 2019-11-06 18:46

如果您正在阅读这篇文章,您可能会因为缺少与Squid相关的信息而感到沮丧,Squid是一种非常流行的转发代理。这些令人沮丧的事情包括:在小的软件修订之后出现的重大的可用性变化,对幕后发生的事情的误解,以及真正糟糕的文档。这是一个全面的入门,它将使你和鱿鱼。

首先,为什么要使用转发代理?在过去,在将所有连接发送到internet之前终止所有代理上的连接是非常流行的。这在企业中已经不那么流行了,但有时您可能仍然会遇到这种情况。然而,Squid可以做的远不止截获纯文本通信——它还可以对SSL/TLS通信进行实时解密,并且可以采用两种不同的配置,这些配置具有各自的安全含义。

转发代理有两种子类型——显式和隐式,代理SSL/TLS通信有两种方式——终止和不终止。这四种组合中的任何一种都是可能的,并且每种都有自己的需求集。显式v.隐式只是指客户端是否必须在其端指定(并可能验证)转发代理。在这种情况下,客户知道这正在发生。它使用CONNECT消息与代理进行接口,并帮助它协商到目的地的连接。

另一方面,隐含的联系更棘手,也更危险。在这个配置中,代理正在执行在另一个上下文中被认为是中间人攻击的操作。客户端完全不知道,他们的通信正在发送的某个地方伪装成目的地,对他们的通信进行解密,然后重新加密后发送到真正的目标服务器。响应也被动态捕获,并发送回原始服务器。正如我们所知,SSL/TLS通过使用非对称加密来保护与私钥的通信安全,并通过维护受信任公钥的注册表来防止中间人攻击。隐式转发代理绕过了这两种保护(尽管常常是故意的,有时甚至是安全的)。客户机没有显式地指定连接,而是像往常一样发送它的流量。在上游的某个地方,流量实际上是由第三层设备路由到代理的,然后代理将流量发送到另一个接口,以避免在另一端被检测到。它提供了一个对任何域都有效的证书,这些域是在请求实时到达时生成的,由于客户端需要被配置为信任代理使用的同一根CA证书,因此将允许连接。(请记住,作为根证书受信任的任何证书都可以为任何和所有域和路径签署有效的证书,而不仅仅是自己的。)

然而,这种配置非常有用。因为代理终止连接并与目的地重新协商,所以它实际上可以更改在飞行中使用的加密类型。假设您有使用Java 6的旧软件。你可以把前面的鱿鱼代理服务器,允许它实现PCI遵从性,即使软件只能使用TLS通过普通HTTP或HTTPS通信v1(目前不一致),代理将对交通使用TLS 1.2黄金标准。

如何配置这样的配置?当然,这可能会有点麻烦。对于每个操作系统来说也是不同的,但是基础是相同的。这并不适合胆小的人,需要一些在Linux中编译软件的经验。

在撰写本文时,最好的版本是Squid 3.5。从项目网站下载并解压到一个目录。您的linux发行版将需要gcc、make和其他潜在的开发环境工具。特别是在ubuntu上,安装build-essential应该覆盖你。你需要在这个盒子上加两个网卡,这样你才能在它们之间进行NAT。

您需要创建一个用户,名为:squid。

adduser squid

确保使用这些标志正确链接到所需的库。

./configure --prefix=/usr --exec-prefix=/usr --includedir=/usr/include --datadir=/usr/share --libdir=/usr/lib64 --libexecdir=/usr/lib64/squid --localstatedir=/var --sysconfdir=/etc/squid --sharedstatedir=/var/lib --with-logdir=/var/log/squid --with-pidfile=/var/run/squid.pid --with-default-user=squid --enable-silent-rules --enable-dependency-tracking --with-openssl --enable-icmp --enable-delay-pools --enable-useragent-log --enable-esi --enable-follow-x-forwarded-for --enable-auth --enable-ssl-crtd --disable-arch-native --with-openssl

接下来是make,然后是make install。

您需要生成自己的CA。

cd /etc/squid mkdir ssl_cert chown squid:squid ssl_cert chmod 600 ssl_cert cd ssl_cert openssl req -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -keyout myCA.pem -out myCA.pem

您可以确定您的CA的有效期应该超过1年。

openssl x509 -in myCA.pem -outform DER -out myCA.der

你的squidconf应该是这样的:

# # Recommended minimum configuration: # # Example rule allowing access from your local networks. # Adapt to list your (internal) IP networks from where browsing # should be allowed acl localnet src 10.0.0.0/8 # RFC1918 possible internal network acl localnet src 172.16.0.0/12 # RFC1918 possible internal network acl localnet src 192.168.0.0/16 # RFC1918 possible internal network acl localnet src fc00::/7 # RFC 4193 local private network range acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines acl localnet src 127.0.0.1 acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp acl Safe_ports port 443 # https acl Safe_ports port 70 # gopher acl Safe_ports port 210 # wais acl Safe_ports port 1025-65535 # unregistered ports acl Safe_ports port 280 # http-mgmt acl Safe_ports port 488 # gss-http acl Safe_ports port 591 # filemaker acl Safe_ports port 777 # multiling http acl CONNECT method CONNECT sslproxy_cert_error allow all #disable this in production, it is dangerous but useful for testing sslproxy_flags DONT_VERIFY_PEER # # Recommended minimum Access Permission configuration: # # Deny requests to certain unsafe ports http_access deny !Safe_ports # Deny CONNECT to other than secure SSL ports http_access deny CONNECT !SSL_ports # Only allow cachemgr access from localhost http_access allow localhost manager http_access deny manager # We strongly recommend the following be uncommented to protect innocent # web applications running on the proxy server who think the only # one who can access services on "localhost" is a local user #http_access deny to_localhost # # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS # # Example rule allowing access from your local networks. # Adapt localnet in the ACL section to list your (internal) IP networks # from where browsing should be allowed http_access allow localnet http_access allow localhost # And finally deny all other access to this proxy http_access deny all # Squid normally listens to port 3128 http_port 3128 # Uncomment and adjust the following to add a disk cache directory. #cache_dir ufs /var/cache/squid 100 16 256 # Leave coredumps in the first cache dir coredump_dir /var/cache/squid http_port x.x.x.x:3129 ssl-bump \ cert=/etc/squid/ssl_cert/myCA.pem \ generate-host-certificates=on dynamic_cert_mem_cache_size=4MB #this is what generates certs on the fly. Point to the CA you generated above. https_port x.x.x.x:3130 ssl-bump intercept \ cert=/etc/squid/ssl_cert/myCA.pem \ generate-host-certificates=on dynamic_cert_mem_cache_size=4MB acl step1 at_step SslBump1 ssl_bump peek step1 ssl_bump stare all ssl_bump bump all always_direct allow all # # Add any of your own refresh_pattern entries above these. # refresh_pattern ^ftp: 1440 20% 10080 refresh_pattern ^gopher: 1440 0% 1440 refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 refresh_pattern . 0 20% 4320

使用操作系统提供的命令启动squid服务。确保/var/log/squid中没有错误

你可以使用以下命令:

sudo netstat -peant | grep ":3130"

以确保squid已经成功地连接到端口。

此命令需要在每次启动时应用到NAT流量,该流量将被路由到IP上的端口443(在您的原始设备上使用静态路由y.y.y)。y或上一个网络组件)监听到的乌贼正在监听另一个NIC绑定到的乌贼(x.x.x.x)

iptables -t nat -I PREROUTING -p tcp --dport y.y.y.y:443 -j DNAT --to x.x.x.x:3130

假设客户机信任根证书,squid代理将透明地代理所有发送到出站的连接。

原文:https://www.ssltrust.com.au/help/setup-guides/setup-squid-proxy

本文:https://pub.intelligentx.net/setup-squid-forward-proxy

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-11-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 首席架构师智库 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 「技术架构」设置Squid转发代理或者正向代理
相关产品与服务
SSL 证书
腾讯云 SSL 证书(SSL Certificates)为您提供 SSL 证书的申请、管理、部署等服务,为您提供一站式 HTTPS 解决方案。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档