{{tag>netadmin sysadmin filtering forwarding https squid proxy web todo}} ====== Filtrer HTTPS via Squid ====== :TODO: Installation et paramétrage d'un serveur mandataire HTTP/HTTPS avec Squid sur Debian 12 (bookworm). ===== Installer le service Squid ===== Sous Debian, attention de bien installer le paquet **squid-openssl** : c'est cette version de Squid qui supporte le **bumping-ssl capable d'analyser le trafic HTTPS**. apt install -y squid-openssl Pour supporter le bumping-SSL (ou interception TLS) Squid doit être compilé avec les options **%%--with-openssl%%** et **%%--enable-ssl-crtd%%** La commande ci-dessous met en couleur les options de compilation lorsqu'elles sont trouvées : squid -v | grep --color -E '(--with-openssl|--enable-ssl-crtd)' ===== Créer le Root CA ===== Pour que la magie puisse opérer, Squid doit agir comme autorité de certification racine (Root CA) et les clients devront l'accepter comme autorité de certification racine de confiance. Le certificat racine et la clé privée sont des fichiers sensibles : attention à bien restreindre les droits d'accès. cd /etc/squid mkdir ssl_cert chown root:proxy ssl_cert chmod ug+rx,o-rwx ssl_cert cd ssl_certs # Génère le certificat CA valable 10 ans et la clé openssl req -new -newkey rsa:4096 -sha256 -days 3650 -nodes -x509 \ -extensions v3_ca -keyout Tethys_Proxy_CA.pem -out Tethys_Proxy_CA.pem Pour ce cas d'usage, on conserve la clé privée et le certificat dans un même fichier texte (format PEM). On peut maintenant créer différentes versions du certificat racine qui pourront être déployées sur les clients (excluant la clé privée) : # Format DER (bianire) pour les machines Windows openssl x509 -in Tethys_Proxy_CA.pem -outform DER -out /tmp/Tethys_Proxy_CA.der # Format PEM (texte) pour les clients Linux openssl x509 -in Tethys_Proxy_CA.pem -outform PEM -out /tmp/Tethys_Proxy_CA.crt chmod ugo+r-wx /tmp/Tethys_Proxy_CA.crt /tmp/Tethys_Proxy_CA.der ===== Configuration de Squid ===== On configure le service via le fichier ''/etc/squid/squid.conf''. Ce fichier commente largement les options actives par défaut (plus de 9000 lignes). Pour obtenir une vue synthétique des directives actives de ce fichier : cd /etc/squid/ grep --invert-match -e '^$' -e '^#' squid.conf 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 1025-65535 # unregistered ports acl purge method PURGE acl CONNECT method CONNECT http_access allow manager localhost http_access deny manager http_access allow purge localhost http_access deny purge http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access allow localhost http_access deny all http_port 127.0.0.1:3128 ssl-bump cert=/etc/squid/cert/squid_proxyCA.pem generate-host-certificates=on options=NO_SSLv3,NO_TLSv1,NO_TLSv1_1 ssl_bump bump all coredump_dir /var/spool/squid logfile_rotate 0 refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 refresh_pattern . 0 20% 4320 cache_dir ufs /var/spool/squid 200 16 256 Initialiser le repertoire de stockage des certificats SSL gérés par Squid runuser -u proxy -- /usr/lib/squid/security_file_certgen -c -s /var/spool/squid/ssl_db -M 64MB Cette étape est nécessaire pour que Squid puisse démarrer sans erreur La configuration est répartie dans plusieurs fichiers. Pour tester la syntaxe de la configuration chargée par le service : squid -k parse Vérifier l'état du service et si nécessaire activer le service au démarrage : systemclt status squid.service systemctl enable squid.service --now Si le pare-feu **firewalld** est actif, penser à autoriser le trafic entrant sur le port 3128 # Si le port par défaut n'est pas modifié firewall-cmd --info-service=squid firewall-cmd --permanent --zone=internal --add-service=squid firewall-cmd --reload ===== Exclusion du bumping-SSL ===== L'interception TLS peut ne pas s'appliquer systématiquement. On peut définir des ACLs et exclure des domaines du bumping-SSL. :TODO: sources : * https://support.kaspersky.com/fr/kwts/6.1/193664 * https://blog.microlinux.fr/squid-exceptions/ ===== Dépannage ===== Le service squid ne démarre pas normalement, les logs indiquent : nov. 17 23:14:09 tethys (squid-1)[1308]: WARNING: BCP 177 violation. Detected non-functional IPv6 loopback. nov. 17 23:14:09 tethys squid[1308]: Set Current Directory to /var/spool/squid nov. 17 23:14:09 tethys squid[1308]: Starting Squid Cache version 5.7 for x86_64-pc-linux-gnu... nov. 17 23:14:09 tethys squid[1308]: Service Name: squid nov. 17 23:14:09 tethys squid[1308]: Process ID 1308 nov. 17 23:14:09 tethys squid[1308]: Process Roles: worker nov. 17 23:14:09 tethys squid[1308]: With 1024 file descriptors available nov. 17 23:14:09 tethys squid[1308]: Initializing IP Cache... nov. 17 23:14:09 tethys squid[1308]: DNS Socket created at 0.0.0.0, FD 9 nov. 17 23:14:09 tethys squid[1308]: Adding nameserver 192.168.122.1 from /etc/resolv.conf nov. 17 23:14:09 tethys squid[1308]: helperOpenServers: Starting 5/32 'ssl_crtd' processes nov. 17 23:14:09 tethys squid[1309]: ipcCreate: /usr/lib/squid/ssl_crtd: (2) No such file or directory nov. 17 23:14:09 tethys squid[1310]: ipcCreate: /usr/lib/squid/ssl_crtd: (2) No such file or directory nov. 17 23:14:09 tethys squid[1308]: Logfile: opening log daemon:/var/log/squid/access.log nov. 17 23:14:09 tethys squid[1308]: Logfile Daemon: opening log /var/log/squid/access.log nov. 17 23:14:09 tethys squid[1308]: Local cache digest enabled; rebuild/rewrite every 3600/3600 sec nov. 17 23:14:09 tethys squid[1308]: Store logging disabled nov. 17 23:14:09 tethys squid[1308]: Swap maxSize 0 + 131072 KB, estimated 10082 objects nov. 17 23:14:09 tethys squid[1308]: Target number of buckets: 504 nov. 17 23:14:09 tethys squid[1308]: Using 8192 Store buckets nov. 17 23:14:09 tethys squid[1308]: Max Mem size: 131072 KB nov. 17 23:14:09 tethys squid[1308]: Max Swap size: 0 KB nov. 17 23:14:09 tethys squid[1308]: Using Least Load store dir selection nov. 17 23:14:09 tethys squid[1308]: Set Current Directory to /var/spool/squid nov. 17 23:14:10 tethys squid[1311]: ipcCreate: /usr/lib/squid/ssl_crtd: (2) No such file or directory nov. 17 23:14:10 tethys squid[1308]: Finished loading MIME types and icons. nov. 17 23:14:10 tethys squid[1313]: ipcCreate: /usr/lib/squid/ssl_crtd: (2) No such file or directory nov. 17 23:14:10 tethys squid[1312]: ipcCreate: /usr/lib/squid/ssl_crtd: (2) No such file or directory nov. 17 23:14:10 tethys squid[1308]: HTCP Disabled. nov. 17 23:14:10 tethys squid[1308]: Pinger socket opened on FD 24 nov. 17 23:14:10 tethys squid[1308]: Squid plugin modules loaded: 0 nov. 17 23:14:10 tethys squid[1308]: Adaptation support is off. nov. 17 23:14:10 tethys squid[1308]: Accepting SSL bumped HTTP Socket connections at conn12 local=0.0.0.0:3128 remote=[::] FD 22 flags=9 nov. 17 23:14:10 tethys squid[1308]: WARNING: sslcrtd_program #Hlpr1 exited nov. 17 23:14:10 tethys squid[1308]: Too few sslcrtd_program processes are running (need 1/32) nov. 17 23:14:10 tethys squid[1308]: Closing HTTP(S) port 0.0.0.0:3128 nov. 17 23:14:10 tethys squid[1308]: storeDirWriteCleanLogs: Starting... nov. 17 23:14:10 tethys squid[1308]: Finished. Wrote 0 entries. nov. 17 23:14:10 tethys squid[1308]: Took 0.00 seconds ( 0.00 entries/sec). nov. 17 23:14:10 tethys squid[1308]: FATAL: The sslcrtd_program helpers are crashing too rapidly, need help! nov. 17 23:14:10 tethys squid[1308]: Squid Cache (Version 5.7): Terminated abnormally. nov. 17 23:14:10 tethys squid[1308]: Closing Pinger socket on FD 24 nov. 17 23:14:10 tethys squid[1270]: Squid Parent: squid-1 process 1308 exited with status 1 nov. 17 23:14:10 tethys squid[1270]: Squid Parent: squid-1 process 1308 will not be restarted for 3600 seconds due to repeated, frequent failures nov. 17 23:14:10 tethys squid[1270]: Exiting due to repeated, frequent failures nov. 17 23:14:10 tethys squid[1270]: Removing PID file (/run/squid.pid) nov. 17 23:14:10 tethys systemd[1]: squid.service: Main process exited, code=exited, status=1/FAILURE nov. 17 23:14:10 tethys systemd[1]: squid.service: Killing process 1315 (squid) with signal SIGKILL. nov. 17 23:14:10 tethys systemd[1]: squid.service: Failed with result 'exit-code'. Le message ''FATAL: The sslcrtd_program helpers are crashing too rapidly, need help!'' peut apparaitre si le repertoire de stockage des certificats gérés par Squid n'est pas créé. voir section "Configuration SQuid". ===== Références ===== * [[https://blog.microlinux.fr/squid-https-rocky-linux-8/|Filtrer HTTPS via Squid SSL-Bump (microlinux.fr)]] * [[https://wiki.squid-cache.org/Features/HTTPS|Gestion du HTTPS par Squid (squid-cache.org) (en)]] * [[https://webhostinggeeks.com/howto/how-to-configure-squid-proxy-server-for-https-filtering/|Comment configurer un serveur mandataire Squid pour filtrer le HTTPS (webhostinggeeks.com) (en)]] * [[https://www.cyberciti.biz/faq/squid-test-config-file-for-syntax-errors/|Tester la configuration du service Squid (cyberciti.biz) (en)]] * [[https://www.bomberbot.com/proxy/installing-and-configuring-squid-proxy-for-ssl-bumping-or-peek-n-splice/|Installer et configurer un serveur proxy squid pour filtrer le HTTPS via le SSL-Bumping (bomberbot.com) (en)]] * [[https://notebook.arnodo.fr/documentation/securit%C3%A9/ssl_bumping/ssl_bumping/|A propos du SSL-Bumping ou interception TLS (notebook.arnodo.fr)]] * [[https://wiki.squid-cache.org/KnowledgeBase/Debian|Installer Squid sous Debian (squid-cache.org) (en)]] * [[https://unix.stackexchange.com/questions/613359/setting-up-squid-transparent-proxy-with-ssl-bumping-on-debian-10|Configurer squid avec SSL-bumping sous Debian 10 (unix.stackexchange.com) (en)]]