macronut / phantomsocks

A cross-platform proxy client/server for Linux/Windows/macOS
GNU Lesser General Public License v3.0
453 stars 18 forks source link

Connection does not exist when connect to website in REDIRECT mode #59

Closed Sunsetra closed 1 year ago

Sunsetra commented 1 year ago

Platform: Archlinux

When I use REDIRECT mode, all connection is EOF and the log shows connection does not exist.

Config File

config.json ``` { "vaddrprefix": 6, "profiles": ["default.conf"], "services": [ { "name": "redirect", "protocol": "redirect", "address": "0.0.0.0:6" } ], "interfaces": [ { "name": "default", "device": "wlp2s0", "dns": "udp://192.168.0.1:53", "hint": "w-md5" } ] } ```

Iptables Setting

iptables -t nat -L ``` # iptables -t nat -L Chain PREROUTING (policy ACCEPT) target prot opt source destination Chain INPUT (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination PTCP tcp -- anywhere anywhere Chain POSTROUTING (policy ACCEPT) target prot opt source destination Chain PTCP (1 references) target prot opt source destination RETURN all -- anywhere 0.0.0.0/8 RETURN all -- anywhere 10.0.0.0/8 RETURN all -- anywhere 127.0.0.0/8 RETURN all -- anywhere 172.16.0.0/12 RETURN all -- anywhere 192.168.0.0/16 REDIRECT tcp -- anywhere anywhere redir ports 6 ```

Pcap version log

./phantomsocks-pcap -log 3 ``` # ./phantomsocks-pcap -log 3 map[default:{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 }] [default] &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } default.conf Redirect: 0.0.0.0:6 Device: wlp2s0 Redirect: 192.168.0.101:53258 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } Redirect: 192.168.0.101:53260 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } nslookup github.com 1 [20.205.243.166] nslookup github.com 1 [20.205.243.166 20.205.243.166] Redirect: 192.168.0.101:55148 -> www.bingapis.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } nslookup www.bingapis.com 1 [13.107.5.80] Redirect: 192.168.0.101:56774 -> nav-edge.smartscreen.microsoft.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } nslookup nav-edge.smartscreen.microsoft.com 1 [20.44.202.200] github.com connection does not exist EOF Redirect: 192.168.0.101:53262 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 20.205.243.166] EOF github.com connection does not exist Redirect: 192.168.0.101:41160 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 20.205.243.166] EOF www.bingapis.com connection does not exist Redirect: 192.168.0.101:38146 -> www.bingapis.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: www.bingapis.com 1 [13.107.5.80] EOF nav-edge.smartscreen.microsoft.com connection does not exist Redirect: 192.168.0.101:54246 -> nav-edge.smartscreen.microsoft.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: nav-edge.smartscreen.microsoft.com 1 [20.44.202.200] EOF github.com connection does not exist EOF github.com connection does not exist EOF www.bingapis.com connection does not exist nav-edge.smartscreen.microsoft.com connection does not exist EOF Redirect: 192.168.0.101:41172 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 20.205.243.166] Redirect: 192.168.0.101:54254 -> nav-edge.smartscreen.microsoft.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: nav-edge.smartscreen.microsoft.com 1 [20.44.202.200] Redirect: 192.168.0.101:41180 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 20.205.243.166] github.com connection does not exist EOF github.com connection does not exist Redirect: 192.168.0.101:41188 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 20.205.243.166] nav-edge.smartscreen.microsoft.com connection does not exist EOF EOF Redirect: 192.168.0.101:41194 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 20.205.243.166] Redirect: 192.168.0.101:54262 -> nav-edge.smartscreen.microsoft.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: nav-edge.smartscreen.microsoft.com 1 [20.44.202.200] EOF github.com connection does not exist github.com connection does not exist EOF nav-edge.smartscreen.microsoft.com connection does not exist EOF ```

I also try to use rawsocket version, but get the same results.

RawSocket version log

./phantomsocks-rs -log 3 ``` # ./phantomsocks-rs -log 3 map[default:{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 }] [default] &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } default.conf Redirect: 0.0.0.0:6 Device: wlp2s0 (240e:398:1d7:8520::1001) Device: wlp2s0 (192.168.0.101) Redirect: 192.168.0.101:48656 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } Redirect: 192.168.0.101:48640 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } nslookup github.com 1 [20.205.243.166] github.com 20.205.243.166:443 connected Redirect: 192.168.0.101:34525 -> 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } nslookup github.com 1 [20.205.243.166 192.30.255.113] github.com 20.205.243.166:443 connected Redirect: 192.168.0.101:48475 -> 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } nslookup 1 [] no such host nslookup 1 [] no such host Redirect: 192.168.0.101:48398 -> nav-edge.smartscreen.microsoft.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } nslookup nav-edge.smartscreen.microsoft.com 1 [20.198.213.74] nav-edge.smartscreen.microsoft.com 20.198.213.74:443 connected Redirect: 192.168.0.101:57111 -> 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: 1 [] no such host relay error: readfrom tcp 127.0.0.1:6->192.168.0.101:48640: splice: connection reset by peer relay error: readfrom tcp 127.0.0.1:6->192.168.0.101:48656: splice: connection reset by peer relay error: readfrom tcp 127.0.0.1:6->192.168.0.101:48398: splice: connection reset by peer Redirect: 192.168.0.101:56298 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 192.30.255.113] github.com 20.205.243.166:443 connected Redirect: 192.168.0.101:38919 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 192.30.255.113] github.com 20.205.243.166:443 connected Redirect: 192.168.0.101:36330 -> nav-edge.smartscreen.microsoft.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: nav-edge.smartscreen.microsoft.com 1 [20.198.213.74] Redirect: 192.168.0.101:44545 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 192.30.255.113] Redirect: 192.168.0.101:56310 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 192.30.255.113] github.com 20.205.243.166:443 connected Redirect: 192.168.0.101:56139 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 192.30.255.113] github.com 20.205.243.166:443 connected Redirect: 192.168.0.101:56211 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 192.30.255.113] nav-edge.smartscreen.microsoft.com 20.198.213.74:443 connected Redirect: 192.168.0.101:52041 -> 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: 1 [] no such host github.com 20.205.243.166:443 connected Redirect: 192.168.0.101:49573 -> github.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: github.com 1 [20.205.243.166 192.30.255.113] github.com 20.205.243.166:443 connected Redirect: 192.168.0.101:43579 -> 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: 1 [] no such host github.com 20.205.243.166:443 connected Redirect: 192.168.0.101:36336 -> nav-edge.smartscreen.microsoft.com 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: nav-edge.smartscreen.microsoft.com 1 [20.198.213.74] Redirect: 192.168.0.101:47087 -> 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: 1 [] no such host nav-edge.smartscreen.microsoft.com 20.198.213.74:443 connected Redirect: 192.168.0.101:36999 -> 443 &{wlp2s0 udp://192.168.0.1:53 4096 0 0 0 65535 0 } cached: 1 [] no such host relay error: readfrom tcp 127.0.0.1:6->192.168.0.101:36336: splice: connection reset by peer ```

How can I get rid of those ERRORs?

macronut commented 1 year ago

Only virtual addresses can be forwarded when forwarding directly connected addresses in OUTPUT, forwarding all addresses will cause a loop.