socks握手时的bufio会吞掉客户端流水线发送的首段payload,进而导致UoT v2客户端的每条流都会失败
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- go
- Área
- networking
Línea de trabajo
Start with protocol/socks/handshake.go, especially the reader and handler handoff locations linked in the issue, and trace how buffered bytes are handled after the SOCKS5 CONNECT request. Reproduce with the supplied Python client, sending the greeting, CONNECT request, UoT header, and first frame together; done when the pipelined case succeeds as well as the staged case without losing payload bytes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
问题
SOCKS5客户端可以把首个payload和CONNECT请求放在同一个TCP段里发送,以此节省一个RTT。但是sing就会把这部分字节丢掉。
对UoT v2客户端来说,就表现为每一条UoT流都在请求头处失败:客户端把发往 sp.v2.udp-over-tcp.arpa 的 CONNECT、UoT请求头和第一个数据帧写在同一个缓冲区里一次发出,服务端日志为
INFO inbound/socks[in]: inbound connection to sp.v2.udp-over-tcp.arpa:0
ERROR inbound/socks[in]: process connection from 127.0.0.1:58042: UoT read request: unknown address family: 152
复现
注意要一次性发出全部内容
import socket, struct, time
MAGIC = b'sp.v2.udp-over-tcp.arpa'
greeting = bytes([5, 1, 0])
connect = bytes([5, 1, 0, 3, len(MAGIC)]) + MAGIC + b'\x00\x00'
uot_request = bytes([1, 1, 192, 168, 1, 1, 0x75, 0x3A]) # isConnect, ATYP=IPv4, addr, port
frame = struct.pack('>H', 8) + b'WFE1\x00\x00\x00\x01'
s = socket.create_connection(('127.0.0.1', 1080)) # sing-box v1.14.2 SOCKS5 Listen
s.sendall(greeting + connect + uot_request + frame)
time.sleep(1)
s.close()
socks inbound + direct outbound:
| 客户端 | sing侧结果 |
|---|---|
发 greeting、读回复;发 CONNECT、读回复;之后再发UoT请求 |
inbound UoT connect connection to 192.168.1.1:30001;OK没有问题 |
| 一次写完全部内容 | UoT read request: EOF;之后还有数据帧的话就是unknown address family: N;失败了 |
原因
handshake.go里握手通过reader *std_bufio.Reader解析,bufio每次 fill都把整块缓冲读满,但CONNECT交给handler的是原始连接:
https://github.com/SagerNet/sing/blob/6f21f2425a959912c37d2ef43d61e2a663315dea/protocol/socks/handshake.go#L158
https://github.com/SagerNet/sing/blob/6f21f2425a959912c37d2ef43d61e2a663315dea/protocol/socks/handshake.go#L228
把流的中间当成了开头
- Lenguaje dominante
- Go
- Estrellas
- 131
- Forks
- 116
- Merge medio
- 1 h 42 min
- PR fusionados (30 d)
- 1
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de SagerNet/sing
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
-
addr 相关的几个问题Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 30/100
Todos los issues de SagerNet/sing
Issues similares
-
[Bug]: Deleting an MCP proxy leaves its API keys in the gateway's memory and in the policy engineAbiertoAspect/API Aspect/Other Severity/Minor Type/Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
wso2/api-platform#3852 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Rafaeldelinares/gentle-mesh#125 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Gentleman-Programming/gentle-ai#5643 ·
Los mantenedores suelen responder en 1 día
-
security
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
FootprintAI/Containarium#2869 ·
Los mantenedores suelen responder en 1 día
-
kind/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
kubevirt/kubevirt#19559 · 1 reacción ·
Los mantenedores suelen responder en 1 día