Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

识别 SOCKS4A 请求中可能的 IP 地址以提高稳健性 #3622

Closed
3 tasks done
ckwastra opened this issue Aug 1, 2024 · 5 comments
Closed
3 tasks done

识别 SOCKS4A 请求中可能的 IP 地址以提高稳健性 #3622

ckwastra opened this issue Aug 1, 2024 · 5 comments

Comments

@ckwastra
Copy link

ckwastra commented Aug 1, 2024

完整性要求

  • 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
  • 我提供了完整的配置文件和日志,而不是出于自己的判断只给出截取的部分。
  • 我搜索了issues,没有发现已提出的类似问题。

版本

1.8.23

描述

作为 SOCKS4 协议的扩展,SOCKS4A 允许客户端以特殊格式在请求中使用域名作为目标地址,以便服务端解析域名。然而,即使目标是 IP 地址,某些客户端仍然会使用此格式发送请求(例如 cURLGecko)。这导致 Xray 错误地将其中的 IP 地址视为域名,并在进行路由规则匹配时指向错误的出口:

if address.IP()[0] == 0x00 {
domain, err := ReadUntilNull(reader)
if err != nil {
return nil, errors.New("failed to read domain for socks 4a").Base(err)
}
address = net.DomainAddress(domain)
}

尽管这听起来更像是客户端实现的问题,主动识别请求中的地址类型也能提高 Xray 的稳健性。需要注意的是,Gecko 发送的 SOCKS5 请求同样存在上述问题,但由于 Xray 在处理 SOCKS5 请求时能够识别可能的 IP 地址,因此能够正确处理:

if maybeIPPrefix(domain[0]) {
addr := net.ParseAddress(domain)
if addr.Family().IsIP() {
return addr, nil
}
}

重现方式

  1. 使用以下配置启动 Xray:
    xray run -c config.json
    
  2. 使用 cURL 向其发送 SOCKS4A 请求,目标为 192.168.1.1:
    curl -x socks4a://127.0.0.1:1081 192.168.1.1
    
  3. cURL 返回以下结果,即连接被错误地关闭:
    curl: (52) Empty reply from server
    

客户端配置

{
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 1081,
      "protocol": "socks"
    }
  ],
  "log": {
    "loglevel": "debug",
    "dnsLog": true
  },
  "outbounds": [
    {
      "protocol": "freedom"
    },
    {
      "protocol": "blackhole",
      "tag": "block"
    }
  ],
  "routing": {
    "rules": [
      {
        "domain": [
          "full:192.168.1.1"
        ],
        "outboundTag": "block"
      }
    ]
  }
}

服务端配置

N/A

客户端日志

Xray 1.8.23 (Xray, Penetrates Everything.) Custom (go1.22.5 darwin/amd64)
A unified platform for anti-censorship.
2024/08/01 23:17:26 [Info] infra/conf/serial: Reading config: config.json
2024/08/01 23:17:26 [Debug] app/log: Logger started
2024/08/01 23:17:26 [Debug] app/router: MphDomainMatcher is enabled for 1 domain rule(s)
2024/08/01 23:17:26 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:1081
2024/08/01 23:17:26 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:1081
2024/08/01 23:17:26 [Warning] core: Xray 1.8.23 started
2024/08/01 23:17:35 [Info] [2709202480] proxy/socks: TCP Connect request to tcp:192.168.1.1:80
2024/08/01 23:17:35 [Info] [2709202480] app/dispatcher: taking detour [block] for [tcp:192.168.1.1:80]
2024/08/01 23:17:35 tcp:127.0.0.1:64492 accepted tcp:192.168.1.1:80 [block]
2024/08/01 23:17:35 [Info] [2709202480] app/proxyman/inbound: connection ends > proxy/socks: connection ends > proxy/socks: failed to transport all TCP response > io: read/write on closed pipe

服务端日志

N/A

@RPRX
Copy link
Member

RPRX commented Aug 2, 2024

感谢报告问题,打算把 Socks4(a) 删掉:#1967

@Fangliding
Copy link
Member

顺便提一句Chrome发送的socks5请求也有这种问题

感谢报告问题,打算把 Socks4(a) 删掉:#1967

Windows目前还只支持socks4 还是留着吧 反正也这玩意没依赖

@RPRX
Copy link
Member

RPRX commented Aug 2, 2024

@Fangliding 那还是不删了,你修一下 Socks 吧

@RPRX
Copy link
Member

RPRX commented Aug 2, 2024

@Fangliding b11fcf0#commitcomment-144976076 重新写一下开个 PR 吧

@Fangliding
Copy link
Member

Fangliding commented Aug 3, 2024

@Fangliding b11fcf0#commitcomment-144976076 重新写一下开个 PR 吧

就一行要不直接amend吧
好吧好像被reset掉了

Fangliding added a commit to Fangliding/Xray-core that referenced this issue Aug 3, 2024
leninalive pushed a commit to amnezia-vpn/amnezia-xray-core that referenced this issue Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants