{"record":{"id":"26d7b7c7e994286f","repo":"shadow1ng/fscan","slug":"socks5-invalid-request","errorCode":null,"errorMessage":"socks5_invalid_request","messagePattern":"socks5_invalid_request","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"plugins/local/socks5proxy.go","lineNumber":251,"sourceCode":"\t\t}\n\t\ttargetHost = string(addr[:domainLen])\n\t\ttargetPort = int(addr[domainLen])<<8 + int(addr[domainLen+1])\n\tcase 0x04: // IPv6\n\t\taddr := make([]byte, 18)\n\t\tif _, err := io.ReadFull(clientConn, addr); err != nil {\n\t\t\treturn nil, 0, fmt.Errorf(\"%s\", i18n.GetText(\"ipv6_address_invalid\"))\n\t\t}\n\t\t// IPv6地址解析（简化实现）\n\t\ttargetHost = net.IP(addr[:16]).String()\n\t\ttargetPort = int(addr[16])<<8 + int(addr[17])\n\tdefault:\n\t\t// 发送不支持的地址类型响应\n\t\tresponse := []byte{0x05, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\n\t\t_, _ = clientConn.Write(response)\n\t\treturn nil, 0, fmt.Errorf(i18n.GetText(\"socks5_unsupported_address_type\")+\": %d\", addrType)\n\t}\n\tif targetPort == 0 {\n\t\treturn nil, 0, fmt.Errorf(\"%s\", i18n.GetText(\"socks5_invalid_request\"))\n\t}\n\n\t// 连接目标服务器\n\ttargetAddr := net.JoinHostPort(targetHost, strconv.Itoa(int(targetPort)))\n\ttargetConn, err := net.DialTimeout(\"tcp\", targetAddr, 10*time.Second)\n\tif err != nil {\n\t\t// 发送连接失败响应\n\t\tresponse := []byte{0x05, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\n\t\t_, _ = clientConn.Write(response)\n\t\treturn nil, 0, fmt.Errorf(\"%s: %w\", i18n.GetText(\"socks5_target_connect_failed\"), err)\n\t}\n\n\t// 获取本地监听端口（从targetConn获取）\n\tlocalAddr, ok := targetConn.LocalAddr().(*net.TCPAddr)\n\tif !ok {\n\t\treturn nil, 0, fmt.Errorf(\"%s\", i18n.GetText(\"local_address_unavailable\"))\n\t}\n\tlocalPort := localAddr.Port","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/local/socks5proxy.go#L233-L269","documentation":"SOCKS5 request handler rejects a client request whose parsed request is invalid: specifically the client requested a connection to target port 0, which is not a valid destination port. The handler responds with SOCKS5 reply code 0x08 (address type not supported / invalid request context) and returns a localized error string.","triggerScenarios":"A SOCKS5 client sends a CONNECT/BIND request after address parsing succeeds but with targetPort == 0 (e.g. malformed or malicious client, a client bug encoding port bytes as zero).","commonSituations":"Port-scanning or fuzzing tools against the proxy; clients with byte-order bugs in constructing the SOCKS5 request (port sent in wrong endianness yielding 0); handcrafted SOCKS5 requests.","solutions":["Fix or reconfigure the SOCKS5 client so the destination port is correctly encoded (big-endian) and non-zero","Check the port bytes in the client's request packet; bytes 8-9 of the request are the port and must not both be 0x00","Log the client address and reject the connection; port 0 is never a valid target"],"exampleFix":"// before (client side, little-endian port)\nreq := []byte{0x05, 0x01, 0x00, 0x01, 127, 0, 0, 1, 0x50, 0x00}\n// after (big-endian port 8080)\nreq := []byte{0x05, 0x01, 0x00, 0x01, 127, 0, 0, 1, 0x1F, 0x90}","handlingStrategy":"validation","validationCode":"// client side, before sending the request\nif dstPort <= 0 || dstPort > 65535 {\n    return fmt.Errorf(\"invalid destination port %d\", dstPort)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always encode the SOCKS5 port as big-endian (network byte order)","Never send port 0 as a destination","Validate host/port on the client before building the request"],"tags":["socks5","proxy","protocol","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}