1
votes

I am using (socks5)redsocks2(from https://github.com/semigodking/redsocks) at client side to redirect all data packets to an intermediate gateway instead of Application server directly.It works very well in case of tcp packets. But in case of UDP packets it doesnt work at all. Problem is that once the UDP packet comes to redsocks, the Destination Address and port has changed to redsocks local address and port.

I am using below IPTable rules for packet forwarding :-

iptables -t nat -N REDSOCKS
iptables -t nat -A REDSOCKS -p tcp --dport  7 -j RETURN 
iptables -t nat -A REDSOCKS -p tcp -d xxx.xxx.xxx.xxx --dport 1080 -j RETURN
iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 0.0.0.0 -j RETURN
iptables -t nat -A REDSOCKS -p udp --dport  53 -j RETURN 
iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports YYYYY
iptables -t nat -A REDSOCKS -p udp -j REDIRECT --to-ports ZZZZZ
iptables -t nat -A OUTPUT -p tcp -j REDSOCKS
iptables -t nat -A OUTPUT -p udp -j REDSOCKS

** xxx.xxx.xxx.xxx = intermediate gateway server address
** YYYY, ZZZZ = local ports for redsocks in client device

I am using below redsocks conf file :

base { 
    log_debug = off; 
    log_info = off; 
    daemon = on; 
    redirector = iptables; 
} 

redsocks {
    local_ip = 127.0.0.1; 
    local_port = YYYYY; 
    ip = xxx.xxx.xxx.xxx; 
    port = MMMM; 
    type = socks5; 
    login = "login"; 
    password = "password"; 
}

redudp {
    local_ip = 0.0.0.0; 
    local_port = ZZZZZ; 
    ip = xxx.xxx.xxx.xxx; 
    port = MMMM; 
    type = socks5;
    login = "login"; 
    password = "password"; 
    udp_timeout = 30;udp_timeout_stream = 180;
} 

As far as I know, TPROXY works on PREROUTING. It doesn't work on packet generated from local machine(I mean OUTPUT chain). TPROXY can work on router but can not work on origin machine.

Please suggest how can we handle this scenario for udp packet forwarding via redsocks2.

2

2 Answers

0
votes

try use google translation to read the Chinese ReadMe at URL https://github.com/semigodking/redsocks/wiki

0
votes

If you are using redirect rule, the destination address in the packets gets overwritten and if you try to read the destination address from the packet using IP_ORIGDSTADDR you would only read the loopback address.

To get the original destination address you can probably try parsing the /proc/net/nf_conntrack (match with source IP and port) file which contains info about all the connections.But you might have a problem if you have multiple destinations for same (srcIP,srcPort) pair and hence this is not the best way. But it is worth giving a try if you don't have such possibility.