我使用squid作为SSL Bump截取的透明代理。
Squid的HTTP和HTTPS端口configuration是:
http_port 3127 transparent https_port 3129 intercept ssl-bump generate-host-certificates=on cert=/opt/squid/ssl_cert/cert.crt key=/opt/squid/ssl_cert/cert.key options=NO_SSLv2,NO_SSLv3
我写了下面的URL程序来强制安全searchGoogle和duckduckgo:
#!/usr/bin/perl use strict; use URI::URL; # Turn off buffering to STDOUT $| = 1; # Read from STDIN while (<STDIN>) { # Do some trimming s/^\s*//; s/\s*$//; my $string = $_; # Google Safe search if ($string =~ m/^http(s?)\:\/\/([az]+\.)?google\.([az]{2,3})(\.[az]{2,3})?\/.*(\?(as_)?q=)|(\#(as_)?q=)|(\&(as_)?q=)/) { #print "OK rewrite-url=\"$string", "&safe=active\""; if ($string !~ m/&safe=active/) { print "OK url=\"$string", "&safe=active\""; print "\n"; } else { print "OK\n"; } } # Duckduckgo safe search elsif ($string =~ m/^http(s?)\:\/\/([az]+\.)?duckduckgo\.([az]{2,3})(\.[az]{2,3})?/) { #print "OK rewrite-url=\"$string", "&kp=1\""; if ($string !~ m/&kp=1/) { print "OK url=\"$string", "&kp=1\""; print "\n"; } else { print "OK\n"; } } # If no one match, url still intact else { print "ERR\n"; } }
在鱿鱼configuration我添加下面的行:
url_rewrite_program /opt/squid/bin/url_rewriter
在CLI中进行testing时,url_rewriter可以很好地重写URL:
./url_rewriter https://www.google.fr/?q=test OK url="https://www.google.fr/?q=test&safe=active" https://www.duckduckgo.com/ OK url="https://www.duckduckgo.com/&kp=1"
它在浏览器中工作得很好,只是在查询中squid总是添加LAN IP,用户名和squid端口。 例如,它将其添加到查询中:
"%20192.168.1.18/192.168.1.18%20benoit%20GET%20myip=-%20myport=3129"
对于谷歌我得到这个:
https://www.google.fr/?q=test%20192.168.1.18/192.168.1.18%20benoit%20GET%20myip=-%20myport=3129&safe=active
代替 :
https://www.google.fr/?q=test&safe=active
对于duckduckgo,我明白了
https://duckduckgo.com/%20192.168.1.18/192.168.1.18%20benoit%20GET%20myip=-%20myport=3127&kp=1
代替 :
https://duckduckgo.com/&kp=1
为什么我有这种行为? 我错过了什么 ? 如果需要,我可以发布更多的configuration。
是的,你错过了一个小细节。 稍后,squid不会添加myip =等东西,但在将url发送到重写器之前。 这意味着你必须在将它交给鱿鱼之前将其移走。
不是所有版本的squid都这么做,但是它被logging到3.4版本
TomTomTom
我自己find了解决scheme。
是的,我错过了给鱿鱼的版本,这是我的情况的一个重要的信息。 我使用版本3.5.20
有一个来自squid 3.5的名为url_rewrite_extras的新指令
http://www.squid-cache.org/Doc/config/url_rewrite_extras/
默认情况下,在使用URL-rewriter / redirector helper程序时,在每个查询中添加: “%> a /%> A%un%> rm myip =%la myport =%lp” 。
所以我添加了这个选项来覆盖这个值。 我不得不设置一个空间作为值,因为url_rewrite_extras“”添加一个破折号“ – ”来查询。
url_rewrite_extras " " url_rewrite_program /opt/squid/bin/url_rewriter