Perfect Squid with Transparent proxy and SSL log Rumi, September 5, 2017September 5, 2017 This will be a transparent SQUID proxy for your home or corporate network , it will transparently intercept all traffic http and https , for https you will need to push to clients the CA certificate of the SQUID server, it has been tested to be working without problems with lastest Internet Explorer, Mozilla Firefox and Chrome browsers. STEP 1 – Installing Base system , upgrading it and disabling IPtables , SeLINUX We start by downloading the CentOS 6.5 iso from CentOS website (x86 or x64) : CentOS 6.5 ISO’s , install Base system. Partitioning , software or hardware raid is up to the user. In this example hostname is : proxy.home.lan and ip address is : 192.168.201.250 . chkconfig iptables off chkconfig ip6tables off vi /etc/selinux/config Press i , look for SELINUX= line and change it to SELINUX=disabled Once you are done editing press ESC , then type :wq then pres ENTER. Type into console : reboot Once the system is rebooted , type into console : yum upgrade STEP 2 – Enable EPEL repo, install SQUID CentOS provided SQUID does not have ssl_crtd for some reason, thus it cannot be configured to generate certificates for https sites. Type the following into console : cd /home wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -Uvh epel-release-6.8.noarch.rpm cd /etc/yum.repos.d vi SQUID.repo Enter the following text into this file : [Squid] name=SQUID repo for CentOS Linux 6 - $basearch #IL mirror baseurl=http://www1.ngtech.co.il/rpm/centos/6/i686 failovermethod=priority enabled=1 gpgcheck=0 Once done we update the system again and install SQUID, type into terminal : yum update yum install perl-Crypt-OpenSSL-X509 yum install squid Now we initialize SQUID ssl_db directory , type this into console : /usr/lib/squid/ssl_crtd -c -s /var/lib/ssl_db chown -R squid.squid /var/lib/ssl_db * On the above state- I encountered problem, so had to do some tweaking, First remove Squid and re-install using squid-helpers yum remove squid yum install squid-helpers Finally we edit our Squid config file to look like this : /etc/squid/squid.conf acl localnet src 192.168.201.0/24 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 http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access allow all http_port 3130 http_port 3128 intercept https_port 3129 intercept ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=4MB cert=/etc/squid/ssl_cert/myca.pem key=/etc/squid/ssl_cert/myca.pem #always_direct allow all ssl_bump server-first all #sslproxy_cert_error deny all #sslproxy_flags DONT_VERIFY_PEER sslcrtd_program /usr/lib/squid/ssl_crtd -s /var/lib/ssl_db -M 4MB sslcrtd_children 8 startup=1 idle=1 coredump_dir /var/spool/squid # 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 shutdown_lifetime 1 second STEP 3 – Generate Certificate for SQUID using OpenSSL We will first edit our /etc/pki/tls/openssl.conf file , and alter only the following default_days = 1365 # How long to certify for ... [ req_distinguished_name ] countryName = Country Name (code) countryName_default = DE countryName_min = 2 countryName_max = 2 stateOrProvinceName = State or Province Name (full name) stateOrProvinceName_default = NRW localityName = Locality Name (eg, city) localityName_default = Paderborn 0.organizationName = Organization Name (eg, company) 0.organizationName_default = Home.LAN # we can do this but it is not needed normally :-) #1.organizationName = Second Organization Name (eg, company) #1.organizationName_default = World Wide Web Pty Ltd organizationalUnitName = Organizational Unit Name (eg, section) organizationalUnitName_default = Proxy Server commonName = Common Name (eg, your name or your server's hostname) # (Very Important, in order to keep mail clients and other user agents from complaining, this name must # match exactly the name that the user will be entering into their client settings. Whether that be # domain.extension or mail.domain.extension or what. It must be a valid DNS name pointing at your # server. commonName_default = proxy.home.lan # this line you need to add commonName_max = 64 emailAddress = Email Address emailAddress_default = robert@proxy.home.lan # this line you need to add emailAddress_max = 64 Once this is done we go to SQUID directory , create the certificate folder and generate the keys : mkdir /etc/squid/ssl_cert chown -R squid.squid /etc/squid/ssl_cert cd /etc/squid/ssl_cert For SQUID server the key : openssl req -new -newkey rsa:1024 -days 1365 -nodes -x509 -keyout myca.pem -out myca.pem For Windows clients the key : openssl x509 -in myca.pem -outform DER -out myca.der STEP 4 – install our own DNS server Enter the following into console : yum install bind Then we go and modify the /etc/named.conf to look like this : // // named.conf // // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS // server as a caching only nameserver (as a localhost DNS resolver only). // // See /usr/share/doc/bind*/sample/ for example named configuration files. // acl mynet { 192.168.201.0/24; # test network 127.0.0.1; # localhost }; options { listen-on { mynet; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; allow-query { mynet; }; recursion yes; forward only; forwarders { 8.8.8.8; }; dnssec-enable yes; dnssec-validation yes; dnssec-lookaside auto; /* Path to ISC DLV key */ bindkeys-file "/etc/named.iscdlv.key"; managed-keys-directory "/var/named/dynamic"; }; logging { channel default_debug { file "data/named.run"; severity dynamic; }; }; zone "." IN { type hint; file "named.ca"; }; include "/etc/named.rfc1912.zones"; include "/etc/named.root.key"; ############################################# # home.lan ############################################# zone "home.lan" IN { type master; file "/var/named/home.lan/db.home"; allow-query { mynet; }; }; Type this into terminal : mkdir /var/named/home.lan touch /var/named/home.lan/db.home chown -R named.named /var/named/home.lan Then we add the following to the file /var/named/home.lan/db.home $ORIGIN home.lan. $TTL 86400 @ IN SOA proxy.home.lan. proxy.home.lan. ( 2014032801 ; Serial 28800 ; Refresh 7200 ; Retry 604800 ; Expire 86400 ; Negative Cache TTL ) @ IN NS proxy.home.lan. proxy IN A 192.168.201.250 Next we make sure that both SQUID and NAMED are automatically started every time we reboot. Type this into terminal : chkconfig squid on chkconfig named on /etc/init.d/named start /etc/init.d/squid start Then we alter /etc/resolv.conf to use local DNS server : search localdomain home.lan nameserver 127.0.0.1 Since we are issuing certificates with this machine it is highly recommended to sync it’s time with our internal NTP server or a external one. We can setup a cronjob for it like this : vi /home/timesync Then add the following into this file : 0 3,9,15,21 * * * /usr/sbin/ntpdate -u 134.130.4.17 And finally we add it to the crontab like this crontab /home/timesync This way it will sync the time regularely with our own internal or in this case with this external NTP server. STEP 5 – Redirect HTTP and HTTPS traffic on our router to Proxy On our router we add the following rules to IPtables : iptables -t nat -A PREROUTING -p tcp -s 192.168.201.0/24 --dport 80 -j DNAT --to 192.168.201.250:3128 iptables -t nat -A PREROUTING -p tcp -s 192.168.201.0/24 --dport 443 -j DNAT --to 192.168.201.250:3129 STEP 6 – Client Configuration We need to copy the /etc/squid/ssl_cert/myca.der file to our Windows clients , we can use WinSCP . Installation and configuration is straightforward so I wont go into detail here . For Internet Explorer : Tools -> Internet Options -> Content -> Certificates Click on Import , select myca.der file , make sure that you import to Root Trusted Certificates , close down the browser and try www.grc.com for example. For Mozilla Firefox : Tools-> Options-> Advanced -> Certificates – > View Certificates Import (x) Trust this CA to identify websites (x) Trust this CA to identify email users (x) Trust this CA to identify software developers Click OK you are done. For Google Chrome same as Internet Explorer. There’s a good tutorial on installing SARG a squid report generation program in perl. The link is below- https://www.clearos.com/clearfoundation/social/community/install-sarg-on-clearos-version-6-x-or-version-7-x-for-great-proxy-reports NOTE : If the main certificate expires for SQUID , and you generate a new one , don’t forget to delete the old certificates , /var/lib/ssl_db/certs also empty the file /var/lib/ssl_db/index.txt , and set the number inside the file /var/lib/ssl_db/size to 0 . Src: http://roberts.bplaced.net/index.php/linux-guides/centos-6-guides/proxy-server/squid-transparent-proxy-http-https https://serverfault.com/questions/680737/missing-ssl-crtd-folder-with-squid-3-5-2-centos Administrations Configurations (Linux) CentOSCentOS6proxysquid
Yhese are quick installation processes. SELinux most of the time does some protection where expected system might not work. For quick around, I usually disable it. ANywone who’d be using system for production grade, should keep it enable it. Thanks.