Implement HTTP/HTTPS Transparent Proxy with Safe Content Solution
Total Page:16
File Type:pdf, Size:1020Kb
Technical Paper: Linux Administration – Implement HTTP/HTTPS Transparent Proxy with Safe Content Solution IMPLEMENT HTTP/HTTPS TRANSPARENT PROXY WITH SAFE CONTENT SOLUTION Document Number: 002-001 Author: Javier Lagos Version: 0.6 Category: Linux Administration NOTES TO THE READERS All the experiences performed in this lab, has been done using the following software: O.S.: Ubuntu Server 16.04 LTS x64. Products: squid 3.5.28 (Proxy Cache), squidguard-1.5 (Safe Content Tool). This Paper has been created by Javier Lagos under Creative Commons License from https://jl-lib.seti-chile.cl. To contact the author, please send an email to: [email protected]. CONTENTS 1) Introduction 1.1 Concepts. 1.2 Goals. 2) Planing and Design. 2.1) Architecture. 2.2) Implementation Plan. 2.3) Testing Plan. 3) Implementation and Testing. 3.1) Pre-Implementation Tasks. 3.2) Implementation Tasks. 3.3) Post-Implementation Tasks. 3.4) Testing. 4) Conclusion. 5) References. 5.1) Sources. Document Number: 002-001 1 Technical Paper: Linux Administration – Implement HTTP/HTTPS Transparent Proxy with Safe Content Solution 1 INTRODUCTION One, 1 1.1 LOGICAL VOLUME MANAGER CONCEPTS LVM 1.2 LOGICAL VOLUME MANAGER CONCEPTS Document Number: 002-001 2 Technical Paper: Linux Administration – Implement HTTP/HTTPS Transparent Proxy with Safe Content Solution 2 PLANING AND DESIGN 2.1 ARCHITECTURE The Architecture Design for this Lab consist in one Server acting as a Router and Proxy/Content Safe Server that communicate The Internal Lab Network to Servers Farm/Internet. The Complete Flow for a device inside Lab Network to communicate to a web site in internet works as below: 1. Every Device inside “Lab Network”, send a http/https request from browser or any other application to "Proxy & Safe Content Server" through Router/Nat (Gateway) configured inside it. 2. The firewall rules configured on “Proxy & Safe Content Server” intercept any traffic through on port 80 (http) and 443 (https) and redirect them to Proxy Service on Ports 3128 (http) and 3129 (https). 3. Proxy Service (Squid) check incoming domain information sending nslookup request to “DNS Server”. If domain exist, Proxy Service send a request to Content Safe Service (squidGuard) to validate if domain is in Document Number: 002-001 3 Technical Paper: Linux Administration – Implement HTTP/HTTPS Transparent Proxy with Safe Content Solution the white (allowed) or black (denied) list. If domain doesn't exist, Proxy Service send an error page to browser. 4. Content Safe Service (squidGuard) validate domain in it internal database. If domain is allowed, will contact the target website, save related content of this in the Squid Cache and then send the content to the browser. If domain is not allowed, will return a denied error to browser. Document Number: 002-001 4 Technical Paper: Linux Administration – Implement HTTP/HTTPS Transparent Proxy with Safe Content Solution 2.2 IMPLEMENTATION PLAN Below is an Action Plan on what you need and what to do, to accomplish this project: 1. Network Definition 1.1 Two Network Cards. One will be exposed to “Servers Farms” and the second one will be exposed to “Lab Network”. (Check Diagram on Infrastructure Design). 1.2 IP and DNS definition on both Network Cards. On this Lab, I will use below details: NIC 1 (Exposed to Servers Farm): IP: 192.168.2.120/24 → leda.lab.seti-chile.org Gateway: 192.168.2.200 DNS1: 192.168.2.223 DNS2: 192.168.2.222 NIC 2 (Exposed to Lab Network): IP: 192.168.4.203/24 → leda-internal.lab.seti-chile.org DNS1: 192.168.2.223 DNS2: 192.168.2.222 2. Software and Dependencies 2.1 Download Squid Cache and SquidGuard Packages. 2.2 Solve Software Dependencies. 2.3 Create Dedicated Filesystem for SquidCache and SquidGuard. 2.4 Compile and install Squid Cache and SquidGuard. 3. Firewall and Routing Configuration 3.1 Set Forwarding and Redirection Rules. 4. Squid Cache Configuration 4.1 Set Port, Interception and SSL configuration. 4.2 Create Secure Certificate between Squid Cache and Browsers/End- Point Tools. 4.3 Create Swap/Cache Directories. Document Number: 002-001 5 Technical Paper: Linux Administration – Implement HTTP/HTTPS Transparent Proxy with Safe Content Solution 5. SquidGuard Configuration 5.1 Set Logging Configuration and ACL Groups using ShallaList Database. 5.2 Integrate SquidGuard into Squid Cache Configuration. 5.3 Build Safe Content Database. 6. Browser Configuration/Certificates 6.1 Import Certificates to Client Browsers and at OS Wallet on Windows and Linux Based Clients. 2.3 TESTING PLAN Below is an Action Plan in order to test and certify the implementation: 1. Test Internet Navigation through browser on http, https sites. Some examples: - https://www.google.com - https://www.yahoo.com - https://www.youtube.com - http://www.openbsd.org - http://www.mit.edu - http://www.apache.org Document Number: 002-001 6 Technical Paper: Linux Administration – Implement HTTP/HTTPS Transparent Proxy with Safe Content Solution 3 IMPLEMENTATION AND TESTING 3.1 PRE-IMPLEMENTATION TASKS NETWORK CONFIGURATION As mentioned in Planing chapter, in this lab we will use 2 Network Cards, one connected to Servers Farm and the other to Lab Network. Perform below changes on Ubuntu’s Network Configuration: 1. Into the server (leda.lab.seti-chile.org), edit file /etc/network/interfaces using to preferable editor. In our case vi: $ sudo vi /etc/network/interfaces # LOOPBACK auto lo iface lo inet loopback # PRIMARY ETHERNET auto eth0 iface eth0 inet static address 192.168.2.120 gateway 192.168.2.200 netmask 255.255.255.0 dns-nameservers 192.168.2.223 192.168.2.222 208.67.222.222 208.67.220.220 dns-search lab.seti-chile.org # SECONDARY ETHERNET auto eth1 iface eth1 inet static address 192.168.4.203 #gateway 192.168.4.200 netmask 255.255.255.0 pre-up iptables-restore < /etc/iptables/rules.v4 Note: “iptables-restore” belongs to iptables-persistent packages and is needed to store firewall rules. Will be used by Firewall to redirect http/https traffic to SquidCache service. 2. Edit /etc/hosts file as bellow: $ sudo vi /etc/hosts 127.0.0.1 localhost.localdomain localhost 192.168.2.120 leda.lab.seti-chile.org leda 192.168.2.120 proxy.lab.seti-chile.org proxy Document Number: 002-001 7 Technical Paper: Linux Administration – Implement HTTP/HTTPS Transparent Proxy with Safe Content Solution SOFTWARE AND DEPENDENCIES In order to build SquidCache and SquidGuard we need to satisfy some software dependencies (packages). Below is the list of dependencies and their installation: - build-essential, bison, flex, automake, autoconf, openssl, openssl- devel, iptables-persistent. 1. Into the server (leda.lab.seti-chile.org), run below commands to update the apt sources: $ sudo apt-get update 2. To update current software (system), run below command: $ sudo apt-get upgrade -y 3. To install dependencies, run below command: $ sudo apt-get install -y build-essential bison flex automake autoconf openssl libssl-dev iptables-persistent libdb-dev:i386 Note: If for some reason above installation fails due broken packages or incomplete old installation, fix it as following: $ sudo apt-get -f install 4. To Download SquidCache and SquidGuard from Ubuntu Sources, run below commands: $ cd /usr/local/src $ sudo apt-get source squid $ sudo apt-get source squidguard Note: We strongly recommend to use Ubuntu Source for Squid and SquidGuard due the compatibility with dependencies. Anyway you can use sources from it makers without issues, just downloading them from their homepages. Below an example how to download them directly to the server: $ cd /usr/local/src $ sudo wget http://www.squid-cache.org/Versions/v3/3.5/squid- 3.5.28.tar.gz $ sudo wget http://www.squidguard.org/Downloads/squidGuard-current.tar.gz Document Number: 002-001 8 Technical Paper: Linux Administration – Implement HTTP/HTTPS Transparent Proxy with Safe Content Solution 5. Create SquidCache/SquidGuard Group and User at OS Level. This will be the owner account for Proxy and Safe Content Services: $ sudo groupadd -g 13 proxy $ sudo useradd -u 13 -g 13 -c “Proxy Service Owner” -d /u01/squid -m -s / usr/sbin/nologin proxy $ 6. Create Dedicated Filesystem and directories for SquidCache and SquidGuard. Will be used LVM + ext4 for this filesystem: $ fdisk /dev/sdb Note: Create Primary LVM Partition (Code: 8e) $ sudo pvcreate /dev/sdb1 $ sudo vgcreate VolGroup01 /dev/sdb1 $ sudo lvcreate -L 6g -n LVu01 VolGroup01 $ sudo mkfs -t ext4 /dev/VolGroup01/LVu01 $ sudo mkdir /u01 $ sudo mount -t ext4 /dev/VolGroup01/LVu01 /u01 $ sudo mkdir -p /u01/squid/log /u01/squid/guard /u01/squid/run /u01/squid/cache /u01/squid/guard/log /u01/squid/guard/db $ sudo chown -R proxy:proxy /u01/squid Note: Is recommended to register new filesystem in /etc/fstab in order to automatically mount at boot. FIREWALL AND ROUTING CONFIGURATION As explained in Architecture/Design Chapter, Our Proxy Server will act as a router and firewall for “Labs Network” in order to redirect traffic to interceptor ports of SquidCache and to communicate with Internet. 1. To enable IP Forwarding, edit /etc/sysctl.conf and add below definitions on it: $ sudo vi /etc/sysctl.conf net.ipv4.ip_forward=1 net.ipv4.conf.all.forwarding=1 Note: Depending on the OS distribution and version, you can create a file into /etc/sysctl.d/ and add the definitions on it. The Kernel will automatically check inside that directory and include all files on it. Check below example: $ sudo vi /etc/sysctl.d/99_squid_ipfw.conf net.ipv4.ip_forward=1 net.ipv4.conf.all.forwarding=1 Document Number: 002-001 9 Technical Paper: