SQUID ( Transparent + SquidGuard + HTTPS filtering) CentOS 6.5

Don’t forget to set your server as router between your networks

#sysctl -w net.ipv4.ip_forward=1 #you can find this file under /etc

#iptables -t nat -A POSTROUTING -o eth0 -j MASQUERDE #this is going to hide your internal ip address and present all packages as eth0 interface.

 

INSTALL SQUID

# yum install squid

INSTALL EPEL Redhat 6

# wget https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

# sudo rpm -Uvh epel-release-6*.rpm

 

INSTALL EPEL Redhat 7

# wget https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-1.noarch.rpm

# sudo rpm -Uvh epel-release-7*.rpm

Install SquidGuard

# yum install squidGuard

 

iptables configuration

#iptables -t nat -A PREROUTING -i eth1 -p tcp –dport 80 -J DNAT –to 192.168.3.1 :8080

#192.168.3.1 is the gatways interface for my LAN ====> eth1

# iptables -t filter -A INPUT -p tcp –dport 8080 -j ACCEPT

# netstat -ant

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 192.168.3.1:53 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN

tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN

tcp 0 0 192.168.3.1:8080 0.0.0.0:* LISTEN

tcp 0 0 192.168.1.9:22 192.168.3.5:57801 ESTABLISHED

tcp 0 64 192.168.1.9:22 192.168.1.149:51888 ESTABLISHED

tcp 0 0 192.168.1.9:22 192.168.3.5:57707 ESTABLISHED

tcp 0 0 :::22 :::* LISTEN

tcp 0 0 ::1:953 :::* LISTEN

tcp 0 0 ::1:25 :::* LISTEN

Review your logs

# tail -f /var /log/squid/access.log

1419230802.496 0 192.168.3.5 TCP_DENIED/403 3855 GET https://www.squid-cache.org/Artwork/SN.png – NONE/- text/html

1419230802.505 0 192.168.3.5 TCP_DENIED/403 4166 GET https://www.google.com/favicon.ico – NONE/- text/html

1419230802.557 0 192.168.3.5 TCP_DENIED/403 4296 POST https://safebrowsing.clients.google.com/safebrowsing/downloads? – NONE/- text/html

1419231063.959 1 192.168.3.5 TCP_DENIED/403 4061 GET https://www.google.com/ – NONE/- text/html

1419231063.985 0 192.168.3.5 TCP_DENIED/403 3855 GET https://www.squid-cache.org/Artwork/SN.png – NONE/- text/html

At this point all http traffic should go through port 8080. We are going to set squidGuard in order to do some filtering.

 

Let’s continue with SquidGuard

  1. Go to # cd /var/squidGuard/
  2. Download # wget https://www.shallalist.de/Downloads/shallalist.tar.gz
  3. # tar –zxvf shallalist.tar.gz
  4. # rename the forlder to blacklist
  5. Change the ownership to squid:squid blacklist
  6. # vi /etc/ dbhome /var/squidGuard/blacklist
  7. logdir /var/log/squidGuard

    ++++++++

    dest porn {

    domainlist porn/domains

    urllist porn/urls

    }

    dest socialnet {

    domainlist socialnet/domains

    urllist socialnet/urls

    }

     

    acl {

    default {

    pass !porn !socialnet any

    redirect https://www.google.com

    }

    }

    ++++++++++

  8. Add the following line to squid.conf

    redirect_program /usr/bin/squidGuard -c /etc/squid/squidGuard.conf

     

  9. Make sure that permission are allowed for user and group squid on

/var/log/squidGuard/squidGuard.log

 

-rw-r–r–. 1 squid squid 68716 Dec 28 03:36 squidGuard.log

    10) run the command# squidGuard -b -d -C all

# squidGuard -b -d -C all

# chown -R squid:squid /var/squidGuard/blacklist

  1. Tail –f /var/log/squidGuard/squidGuard.log

     

  2. 2014-12-28 03:36:01 [3693] loading dbfile /var/squidGuard/blacklist/porn/urls.db

    2014-12-28 03:36:01 [3693] squidGuard 1.4 started (1419766561.351)

    2014-12-28 03:36:01 [3693] squidGuard ready for requests (1419766561.352)

 

Let’s begging filtering HTTPS content

First with have to install the following package

# yum install openssl openssl-devel

