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

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Die Seite wurde neu angelegt: „= Squid im Intercept-Modus via TPROXY mit nftables = == Voraussetzungen == * Squid läuft nicht direkt auf der Firewall, sondern auf einer separaten Maschine…“
 
Keine Bearbeitungszusammenfassung
 
(7 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 ==
* Squid läuft nicht direkt auf der Firewall, sondern auf einer separaten Maschine im Netzwerk.
* Der Proxy hat eine eigene IP im LAN, z. B. 10.88.113.51
* Der Proxy soll HTTP (Port 80) und HTTPS (Port 443) Verkehr transparent abfangen.
* Squid läuft direkt auf diesem Host
* Die Original-Ziel-IP soll erhalten bleiben – daher TPROXY statt DNAT/REDIRECT.
* Der Traffic wird per iptables/nftables von Port 80/443 auf lokale Ports umgeleitet
* Die Firewall nutzt `nftables` und unterstützt Policy-Based Routing.
* Keine TPROXY-Konfiguration nötig


== nftables-Regeln auf der Firewall ==
== Squid-Konfiguration ==
Tabelle und Kette erstellen:
http_port 3128 intercept
*nft add table inet tproxy
https_port 3129 intercept ssl-bump cert=/etc/squid/certs/proxyCA.pem key=/etc/squid/certs/proxyCA.key
*nft add chain inet tproxy prerouting '{ type filter hook prerouting priority mangle; policy accept; }'


* TPROXY-Regeln für HTTP und HTTPS einfügen:
;Optional: SSL-Bump
*nft add rule inet tproxy prerouting tcp dport 80 tproxy to :3029 mark set 1
ssl_bump peek all
*nft add rule inet tproxy prerouting tcp dport 443 tproxy to :3030 mark set 1
ssl_bump bump all
sslproxy_cert_error allow all
sslproxy_flags DONT_VERIFY_PEER


== Policy Routing auf der Firewall ==
== nftables-Konfiguration (lokal auf dem Proxy) ==
Weiterleitung der markierten Pakete zur lokalen Verarbeitung:
*nft add table ip nat
*ip rule add fwmark 1 lookup 100
*nft add chain ip nat prerouting '{ type nat hook prerouting priority dstnat; policy accept; }'
*ip route add local 0.0.0.0/0 dev lo table 100
*nft add rule ip nat prerouting tcp dport 80  redirect to :3128
*nft add rule ip nat prerouting tcp dport 443 redirect to :3129


== Notwendige Kernel-Module ==
== Kernel-Module laden (falls nötig) ==
Folgende Module müssen geladen sein:
*modprobe nf_nat
mo*dprobe nf_conntrack
*modprobe nf_conntrack
mo*dprobe 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 (`--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 ==
Squid benötigt zusätzliche CAPs zum Binden fremder IPs:
*setcap cap_net_bind_service,cap_net_admin=eip /usr/sbin/squid
 
== Test & Diagnose ==
Überprüfen ob Pakete markiert werden:
*nft list chain inet tproxy prerouting
 
;Policy-Routing prüfen:
*ip rule show
*ip route show table 100
 
;Squid-Logs im Auge behalten:
*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 ==
Clientzertifikate oder CA-Zertifikate müssen ggf. angepasst werden.
Browserwarnungen bei HTTPS sind zu erwarten, falls keine eigene Root-CA ausgerollt 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