Deploying Squid Proxy in PFSense - Installation and Configuration Process

In the previous article, we explained how to install a Bind DNS server in PFSense. The results are very satisfying, internet speed can increase, because Bind is able to perform DNS caching in its internal database. In this article, we will explain how to install and setup Squid Proxy. The aim is none other than to increase internet access speed, especially when you access a web browser such as YouTube, Google, Microsoft, Netflix and others.

As we know, Squid is the best proxy application currently. Almost all computer users trust Squid to proxy ports 80 and 443. Not only that, Squid's features are also very complete. You can set up authentication for anyone who can access your Squid PFSense. Apart from that, anti-virus features such as clamav are also available on Squid Proxy.

Squid is also able to block sites that you don't want. Squid's blocking ability is beyond doubt and is capable of blocking thousands or even hundreds of prohibited sites. There are many benefits of Squid, but the benefit that you can feel directly is that it can improve internet access, because Squid can store all the data from the sites you have accessed. So, when you reopen the site, Squid can immediately serve the request from its database.


1. Create CA Certificates

In this article we will setup Squid proxy for HTTP and HTTP ports. Therefore, Squid proxy requires a CA certificate when configuring Squid proxy. In this article we will demonstrate how to create a CA certificate with the name "LANNetworks".

To create a LANNetworks certificate, click System ->> Certificates, then in the "Authorities" option click the "Add" button. Please fill in the columns according to the following image.





2. Install Squid Proxy package

Same as other applications, the Squid proxy package is available in the PFSense repository, you can install it directly. To start installing Squid proxy, click System ->> Package Manager ->> Available Packages. Search for the Squid package and just click the Install button. Wait until the installation process is complete.

After that, continue by setting up the Squid proxy, click Services ->> Squid Proxy Server. Select Local Cache, in the "Custom refresh_patterns" option, type the script below and immediately click the button (other options just leave the default).

Script Custom refresh_patterns
refresh_pattern -i windowsupdate.com/.*\.(cab|exe|ms[i|u|f|p]|[ap]sf|wm[v|a]|dat|zip|psf) 43200 80% 129600 reload-into-ims
refresh_pattern -i microsoft.com/.*\.(cab|exe|ms[i|u|f|p]|[ap]sf|wm[v|a]|dat|zip|psf) 43200 80% 129600 reload-into-ims
refresh_pattern -i windows.com/.*\.(cab|exe|ms[i|u|f|p]|[ap]sf|wm[v|a]|dat|zip|psf) 43200 80% 129600 reload-into-ims
refresh_pattern -i microsoft.com.akadns.net/.*\.(cab|exe|ms[i|u|f|p]|[ap]sf|wm[v|a]|dat|zip|psf) 43200 80% 129600 reload-into-ims
refresh_pattern -i deploy.akamaitechnologies.com/.*\.(cab|exe|ms[i|u|f|p]|[ap]sf|wm[v|a]|dat|zip|psf) 43200 80% 129600 reload-into-ims


We continue by clicking the "General" option, fill in according to the example below.

Squid General Settings:

Enable Squid Proxy: Check
Keep Settings/Data: Check
Listen IP Version: IPv4
CARP Staus VIP: none
Proxy Interface(s): LAN
Outgoing Network Interface: LAN
PRoxy Port: 3128
ICP Port:
Allow Users on Interface: Check
Patch Captive Portal:
Resolve DNS IPv4 First: Check
Disable ICMP: UnCheck
Use Alternate DNS Server for the PRoxy Server: 192.168.7.1; 1.1.1.1
Extra Trusted CA: LANNetworks

Transparent Proxy Settings

Transparent HTTP Proxy: Check
Transparent Proxy Interface(s): LAN
Bypass Proxy for Private Address Destination: UnCheck
Bypass Proxy for These Source IPs:
Bypass Proxy for These Destination IPs:

SSL Man In the Middle Filtering

HTTPS/SSL Interception: Check
SSL/MITM Mode: Custom
SSL Intercept Interface(s): LAN
SSL Proxy Port: 3129
SSL Proxy Compatibility Mode: Modern
DHParams Key Size: 2048 (default)
CA: LANNetworks
SSL Certificate Deamon Children: 5
Remote Cert Checks:
Certificate Adapt:

Logging Settings

Enable Access Logging: Check
Rotate Logs: 15
Log Pages Denied by Squidguard: Uncheck

Headers Handling, Language and Other Customizations

Visible Hostname: ns5.kursor.my.id
Administrator's Email: datainchi@gmail.com
Error Language: en
X-Forwarded Header Mode: (on)
Disable VIA Header: UnCheck
URI Whitespace Characters Handling: strip
Suppress Squid Version: UnCheck

