dlundquist / sniproxy

Proxies incoming HTTP and TLS connections based on the hostname contained in the initial request of the TCP session.
BSD 2-Clause "Simplified" License
2.57k stars 398 forks source link

Fix IPv6 to IPv6 and IPv4 to IPv6 transparent proxying #370

Open synnack opened 3 years ago

synnack commented 3 years ago

Hi,

Currently, when the client is IPv4 and the destination is IPv4, transparent proxying works. When the client is IPv6 and the destination is IPv6, it does not, because the wrong type of socket is created. When the client is IPv4 and the destination is IPv6, no mapping is done and an address family error is thrown.

The address family error is thrown because when using ::ffff:192.0.2.1 as source address, the socket will create an IPv4 packet, not an IPv6 packet.

This patch fixes the socket type for IPv6 to IPv6, and also changes the source address from ::ffff:192.0.2.1 to ::192.0.2.1 for IPv4 to IPv6.

In the server logs on the destinations the IPv4-address is as human readable as possible, and replies go to ::0.0.0.0/96.

These replies can be captured using: ip6tables -t mangle -A PREROUTING -m socket --transparent -j MARK --set-mark 1 ip -6 rule add fwmark 0x1 lookup 100 ip -6 route add local ::/96 dev lo table 100

With nftables in the table ip6 mangle chain PREROUTING: socket transparent 1 mark set 0x1 accept

renaudallard commented 3 years ago

Thanks, I fixed it in my fork.