#yum install perl-Crypt-OpenSSL-X509

# cd /etc/squid/

# openssl req -new -newkey rsa:1024 -days 365 -nodes -x509 -keyout myconfigure.pem -out myconfigure.pem

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

We have to modify /etc/squid.conf

# vi /etc/squid/squid.conf

Note: Actually this is my final file include (transparent proxy, squidGuard and ssl_bump)

+++++++++++

#acl manager proto cache_object

#acl localhost src 127.0.0.1/32 ::1

#acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

acl localnet src 192.168.3.0/24 # RFC1918 possible internal network

 

visible_hostname monitor.mrwhitebp.com

cache_mem 64 MB

maximum_object_size_in_memory 64 KB

maximum_object_size 512 MB

minimum_object_size 0 KB

cache_swap_low 80

cache_swap_high 90

cache_dir ufs /var/spool/squid 512 16 256

cache_access_log /var/log/squid/access.log

 

 

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

 

## ACL definition ##

acl custom-denied-list src “/etc/squid/custom-denied-list-file”

acl custom-block-site url_regex “/etc/squid/custom-block-website-file”

acl extensions url_regex -i \.avi \.exe \.mp3 \.torrent \.wav

 

## ACL application ##

http_access deny custom-denied-list custom-block-site

http_access allow localhost

#http_access deny manager

http_access deny extensions

http_access deny !Safe_ports

http_access deny CONNECT !SSL_ports

http_access allow localnet

http_access allow localhost

http_access deny all

redirect_program /usr/bin/squidGuard -c /etc/squid/squidGuard.conf

http_port 192.168.3.1:8080 intercept

https_port 192.168.3.1:8081 intercept ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=4MB cert=/etc/squid/mycert_squid.pem key=/etc/squid/mycert_squid.pem

#always_direct allow all

ssl_bump server-first all

#sslproxy_cert_error deny all

#sslproxy_flags DONT_VERIFY_PEER

sslcrtd_program /usr/lib64/squid/ssl_crtd -s /var/lib/ssl_db -M 4MB

sslcrtd_children 8 startup=1 idle=1

hierarchy_stoplist cgi-bin ?

coredump_dir /var/spool/squid

refresh_pattern ^ftp: 1440 20% 10080

refresh_pattern ^gopher: 1440 0% 1440

refresh_pattern -i (/cgi-bin/|\?) 0 0% 0

refresh_pattern . 15 20% 1140

+++++++++

Finally we have to modify Iptables: I’m going to add my iptables file

+++++++++

# Generated by iptables-save v1.4.7 on Sun Dec 21 22:06:35 2014

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [677:85081]

-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state –state NEW -m tcp –dport 22 -j ACCEPT

-A INPUT -p tcp -m state –state NEW -m tcp –dport 53 -j ACCEPT

-A INPUT -p tcp -m state –state NEW -m tcp –dport 8080 -j ACCEPT

-A INPUT -p tcp -m state –state NEW -m tcp –dport 8081 -j ACCEPT

-A INPUT -p udp -m state –state NEW -m udp –dport 53 -j ACCEPT

-A INPUT -p udp -m state –state NEW -m udp –dport 67 -j ACCEPT

-A INPUT -j REJECT –reject-with icmp-host-prohibited

-A FORWARD -i eth0 -o eth1 -m state –state RELATED,ESTABLISHED -j ACCEPT

-A FORWARD -i eth1 -o eth0 -j ACCEPT

-A FORWARD -j REJECT –reject-with icmp-host-prohibited

COMMIT

# Completed on Sun Dec 21 22:06:35 2014

# Generated by iptables-save v1.4.7 on Sun Dec 21 22:06:35 2014

*nat

:PREROUTING ACCEPT [42:3995]

:POSTROUTING ACCEPT [5:335]

:OUTPUT ACCEPT [18:1196]

-A PREROUTING -i eth1 -p tcp -m tcp –dport 80 -j DNAT –to-destination 192.168.3.1:8080

-A PREROUTING -i eth1 -p tcp -m tcp –dport 443 -j DNAT –to-destination 192.168.3.1:8081

-A POSTROUTING -o eth0 -j MASQUERADE

COMMIT

+++++++++++

 

References

https://serverfault.com/questions/610232/how-to-setup-client-for-squid-transparent-proxy

https://www.squidguard.org/Doc/