Advanced Features

Integrations:
Custom Options (Before Auth):
Custom Options (After Auth):
Custom Options (SSL/MITM):
acl splice_it ssl::server_name .microsoft.com
acl splice_it ssl::server_name .windowsupdate.com
acl splice_it ssl::server_name .akamaitechnologies.com
acl splice_it ssl::server_name .akadns.net
acl splice_it ssl::server_name .google.com
acl step1 at_step SslBump1
ssl_bump peek step1
ssl_bump splice splice_it
ssl_bump bump all


3. Setup NAT Port Forward Squid Proxy

The purpose of creating "NAT Port Forward" is so that all clients connecting to your PFSense server are directly redirected to ports 3128 and 3129, namely the Squid proxy ports for HTTP and HTTPS. We will create 2 Port Forward NATs:
  1. Port Forward for HTTP, and
  2. Port Forward for HTTPS
OK, let's just start creating NAT Port Forward for Squid proxy, how to click Firewall ->> NAT. In the "Port Forward" option, click the "Add" button, to fill in NAT Port Forward, follow the image instructions below.

a. Port Forward for HTTP redirect to 3128



b. Port Forward for HTTPS redirect to 3129




4. Example of Squid Proxy generated by PFSense

Every action you take when configuring Squid proxy, PFSense will automatically save the configuration in a script. The Squid configuration file script is stored in the /usr/local/etc/squid directory. You can see all the Squid proxy files in that directory. The main configuration file of Squid proxy is named "squid.conf", below is an example script /usr/local/etc/squid/squid.conf.

Script /usr/local/etc/squid/squid.conf
# This file is automatically generated by pfSense
# Do not edit manually !

http_port 192.168.7.1:3128 ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=10MB cert=/usr/local/etc/squid/serverkey.pem cafile=/usr/local/share/certs/ca-root-nss.crt capath=/usr/local/share/certs/ cipher=EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA+RC4:EECDH:EDH+aRSA:!RC4:!aNULL:!eNULL:!LOW:!3DES:!SHA1:!MD5:!EXP:!PSK:!SRP:!DSS tls-dh=prime256v1:/etc/dh-parameters.2048 options=NO_SSLv3,NO_TLSv1,SINGLE_DH_USE,SINGLE_ECDH_USE

http_port 127.0.0.1:3128 intercept ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=10MB cert=/usr/local/etc/squid/serverkey.pem cafile=/usr/local/share/certs/ca-root-nss.crt capath=/usr/local/share/certs/ cipher=EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA+RC4:EECDH:EDH+aRSA:!RC4:!aNULL:!eNULL:!LOW:!3DES:!SHA1:!MD5:!EXP:!PSK:!SRP:!DSS tls-dh=prime256v1:/etc/dh-parameters.2048 options=NO_SSLv3,NO_TLSv1,SINGLE_DH_USE,SINGLE_ECDH_USE

https_port 127.0.0.1:3129 intercept ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=10MB cert=/usr/local/etc/squid/serverkey.pem cafile=/usr/local/share/certs/ca-root-nss.crt capath=/usr/local/share/certs/ cipher=EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA+RC4:EECDH:EDH+aRSA:!RC4:!aNULL:!eNULL:!LOW:!3DES:!SHA1:!MD5:!EXP:!PSK:!SRP:!DSS tls-dh=prime256v1:/etc/dh-parameters.2048 options=NO_SSLv3,NO_TLSv1,SINGLE_DH_USE,SINGLE_ECDH_USE

tcp_outgoing_address 192.168.7.1
icp_port 0
digest_generation off
dns_v4_first on
pid_filename /var/run/squid/squid.pid
cache_effective_user squid
cache_effective_group proxy
error_default_language en
icon_directory /usr/local/etc/squid/icons
visible_hostname ns5.kursor.my.id
cache_mgr datainchi@gmail.com
access_log /var/squid/logs/access.log
cache_log /var/squid/logs/cache.log
cache_store_log none
netdb_filename /var/squid/logs/netdb.state
pinger_enable on
pinger_program /usr/local/libexec/squid/pinger
sslcrtd_program /usr/local/libexec/squid/security_file_certgen -s /var/squid/lib/ssl_db -M 4MB -b 2048
tls_outgoing_options cafile=/usr/local/share/certs/ca-root-nss.crt
tls_outgoing_options capath=/usr/local/share/certs/
tls_outgoing_options options=NO_SSLv3,NO_TLSv1,SINGLE_DH_USE,SINGLE_ECDH_USE
tls_outgoing_options cipher=EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA+RC4:EECDH:EDH+aRSA:!RC4:!aNULL:!eNULL:!LOW:!3DES:!SHA1:!MD5:!EXP:!PSK:!SRP:!DSS
sslcrtd_children 5

logfile_rotate 15
debug_options rotate=15
shutdown_lifetime 3 seconds
# Allow local network(s) on interface(s)
acl localnet src  192.168.7.0/24
forwarded_for on
uri_whitespace strip
dns_nameservers 192.168.7.1 1.1.1.1 
refresh_pattern -i windowsupdate.com/.*\.(cab|exe|ms[i|u|f|p]|[ap]sf|wm[v|a]|dat|zip|psf) 43200 80% 129600 reload-into-ims
refresh_pattern -i microsoft.com/.*\.(cab|exe|ms[i|u|f|p]|[ap]sf|wm[v|a]|dat|zip|psf) 43200 80% 129600 reload-into-ims
refresh_pattern -i windows.com/.*\.(cab|exe|ms[i|u|f|p]|[ap]sf|wm[v|a]|dat|zip|psf) 43200 80% 129600 reload-into-ims
refresh_pattern -i microsoft.com.akadns.net/.*\.(cab|exe|ms[i|u|f|p]|[ap]sf|wm[v|a]|dat|zip|psf) 43200 80% 129600 reload-into-ims
refresh_pattern -i deploy.akamaitechnologies.com/.*\.(cab|exe|ms[i|u|f|p]|[ap]sf|wm[v|a]|dat|zip|psf) 43200 80% 129600 reload-into-ims

cache_mem 64 MB
maximum_object_size_in_memory 256 KB
memory_replacement_policy heap GDSF
cache_replacement_policy heap LFUDA
minimum_object_size 0 KB
maximum_object_size 4 MB
cache_dir ufs /var/squid/cache 100 16 256
offline_mode off
cache_swap_low 90
cache_swap_high 95
cache 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


#Remote proxies


# Setup some default acls
# ACLs all, manager, localhost, and to_localhost are predefined.
acl allsrc src all
acl safeports port 21 70 80 210 280 443 488 563 591 631 777 901 8282 3128 3129 1025-65535 
acl sslports port 443 563 8282 

acl purge method PURGE
acl connect method CONNECT

# Define protocols used for redirects
acl HTTP proto HTTP
acl HTTPS proto HTTPS

# SslBump Peek and Splice
# http://wiki.squid-cache.org/Features/SslPeekAndSplice
# http://wiki.squid-cache.org/ConfigExamples/Intercept/SslBumpExplicit
# Match against the current step during ssl_bump evaluation [fast]
# Never matches and should not be used outside the ssl_bump context.
#
# At each SslBump step, Squid evaluates ssl_bump directives to find
# the next bumping action (e.g., peek or splice). Valid SslBump step
# values and the corresponding ssl_bump evaluation moments are:
#   SslBump1: After getting TCP-level and HTTP CONNECT info.
#   SslBump2: After getting TLS Client Hello info.
#   SslBump3: After getting TLS Server Hello info.
# These ACLs exist even when 'SSL/MITM Mode' is set to 'Custom' so that
# they can be used there for custom configuration.
acl step1 at_step SslBump1
acl step2 at_step SslBump2
acl step3 at_step SslBump3
http_access allow manager localhost

http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !safeports
http_access deny CONNECT !sslports

# Always allow localhost connections
http_access allow localhost

quick_abort_min 0 KB
quick_abort_max 0 KB
request_body_max_size 0 KB
delay_pools 1
delay_class 1 2
delay_parameters 1 -1/-1 -1/-1
delay_initial_bucket_level 100
delay_access 1 allow allsrc

# Reverse Proxy settings


# Custom options before auth


# Custom SSL/MITM options before auth
acl splice_it ssl::server_name .microsoft.com
acl splice_it ssl::server_name .windowsupdate.com
acl splice_it ssl::server_name .akamaitechnologies.com
acl splice_it ssl::server_name .akadns.net
acl splice_it ssl::server_name .google.com
acl step1 at_step SslBump1
ssl_bump peek step1
ssl_bump splice splice_it
ssl_bump bump all

# Setup allowed ACLs
# Allow local network(s) on interface(s)
http_access allow localnet
# Default block all to be sure
http_access deny allsrc
There are many features of Squid proxy, you can increase the advantages and benefits of Squid proxy by activating these features. This article is just a basic configuration of Squid proxy, you can read other articles to experience more benefits from Squid proxy.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post