{"record":{"id":"3123f04b27df65c3","repo":"shadow1ng/fscan","slug":"service-connection-failed","errorCode":null,"errorMessage":"service_connection_failed","messagePattern":"service_connection_failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/services/smb_protocol.go","lineNumber":210,"sourceCode":"\t\t\"\\x00\\x00\" +\n\t\t\"\\x03\\x00\" +\n\t\t\"\\x0e\\x00\" +\n\t\t\"\\x00\\x00\\x00\\x00\" +\n\t\t\"\\x01\\x00\" +\n\t\t\"\\x00\\x00\" +\n\t\t\"\\x01\\x00\\x00\\x00\" +\n\t\t\"\\x01\\x00\" +\n\t\t\"\\x00\\x00\" +\n\t\t\"\\x00\\x00\\x00\\x00\"\n)\n\n// probeTarget 探测目标SMB信息（协议版本、系统信息）\nfunc probeTarget(ctx context.Context, host string, port int, timeout time.Duration, session *common.ScanSession) (*SMBTarget, error) {\n\ttarget := net.JoinHostPort(host, strconv.Itoa(port))\n\n\tconn, err := session.DialTCP(ctx, \"tcp\", target, timeout)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(i18n.Tr(\"service_connection_failed\", \"%w\"), err)\n\t}\n\tdefer func() { _ = conn.Close() }()\n\n\t_ = conn.SetDeadline(time.Now().Add(timeout))\n\n\t// 首先尝试SMBv1协商\n\t_, err = conn.Write(smbv1NegotiatePacket)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %w\", i18n.GetText(\"smbv1_negotiate_send_failed\"), err)\n\t}\n\n\t// 读取SMBv1协商响应\n\tr1, err := readSMBMessage(conn)\n\tif err != nil {\n\t\tsession.LogDebug(i18n.Tr(\"smbv1_negotiate_read_failed\", err))\n\t}\n\n\t// 检查是否支持SMBv1","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/services/smb_protocol.go#L192-L228","documentation":"probeTarget's first step is to dial the target with session.DialTCP. If the dial fails, it returns service_connection_failed with the wrapped net error (note the i18n.Tr format places %w inside a translated template). This is the lowest-level SMB failure: the TCP connection to host:port could not be established at all, before any SMB negotiation.","triggerScenarios":"session.DialTCP(ctx, \"tcp\", net.JoinHostPort(host, port), timeout) returns an error — connection refused (nothing listening), no route/filtered, or context/deadline timeout — triggering the return at smb_protocol.go:210.","commonSituations":"SMB ports closed or firewalled (very common: 445 blocked on WAN); host offline or DNS resolving to a dead IP; scanner lacking network route (VPN not connected); timeout too small for the environment.","solutions":["Test basic reachability: nc -vz <host> 445 from the scanner host.","Check firewall/security-group rules to allow outbound TCP to 445/139.","Verify DNS resolution of the host and correct IP in the target list.","Increase the timeout in config if the error is a deadline/timeout variant; retry transient network failures."],"exampleFix":"// before\nscanSMB(\"10.0.0.5\", timeout: 2s) // service_connection_failed: dial tcp ... i/o timeout\n// after\nscanSMB(\"10.0.0.5\", timeout: 10s) // with firewall rule allowing tcp/445","handlingStrategy":"retry","validationCode":"addr := net.JoinHostPort(host, \"445\")\nif _, err := net.DialTimeout(\"tcp\", addr, 5*time.Second); err != nil {\n    return fmt.Errorf(\"target %s unreachable before SMB probe: %v\", addr, err)\n}","typeGuard":null,"tryCatchPattern":"res, err := plugin.Scan(ctx, target)\nif err != nil && strings.Contains(err.Error(), \"service_connection_failed\") {\n    var ne net.Error\n    if errors.As(err, &ne) && ne.Timeout() {\n        // retry with larger timeout\n    } else {\n        // connection refused/filtered: mark host unreachable\n    }\n}","preventionTips":["Run a cheap TCP dial health-check before dispatching SMB scans.","Open firewall paths for TCP 445/139 from the scanner subnet.","Verify DNS resolution of targets before scanning.","Retry once on timeout-class dial errors before giving up."],"tags":["smb","tcp","network","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-14T05:17:10.506Z"}