sing-box icon indicating copy to clipboard operation
sing-box copied to clipboard

socks inbound: UDP ASSOCIATE succeeds but relay never forwards datagrams (1.14.0/1.14.2)

Open bingfoon opened this issue 2 months ago • 0 comments

Description

On sing-box 1.14.x acting as a server, a plain socks inbound accepts SOCKS5 UDP ASSOCIATE (reply 0x00, allocates a relay port) but never relays any UDP datagram: datagrams sent to the allocated relay endpoint get no response, even on loopback.

Reproduced on 1.14.0 and 1.14.2, with both a production-shaped config (sniff + hijack-dns route rules) and the minimal config below — so route rules are not a factor.

The same instance's vless inbound (XUDP) relays UDP fine (verified with STUN and NTP), so outbound UDP itself is healthy.

Configuration

Minimal reproduction (run with sing-box run -c on any Linux box):

{
  "log": { "level": "info", "timestamp": true },
  "inbounds": [
    {
      "type": "socks",
      "tag": "socks-in",
      "listen": "127.0.0.1",
      "listen_port": 1080,
      "users": [ { "username": "user", "password": "pass" } ]
    }
  ],
  "outbounds": [ { "type": "direct", "tag": "direct" } ]
}

Reproduction

Same host, plain Python (stdlib only):

import socket, struct, os, time

tcp = socket.create_connection(("127.0.0.1", 1080), timeout=8)
tcp.sendall(b"\x05\x02\x00\x02")                       # methods: no-auth, userpass
assert tcp.recv(2)[1] == 2
tcp.sendall(b"\x01\x04user\x04pass")                   # user/pass auth
assert tcp.recv(2)[1] == 0

tcp.sendall(b"\x05\x03\x00\x01" + socket.inet_aton("0.0.0.0") + struct.pack("!H", 0))
time.sleep(0.3)
rep = tcp.recv(64)                                     # UDP ASSOCIATE
assert rep[1] == 0
relay_ip, relay_port = socket.inet_ntoa(rep[4:8]), struct.unpack("!H", rep[8:10])[0]
print("relay:", relay_ip, relay_port)

u = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); u.settimeout(5)
dst = socket.gethostbyname("stun.cloudflare.com")
pkt = (b"\x00\x00\x00\x01" + socket.inet_aton(dst) + struct.pack("!H", 3478)
       + struct.pack("!HHI", 1, 0, 0) + os.urandom(12))  # SOCKS UDP header + STUN binding request
u.sendto(pkt, (relay_ip, relay_port))
try:
    d, _ = u.recvfrom(2048)
    print("relay reply:", len(d), "bytes")
except socket.timeout:
    print("relay reply: TIMEOUT")

Output:

relay: 127.0.0.1 34339
relay reply: TIMEOUT

Expected: the relay forwards the datagram to stun.cloudflare.com:3478 and returns the STUN binding response.

Evidence it is not the network or firewall

  • Test runs on loopback (127.0.0.1), same host as sing-box
  • Host firewall (ufw) was temporarily configured to allow the allocated relay port — still no response
  • Two independent clients behave identically: the script above, and mihomo (Clash.Meta) with udp: true against a remote instance
  • A vless inbound on the same sing-box instance relays UDP normally (XUDP), including to the same STUN server

Environment

  • sing-box version:
    sing-box version 1.14.2
    Environment: go1.26.8 linux/amd64
    Revision: af6e64c3b69e6132ebaee0e1a3d24e93903f6709
    CGO: enabled
    
    Also reproduced on 1.14.0. Installed from the official apt repository, stock systemd unit.
  • OS: Ubuntu 24.04.1 LTS, amd64
  • Nothing appears in the log at info level during the attempt

Expected behavior

Per RFC 1928, after a successful UDP ASSOCIATE the relay should forward properly framed datagrams between the client and the target. The datagram header used above (RSV=0, FRAG=0, ATYP=0x01, IPv4, port) is the standard framing, and the same framing works against other SOCKS5 servers from the same script.

bingfoon avatar Sep 27 '26 04:09 bingfoon