XTLS / Xray-core

Xray, Penetrates Everything. Also the best v2ray-core, with XTLS support. Fully compatible configuration.
https://t.me/projectXray
Mozilla Public License 2.0
22.79k stars 3.65k forks source link

关于Reality的dest打断连接后xray不会打断链接的特征 #3502

Open CalunVier opened 2 days ago

CalunVier commented 2 days ago

完整性要求

版本

1.8.16

描述

当一个非Reality流量进入Reality inbound时,reality会“回落“到dest选项指定的地址,以掩盖特征。这个想法在非法流量为标准的https请求时工作良好。但当非法的reality流量同时是非法的http/https流量时,其行为将于绝大多数反代软件产生不同。我于telnet的一个典型用例中发现此问题。 当使用Linux下的telnet(Windows下效果类似,只不过Linux下的telnet实现对打断链接相应更快)访问一个标准Nginx反代的网站并发送"hello",结果如下:

~ $ telnet 127.0.0.1 443
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
hello
HTTP/1.1 400 Bad Request
Server: nginx/1.24.0
Date: Wed, 03 Jul 2024 06:01:38 GMT
Content-Type: text/html
Content-Length: 157
Connection: close

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.24.0</center>
</body>
</html>
Connection closed by foreign host.
~ $

注意到倒数第二行,链接被迅速打断。 但当Nginx位于Xray之后时,其行为如下:

~ $ telnet 127.0.0.1 443
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
hello
HTTP/1.1 400 Bad Request
Server: nginx/1.24.0
Date: Wed, 03 Jul 2024 06:05:17 GMT
Content-Type: text/html
Content-Length: 157
Connection: close

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.24.0</center>
</body>
</html>
^]
telnet>

Nginx中断与Xray的连接后,Xray与telnet的连接被维持。注意到倒数第二行,是我等待数秒后使用^]手动结束的连接。

绝大多的反代软件不会拥有类似的行为,我同样尝试了位于frp之后的22端口,非法ssh连接也会被迅速打断。我同样测试了由Sing-Box实现的Reality,其在该情景下依然有明显的特征,但连接会在一段时间后打断。我不确定是否所有的反代软件都会表现的像Nginx或frp,但是至少在现实世界中,xray的行为着实小众。

这是一个应当被解决的特征。因为当Reality假设GFW会主动发起探测,并采取缓解措施时,该情景没有理由不被纳入考虑。

重现方式

重现非常简单,你只需要一个xray和http服务器,以及一个telnet客户端。

我的Vless-Xtls-version-reality入站设置见后文

客户端配置

服务端配置


{inbounds:
[
   {
      "tag":"inbound-vless-443",
      "port": 443,
      "protocol": "vless",
      "settings": {
        "clients": [
          {
            "id": "user1",
            "flow": "xtls-rprx-vision",
            "comment": "user1"
          },
          {
            "id": "user2",
            "flow": "xtls-rprx-vision",
            "comment": "user2"
          },
          "..."
        ],
        "decryption": "none"
      },
      "streamSettings": {
        "network": "tcp",
        "security": "reality",
        "realitySettings": {
          "dest": "127.0.0.1:26172",
          "xver": 1,
          "serverNames": [
            "my.selfs.host"
          ],
          "privateKey": "privateKey",
          "publicKey": "PublicKey",
          "minClientVer": "1.8.0",
          "shortIds": [
            "",
            "01",
            "02",
            "03"
          ]
        }
      },
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls",
          "quic"
        ],
        "routeOnly": true
      }
    }
]}

客户端日志

服务端日志

Fangliding commented 2 days ago

大概reality库少写了一个close 远端关闭连接这边没关掉 其他软件都是调的这个库导致了相同的行为 补上应该就行了

Fangliding commented 2 days ago
telnet 127.0.0.1 8000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
hello
HTTP/1.1 400 Bad Request
Server: cloudflare
Date: Wed, 03 Jul 2024 11:37:08 GMT
Content-Type: text/html
Content-Length: 155
Connection: close
CF-RAY: -

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
Connection closed by foreign host.

现在可以正常断开力 顺便再读了一遍reality的代码

lxhao61 commented 1 day ago

等待合并。

RPRX commented 21 hours ago

我记得当时故意写成了可以仅关闭上/下行,但既然其它反代是同时关闭那就同时关闭吧,感谢报告问题