Monday 5 February 2018

linux transparent proxy not working

I am trying to get apache trafficserver working in transparent proxy mode i.e in inline Linux bridge mode. They have documentation on how to do this. I've configured my Linux system as per their documentation and here's my config:


brctl addbr br0
brctl stp br0 off
brctl addif br0 enp2s0
brctl addif br0 eno1
ifconfig enp2s0 0 0.0.0.0
ifconfig eno1 0 0.0.0.0
ifconfig br0 0.0.0.0
ifconfig br0 192.168.10.100 netmask 255.255.255.0 up
ebtables -t broute -F
ebtables -t broute -A BROUTING -p IPv4 --ip-proto tcp --ip-dport 80 -j redirect --redirect-target DROP
ebtables -t broute -A BROUTING -p IPv4 --ip-proto tcp --ip-sport 80 -j redirect --redirect-target DROP
iptables -t mangle -A PREROUTING -i eno1 -p tcp -m tcp --dport 80 -j TPROXY --on-ip 0.0.0.0 --on-port 8080 --tproxy-mark 1/1
iptables -t mangle -A PREROUTING -i enp2s0 -p tcp -m tcp --sport 80 -j MARK --set-mark 1/1
ip rule add fwmark 1/1 table 1
ip route add local 0.0.0.0/0 dev lo table 1

However, this configuration doesn't seem to work. According to the configuration, the ebtables and iptables rules are intercepting traffic destined for port 80 and redirecting it port 8080. Based on tcpdump output, the initial request seems to come to my Linux system.


tshark -i eno1 port 80
Running as user "root" and group "root". This could be dangerous.
Capturing on 'eno1'
1 0.000000000 192.168.20.200 -> 192.168.20.50 TCP 74 58986 > http [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=345213688 TSecr=0 WS=128
2 1.002013264 192.168.20.200 -> 192.168.20.50 TCP 74 [TCP Retransmission] 58986 > http [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=345214690 TSecr=0 WS=128
3 3.008098848 192.168.20.200 -> 192.168.20.50 TCP 74 [TCP Retransmission] 58986 > http [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=345216696 TSecr=0 WS=128
3 packets captured

However, it looks like the iptables/ebtables are not forwarding up the stack. I added tracing to the iptables rules and this is what I see in the logs.


[ 5425.095575] TRACE: raw:PREROUTING:policy:2 IN=eno1 OUT= MAC=0c:c4:7a:78:97:c6:0c:c4:7a:b5:be:e9:08:00 SRC=192.168.20.200 DST=192.168.20.50 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=41608 DF PROTO=TCP SPT=58922 DPT=80 SEQ=2153102820 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A1478234C0000000001030307)
[ 5425.095620] TRACE: mangle:PREROUTING:rule:1 IN=eno1 OUT= MAC=0c:c4:7a:78:97:c6:0c:c4:7a:b5:be:e9:08:00 SRC=192.168.20.200 DST=192.168.20.50 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=41608 DF PROTO=TCP SPT=58922 DPT=80 SEQ=2153102820 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A1478234C0000000001030307)

The iptables trace confirms what I am seeing in the tcpdump output. It looks like it the request is coming to the iptables and is then getting dropped somewhere Linux IP stack. Not sure where or how to go about debugging this.


Reading online on this topic, someone suggested I disable rp_filter. However, turning off rp_filter did not help. Somebody else suggested that I enabled IP forwarding, that did not help either. Any help in fixing the issue or at least some pointers what or where to debug next would be greatly appreciated.

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...