redsocks icon indicating copy to clipboard operation
redsocks copied to clipboard

detect `iptables` loops

Open darkk opened this issue 8 years ago • 2 comments

It may be possible to write some trivial code checking if the connection is loop connection from redsocks daemon back to itself.

It may help users to avoid bugs like #108 caused by loop in iptables ruleset.

That may be not trivial because of proxy chaining use-case described in #18.

darkk avatar Jul 11 '17 23:07 darkk

Hi @darkk, I am using Redsocks on Openwrt. I have same issue, but on Openwrt is single user system, so I can't run Redsocks using different user and can't match traffic using owner.

Here is my iptables rules:

  iptables -t nat -N REDSOCKS                                           
                                                                         
   # Don't proxy local or private traffic                                
   iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
   iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
   iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN 
   iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
   iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN 
   iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
   iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN   
   iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN   
   iptables -t nat -A REDSOCKS -d 192.0.0.0/16 -j RETURN  
                                                         
   # Send everything else through the redsocks daemon     
   iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports $REDSOCKS_PORT                                                            
                                                                           
   iptables -t nat -A PREROUTING -i br-lan -p tcp -j REDSOCKS  

How can I change it to avoid loop?

animer3009 avatar Mar 17 '22 13:03 animer3009

Hi @animer3009

As far as I understand, OpenWRT is not really a single-user system. There are several users in /etc/passwd and /etc/shadow and users might be added. E.g. I use the following script as "autossh" replacement and it runs ssh binary as network user: https://gist.github.com/darkk/9c71252357d3d422661ae39d340ca22a

I hope, this example is useful.

Also, I'd suggest to consider using VPN instead of TCP-proxy like redsocks, if that's possible. It'll likely give way better performance.

darkk avatar Mar 18 '22 08:03 darkk