{"record":{"id":"47e8620482e73376","repo":"shadow1ng/fscan","slug":"socks5-target-connect-failed-w","errorCode":null,"errorMessage":"socks5_target_connect_failed: %w","messagePattern":"socks5_target_connect_failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/local/socks5proxy.go","lineNumber":261,"sourceCode":"\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\n\n\t// 发送成功响应\n\tresponse := make([]byte, 10)\n\tresponse[0] = 0x05 // SOCKS版本\n\tresponse[1] = 0x00 // 成功\n\tresponse[2] = 0x00 // 保留\n\tresponse[3] = 0x01 // IPv4地址类型\n\t// 绑定地址和端口（使用127.0.0.1:localPort）\n\tcopy(response[4:8], []byte{127, 0, 0, 1})\n\tresponse[8] = byte(localPort >> 8)","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/local/socks5proxy.go#L243-L279","documentation":"The proxy failed to open the TCP connection to the requested target host:port; the DialTimeout returned an error. The proxy sends SOCKS5 reply 0x05 (connection refused) to the client and wraps the underlying net error into socks5_target_connect_failed.","triggerScenarios":"net.DialTimeout(\"tcp\", targetAddr, 10s) fails: target unreachable, refused, DNS failure, or the 10-second timeout expires.","commonSituations":"User proxies to a host that is down or firewalled; DNS cannot resolve the target hostname; slow network exceeds the 10s dial timeout; wrong target port entered in client config.","solutions":["Verify the target host/port is reachable and the service is listening (curl/telnet to targetAddr directly)","Check DNS resolution of the target hostname from the proxy host","Increase or accept the 10s DialTimeout for slow networks; inspect the wrapped %w error for refused vs timeout vs no-route","If all targets fail, check the proxy host's outbound firewall and egress routing"],"exampleFix":"// inspect the wrapped cause in the caller\nif _, _, err := handleSocks5Request(...); err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) && netErr.Timeout() {\n        log.Println(\"target dial timed out; consider raising timeout\")\n    }\n}","handlingStrategy":"retry","validationCode":"// pre-check reachability when possible\nconn, err := net.DialTimeout(\"tcp\", \"target.example:443\", 3*time.Second)\nif err != nil { log.Printf(\"target unreachable: %v\", err) } else { conn.Close() }","typeGuard":null,"tryCatchPattern":"// caller\nif _, _, err := handleSocks5Request(...); err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) && netErr.Timeout() {\n        // retry with backoff\n    } else {\n        var dnsErr *net.DNSError\n        if errors.As(err, &dnsErr) { log.Printf(\"DNS failure for %s\", dnsErr.Name) }\n    }\n}","preventionTips":["Check target reachability before proxying","Raise the dial timeout for slow networks","Monitor egress firewall/DNS health on the proxy host","Surface the wrapped net error for diagnostics"],"tags":["socks5","network","tcp","dial","timeout"],"backgroundTag":"connection-refused","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"}