Clash: 访问 redir-port 导致 clash 停止工作

Created on 10 Dec 2019  ·  8Comments  ·  Source: Dreamacro/clash

系统: Arch Linux x86_64

复现步骤:

  1. 在配置文件中开启 redir port redir-port: 7892
    在规则的第一条插入 IP-CIDR,127.0.0.0/8,DIRECT
  2. 启动 clash
  3. 执行 curl http://127.0.0.1:7892

现象:

  • 日志中出现大量
    level=info msg="127.0.0.1 --> 127.0.0.1 match IPCIDR using DIRECT"

    level=warning msg="dial DIRECT error: dial tcp4 127.0.0.1:7892: socket: too many open files"
  • 高 cpu 占用
  • clash 的 HTTP proxy 停止工作
Stale bug good first issue help wanted

Most helpful comment

可以使用 iptables uid filter 禁止 clash 出站流量回环之类的方法解决。

解决了,感谢。

iptables -A OUTPUT -d 127.0.0.1 -p tcp -m owner --uid-owner clash -m tcp --dport 7892 -j REJECT

edit:
有一个更好的方法:在 REDIRECT 的同时打标签,然后禁止没有标签的流量进入 redir port

iptables -A INPUT -d 127.0.0.1 -p tcp -m tcp --dport 7892 -m connmark ! --mark 5 -j REJECT
...
iptables -A CLASH -p tcp -j CONNMARK --set-mark 5
iptables -A CLASH -p tcp -j REDIRECT --to-ports 7892

All 8 comments

你是指存在一个 DoS 攻击是吗

我是在打开一个 clash 面板 的时候发现异常的,这个面板默认连接到 7892 端口了。

你是指存在一个 DoS 攻击是吗

的确存在被攻击的可能。

P.S. ss-redir 不存在这个问题

是个回环,clash 用 getorigdst 拿到的 address 就是 127.0.0.1:7892 ,然后又从 DIRECT 出去访问 redir port了。

可以使用 iptables uid filter 禁止 clash 出站流量回环之类的方法解决。

可以使用 iptables uid filter 禁止 clash 出站流量回环之类的方法解决。

解决了,感谢。

iptables -A OUTPUT -d 127.0.0.1 -p tcp -m owner --uid-owner clash -m tcp --dport 7892 -j REJECT

edit:
有一个更好的方法:在 REDIRECT 的同时打标签,然后禁止没有标签的流量进入 redir port

iptables -A INPUT -d 127.0.0.1 -p tcp -m tcp --dport 7892 -m connmark ! --mark 5 -j REJECT
...
iptables -A CLASH -p tcp -j CONNMARK --set-mark 5
iptables -A CLASH -p tcp -j REDIRECT --to-ports 7892

@Dreamacro 有沒有可能實作一個檢測回環避免 DoS Attack 的功能

最好能从代码根治这个问题。。。

最好能从代码根治这个问题。。。

技术上有什么想法吗?

检测方面: 如何判断流量是不是从clash发出去的?

处理方面: 如果回环存在,一般是外部配置出现了问题。即便检测到了回环,clash 能做什么?我目前能想到的只是能: 1. 避免自己处理能力被耗尽 2. 提示用户。并不能做什么使得流量被正确转发。

This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days

Was this page helpful?
0 / 5 - 0 ratings