Using Kaspersky Scan Engine in ICAP mode with Squid
Squid is a caching and forwarding web proxy server for Windows and UNIX-like systems. You can use Kaspersky Scan Engine in ICAP mode to scan traffic that passes through the Squid proxy.
Software requirements
- Operating system Ubuntu 18.04 or later
- Squid 4.5 or later
Configuring Squid for working with Kaspersky Scan Engine
For Kaspersky Scan Engine to work with Squid in ICAP mode, you must specify Kaspersky Scan Engine as an ICAP service in the Squid configuration file (squid.conf).
In Squid, an ICAP service is defined in the following format: icap_service id vectoring_point [options] uri
.
To specify Kaspersky Scan Engine as an ICAP service:
- Open squid.conf for editing.
- Define the mandatory parameters
id
,vectoring_point
, anduri
:- Set
id
to any appropriate identifier. For example,srv_kl_resp
for request modification (REQMOD) mode andsrv_kl_req
for response modification (RESPMOD) mode. - Set
vectoring_point
to an appropriate*_precache
value:- For request modification (REQMOD) mode, specify
reqmod_precache
. - For response modification (RESPMOD) mode, specify
respmod_precache
.
- For request modification (REQMOD) mode, specify
- Set
uri
to the location of Kaspersky Scan Engine:- For REQMOD mode, the URI must have the following format:
icap://servername:port/req
. - For RESPMOD mode, the URI must have the following format:
icap://servername:port/resp
.
- For REQMOD mode, the URI must have the following format:
- Set
- Add the following lines to the end of the Squid configuration file:
icap_enable on
adaptation_send_username on
adaptation_send_client_ip on
icap_service srv_kl_resp respmod_precache 0 icap://localhost:1344/resp
icap_service srv_kl_req reqmod_precache 0 icap://localhost:1344/req
adaptation_access srv_kl_resp allow all
adaptation_access srv_kl_req allow all
icap_service_failure_limit -1
icap_service_revival_delay 30
icap_preview_enable off
In the example above,
srv_kl_resp
andsrv_kl_req
are examples ofid
,respmod_precache
andreqmod_precache
are values ofvectoring_point
,0
is the value of the Squidbypass
option, andvectoring_point
andicap://127.0.0.1:1344/req
are examples ofuri
.You can use
127.0.0.1
inuri
only if Kaspersky Scan Engine is installed on the same computer as Squid. - Save and close squid.conf.
- Restart the
squid
service:service squid restart
Configuring Squid for working with Kaspersky Scan Engine and enabling SSL scanning
By default, Kaspersky Scan Engine cannot scan SSL/TLS traffic, but you can configure Squid to decrypt it by using the SSL Bumping functionality.
To configure Squid for working with Kaspersky Scan Engine and enable SSL Bumping:
- Install the packages necessary to compile and configure Squid:
apt-get install build-essential openssl libssl-dev pkg-config
- Download source code for Squid 4.5 or later.
- Unzip the archive that contains the Squid source code to the required directory.
- Move to this directory.
- Compile Squid:
./configure --with-default-user=proxy --with-openssl --enable-ssl-crtd
make all
make install
Options
--with-openssl
and--enable-ssl-crtd
are necessary to enable SSL Bumping. - Set up the correct time and date on the server that is running Squid. The time and date are checked every time a client is trying to validate the certificate of this server.
- Configure OpenSSL:
- Find the default OpenSSL configuration file
openssl.cnf
. The location of this file depends on your operating system, but usually it is/etc/ssl/openssl.cnf
. - Open
openssl.cnf
for editing. - Add the following line to the
[v3_ca]
section of the configuration file:keyUsage = cRLSign, keyCertSign
- Save and close
openssl.cnf
.
- Find the default OpenSSL configuration file
- Prepare the environment for storing SSL certificates:
- Create a directory for storing SSL certificates:
mkdir /usr/local/squid/etc/ssl_cert -p
- Change the user and the group that own that directory to
proxy
:chown proxy:proxy /usr/local/squid/etc/ssl_cert -R
- Change the permissions for that directory:
chmod 700 /usr/local/squid/etc/ssl_cert -R
- Create a directory for storing SSL certificates:
- Move to the newly created directory:
cd /usr/local/squid/etc/ssl_cert
- Generate a new self-signed SSL certificate and a private key for the Squid server:
openssl req -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -extensions v3_ca -keyout squid_ca.pem -out squid_ca.pem
- Convert the newly created certificate to DER format:
openssl x509 -in squid_ca.pem -outform DER -out squid_ca.der
- Export the generated certificate to the client computers and install it on them as a Certificate Authority certificate. The method of doing this depends on the browser and operating system of the client.
- Create a new SSL database for the Squid server:
/usr/local/squid/libexec/security_file_certgen -c -s /usr/local/squid/var/logs/ssl_db -M 4MB
- Change the user and the group that own that directory to
proxy
:chown proxy:proxy /usr/local/squid/var/logs/ssl_db -R
- Configure Squid:
- Find the default Squid configuration file
squid.conf
. The location of this file depends on your operating system, but usually it is/usr/local/squid/etc/squid.conf
. - Open
squid.conf
and make the following edits: - Find the following line:
http_port 3128
- Replace it with the following line:
http_port 3128 ssl-bump cert=/usr/local/squid/etc/ssl_cert/squid_ca.pem generate-host-certificates=on dynamic_cert_mem_cache_size=4MB
This line enables SSL Bumping on port 3128.
- Add the following section:
acl step1 at_step SslBump1
ssl_bump peek step1
ssl_bump bump all
sslcrtd_program /usr/local/squid/libexec/security_file_certgen -s /usr/local/squid/var/logs/ssl_db -M 4MB
- Specify Kaspersky Scan Engine as an ICAP service in the Squid configuration file as described above in the subsection "Configuring Squid for working with Kaspersky Scan Engine".
- Save and close
squid.conf
.
- Find the default Squid configuration file
- Change the user and the group that own the
/usr/local/squid
directory toproxy
:chown -R proxy:proxy /usr/local/squid
- Start Squid and initialize the Squid cache:
/usr/local/squid/sbin/squid -z
Following is an example of a Squid configuration file extract. In this example, Squid uses Kaspersky Scan Engine in ICAP mode to scan HTTP messages in both the REQMOD and RESPMOD modes.
# SSL bumping configuration
http_port 3128 ssl-bump cert=/usr/local/squid/etc/ssl_cert/squid_ca.pem generate-hostcertificates=on dynamic_cert_mem_cache_size=4MB
# ICAP configuration
icap_enable on adaptation_send_username on adaptation_send_client_ip on icap_service srv_kl_resp respmod_precache 0 icap://localhost:1344/resp icap_service srv_kl_req reqmod_precache 0 icap://localhost:1344/req adaptation_access srv_kl_resp allow all adaptation_access srv_kl_req allow all icap_service_failure_limit -1 icap_service_revival_delay 30 icap_preview_enable off |