-
Notifications
You must be signed in to change notification settings - Fork 5k
Closed
Description
完整性要求
- 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
- 我提供了完整的配置文件和日志,而不是出于自己的判断只给出截取的部分。
- 我搜索了issues,没有发现已提出的类似问题。
版本
1.8.23
描述
作为 SOCKS4 协议的扩展,SOCKS4A 允许客户端以特殊格式在请求中使用域名作为目标地址,以便服务端解析域名。然而,即使目标是 IP 地址,某些客户端仍然会使用此格式发送请求(例如 cURL 和 Gecko)。这导致 Xray 错误地将其中的 IP 地址视为域名,并在进行路由规则匹配时指向错误的出口:
Xray-core/proxy/socks/protocol.go
Lines 72 to 78 in 4c82ef8
| 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 地址,因此能够正确处理:
Xray-core/common/protocol/address.go
Lines 213 to 218 in 4c82ef8
| if maybeIPPrefix(domain[0]) { | |
| addr := net.ParseAddress(domain) | |
| if addr.Family().IsIP() { | |
| return addr, nil | |
| } | |
| } |
重现方式
- 使用以下配置启动 Xray:
xray run -c config.json - 使用 cURL 向其发送 SOCKS4A 请求,目标为 192.168.1.1:
curl -x socks4a://127.0.0.1:1081 192.168.1.1 - cURL 返回以下结果,即连接被错误地关闭:
curl: (52) Empty reply from server
客户端配置
Details
{
"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
客户端日志
Details
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels