We are living in a world that depends too much on the internet. The number of devices that are internet-connected increased steadily in the recent decade. As the availability of the internet improved, the risk associated with online services also increased. Daily we are hearing news about hacking and data breaches happening all around the world. We know that when the computer network expands there is a high chance of data breaches happening. In this modern world, a proxy server can help us to prevent some of these malicious attacks and thereby safeguarding our critical devices and data.
Proxy server is an intermediate device that is placed between the internet and the user's computer. This device can make requests on behalf of the user. The destination devices receive this request as usual but that device can only see the IP address of the proxy server and not the IP address of our computer. This masking is one of the important features of a proxy server. Apart from this, there are some useful features they provide. They are listed below
Features of a Proxy Server
Masks the client's IP address and location details from the server.
Prevent hacking attacks
Prevent tracking of devices
We can blacklist or whitelist particular URLs/Websites.
makes our internal private network secure.
Can cache frequently access data to make connections faster.
Normally when a client requests a resource (webpage or a website) the request will be directly sent from our device to the destination server. The destination server can see the IP of the client and even know the location from where the request is made. The destination server then servers the request and provide the necessary resource back to the client.
When a proxy server is added between them, the client's request will go to the proxy server first, in the proxy server, check its defined rules to determine whether the URL is in blocked or not, If not blocked it will send the request to the destination server. From the server end, it can only see the IP address of the proxy server. The same is in the case of return traffic from the server to the client.
Requirements
Linux ( Redhat/Ubuntu or any supporting distribution)
Squid package
Squid is a web proxy that can be used for caching and blocking web traffic. It is used in organizations to block websites that are restricted to access by the organization. They are also used in schools to filter web traffic.
Use case: Squid is used in colleges and schools to block social media and adult sites. When these URLs are accessed by the client proxy can keep the log and also display customized error or warning messages.
Installation
Install the squid package .
apt-get install squid -y
Once installed start and enable the service to run at start up.
systemctl start squid
systemctl enable squid
You can check the status of squid by running the command
systemctl status squid
Output will look similar to this
● squid.service - Squid Web Proxy Server
Loaded: loaded (/lib/systemd/system/squid.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-10-07 07:59:05 UTC; 30s ago
Docs: man:squid(8)
Main PID: 1275 (squid)
Tasks: 4 (limit: 2353)
Memory: 16.0M
CGroup: /system.slice/squid.service
├─1275 /usr/sbin/squid -sYC
├─1277 (squid-1) --kid squid-1 -sYC
├─1280 (logfile-daemon) /var/log/squid/access.log
└─1298 (pinger)
To verify the version details of squid run the below command
squid -v
Initial Configuration
The Squid configuration file is found at /etc/squid/squid.conf.
Open this file in your text editor
sudo nano /etc/squid/squid.conf
Navigate to find the http_port option. Typically, this is set to listen on Port 3218. This port usually carries TCP traffic. If your system is configured for traffic on another port, change it here.
You may also set the proxy mode to transparent if you’d like to prevent Squid from modifying your requests and responses.
http_port 1234 transparent
Navigate to the http_access deny all option and change it to
http_access allow all
Navigate to the visible_hostname option. Add any name you’d like to this entry. This is how the server will appear to anyone trying to connect. Save the changes and exit.
Restart squid server
sudo systmctl restart squid
Testing our Proxy
Open the proxy setting windows in client machine.In windows it will be under Network and setting and add the proxy server name and port ( same name and port that we specified during configuration)
Go to : https://whatismyipaddress.com/ and check your IP address. If configuration is done correctly you can see the IP same as the IP of your proxy server. Now our client IP is masked and all requests will pass through proxy server.
We can also blacklist or whitelist URLs in Squid.
Open squid conf file for block list
sudo nano /etc/squid/blocked.acl
Add the URL to block starting with .
.facebook.com
.twitter.com
.instagram.com
Open the squid conf file and attach this ACL file to it
sudo nano /etc/squid/squid.conf
Add the following line
acl blocked_websites dstdomain “/etc/squid/blocked.acl”
http_access deny blocked_websites
Restart the server to reflect the change
sudo systemctl restart squid
Till now we configured squid with out authentication, that means any one can sent traffic through our squid proxy. Now lets add authentication.
Install the required package to enable authentication
sudo apt-get install apache2-utils
Create a passwd file and change its ownership to proxy user
sudo touch /etc/squid/passwd
sudo chown proxy: etc/squid/passwd
Add new user to squid
sudo htpasswd /etc/squid/passwd newuser
Enter the password when prompt.
Open the squid conf file (/etc/squid/squid.conf) and all the following details to it
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm Squid Basic Authentication
auth_param basic credentialsttl 2 hours
acl auth_users proxy_auth REQUIRED
http_access allow auth_usersCopied!
Restart the service
sudo systemctl restart squid
We have successfully deployed a Squid proxy with Authentication. You can verify the working by accessing a blocked website for example, facebook.com or instagram.com. You will see the access getting blocked.
Proxy servers are useful to prevent hacking and security threats. It can help our machine to become more secure by acting as an interface between us and the internet. Proxies also helps to block web traffics and hide out identity from out side internet. It is always recommended to use proxy servers when visiting unknown URLs so that even if an attack occur, it cannot affect our machine because we are staying safely behind the proxy server.