Squid im Intercept-Modus via TPROXY mit nftables: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
= Squid im Intercept-Modus via TPROXY mit nftables =
+
= Squid im Intercept-Modus per REDIRECT (lokal auf dem Proxy) =
  
 
== Voraussetzungen ==
 
== Voraussetzungen ==
* Die Firewall hat die interne IP 172.17.113.1
+
* Der Proxy hat eine eigene IP im LAN, z. B. 10.88.113.51
* Der Squid-Proxy läuft auf einer separaten Maschine mit der IP 10.88.113.51
+
* Squid läuft direkt auf diesem Host
* Der Proxy soll HTTP (Port 80) und HTTPS (Port 443) Verkehr transparent abfangen.
+
* Der Traffic wird per iptables/nftables von Port 80/443 auf lokale Ports umgeleitet
* Die Original-Ziel-IP soll erhalten bleiben – daher wird auf der Firewall nur DNAT durchgeführt, und **TPROXY erfolgt ausschließlich auf dem Proxyserver**.
+
* Keine TPROXY-Konfiguration nötig
* Die Firewall nutzt nftables für NAT.
 
* Der Proxyserver setzt nftables und Policy Routing für TPROXY ein.
 
  
== nftables-Regeln auf der Firewall ==
+
== Squid-Konfiguration ==
;NAT-Tabelle und Weiterleitung der Verbindungen an den Proxy:
+
http_port 3128 intercept
 +
https_port 3129 intercept ssl-bump cert=/etc/squid/certs/proxyCA.pem key=/etc/squid/certs/proxyCA.key
 +
 
 +
;Optional: SSL-Bump
 +
ssl_bump peek all
 +
ssl_bump bump all
 +
sslproxy_cert_error allow all
 +
sslproxy_flags DONT_VERIFY_PEER
 +
 
 +
== nftables-Konfiguration (lokal auf dem Proxy) ==
 
*nft add table ip nat
 
*nft add table ip nat
 
*nft add chain ip nat prerouting '{ type nat hook prerouting priority dstnat; policy accept; }'
 
*nft add chain ip nat prerouting '{ type nat hook prerouting priority dstnat; policy accept; }'
*nft add rule ip nat prerouting tcp dport 80  dnat to 10.88.113.51:3029
+
*nft add rule ip nat prerouting tcp dport 80  redirect to :3128
*nft add rule ip nat prerouting tcp dport 443 dnat to 10.88.113.51:3030
+
*nft add rule ip nat prerouting tcp dport 443 redirect to :3129
 
 
== nftables-Regeln auf dem Proxyserver ==
 
;Tabelle und Kette erstellen:
 
*nft add table inet tproxy
 
*nft add chain inet tproxy prerouting '{ type filter hook prerouting priority mangle; policy accept; }'
 
 
 
;TPROXY-Regeln für HTTP und HTTPS:
 
*nft add rule inet tproxy prerouting ip daddr 10.88.113.51 tcp dport 3029 tproxy to :3029 mark set 1
 
*nft add rule inet tproxy prerouting ip daddr 10.88.113.51 tcp dport 3030 tproxy to :3030 mark set 1
 
  
== Policy Routing auf dem Proxyserver ==
+
== Kernel-Module laden (falls nötig) ==
*ip rule add fwmark 1 lookup 100
+
*modprobe nf_nat
*ip route add local 0.0.0.0/0 dev lo table 100
 
 
 
== Notwendige Kernel-Module auf dem Proxyserver ==
 
 
*modprobe nf_conntrack
 
*modprobe nf_conntrack
*modprobe nf_tproxy_ipv4
 
*modprobe nf_tproxy_ipv6
 
*modprobe xt_TPROXY
 
  
== Squid-Setup auf dem Proxyserver ==
+
== Squid-Rechte (kein TPROXY nötig) ==
Squid muss mit TPROXY-Support kompiliert sein (mit --enable-linux-netfilter)
+
Keine `setcap`-Anpassung notwendig – REDIRECT reicht.
  
Squid-Konfiguration anpassen:
+
== Test & Logs ==
 
 
http_port 3029 tproxy
 
https_port 3030 tproxy ssl-bump cert=/etc/squid/certs/proxy.pem key=/etc/squid/certs/proxy.key
 
 
 
;Optional: SSL-Bump konfigurieren:
 
ssl_bump peek all
 
ssl_bump bump all
 
sslproxy_cert_error allow all
 
sslproxy_flags DONT_VERIFY_PEER
 
 
 
== Squid-Rechte anpassen ==
 
*setcap cap_net_bind_service,cap_net_admin=eip /usr/sbin/squid
 
 
 
== Test & Diagnose ==
 
;Firewall:
 
*nft list chain ip nat prerouting
 
 
 
;Proxyserver:
 
*nft list chain inet tproxy prerouting
 
*ip rule show
 
*ip route show table 100
 
 
*tail -f /var/log/squid/access.log
 
*tail -f /var/log/squid/access.log
 
*tail -f /var/log/squid/cache.log
 
*tail -f /var/log/squid/cache.log
 
== Hinweise ==
 
* Die Weiterleitung funktioniert nur, wenn keine zusätzlichen NAT- oder Firewall-Regeln die Pakete blockieren.
 
* Für HTTPS müssen die Clients die Root-CA des Proxyservers akzeptieren, wenn SSL-Bump aktiviert ist.
 
* Diese Methode ist technisch aufwendig – in produktiven Umgebungen sollte, wenn möglich, ein expliziter Proxy via WPAD bevorzugt werden.
 

Aktuelle Version vom 24. April 2025, 05:19 Uhr

Squid im Intercept-Modus per REDIRECT (lokal auf dem Proxy)

Voraussetzungen

  • Der Proxy hat eine eigene IP im LAN, z. B. 10.88.113.51
  • Squid läuft direkt auf diesem Host
  • Der Traffic wird per iptables/nftables von Port 80/443 auf lokale Ports umgeleitet
  • Keine TPROXY-Konfiguration nötig

Squid-Konfiguration

http_port 3128 intercept https_port 3129 intercept ssl-bump cert=/etc/squid/certs/proxyCA.pem key=/etc/squid/certs/proxyCA.key

Optional
SSL-Bump

ssl_bump peek all ssl_bump bump all sslproxy_cert_error allow all sslproxy_flags DONT_VERIFY_PEER

nftables-Konfiguration (lokal auf dem Proxy)

  • nft add table ip nat
  • nft add chain ip nat prerouting '{ type nat hook prerouting priority dstnat; policy accept; }'
  • nft add rule ip nat prerouting tcp dport 80 redirect to :3128
  • nft add rule ip nat prerouting tcp dport 443 redirect to :3129

Kernel-Module laden (falls nötig)

  • modprobe nf_nat
  • modprobe nf_conntrack

Squid-Rechte (kein TPROXY nötig)

Keine `setcap`-Anpassung notwendig – REDIRECT reicht.

Test & Logs

  • tail -f /var/log/squid/access.log
  • tail -f /var/log/squid/cache.log