{"record":{"id":"9bccda7d8bc1dd2d","repo":"shadow1ng/fscan","slug":"netbios-smb-negotiate-send-failed-w","errorCode":null,"errorMessage":"netbios_smb_negotiate_send_failed: %w","messagePattern":"netbios_smb_negotiate_send_failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"plugins/services/netbios.go","lineNumber":217,"sourceCode":"\n\t_ = conn.SetDeadline(time.Now().Add(session.Config.ModuleTimeout()))\n\n\t// 发送SMB协商数据包\n\tsmbNegotiate1 := []byte{\n\t\t0x00, 0x00, 0x00, 0x85, 0xFF, 0x53, 0x4D, 0x42, 0x72, 0x00, 0x00, 0x00, 0x00, 0x18, 0x53, 0xC8,\n\t\t0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFE,\n\t\t0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x00, 0x02, 0x50, 0x43, 0x20, 0x4E, 0x45, 0x54, 0x57, 0x4F,\n\t\t0x52, 0x4B, 0x20, 0x50, 0x52, 0x4F, 0x47, 0x52, 0x41, 0x4D, 0x20, 0x31, 0x2E, 0x30, 0x00, 0x02,\n\t\t0x4C, 0x41, 0x4E, 0x4D, 0x41, 0x4E, 0x31, 0x2E, 0x30, 0x00, 0x02, 0x57, 0x69, 0x6E, 0x64, 0x6F,\n\t\t0x77, 0x73, 0x20, 0x66, 0x6F, 0x72, 0x20, 0x57, 0x6F, 0x72, 0x6B, 0x67, 0x72, 0x6F, 0x75, 0x70,\n\t\t0x73, 0x20, 0x33, 0x2E, 0x31, 0x61, 0x00, 0x02, 0x4C, 0x4D, 0x31, 0x2E, 0x32, 0x58, 0x30, 0x30,\n\t\t0x32, 0x00, 0x02, 0x4C, 0x41, 0x4E, 0x4D, 0x41, 0x4E, 0x32, 0x2E, 0x31, 0x00, 0x02, 0x4E, 0x54,\n\t\t0x20, 0x4C, 0x4D, 0x20, 0x30, 0x2E, 0x31, 0x32, 0x00,\n\t}\n\n\t_, err = conn.Write(smbNegotiate1)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %w\", i18n.GetText(\"netbios_smb_negotiate_send_failed\"), err)\n\t}\n\n\tresponse1 := make([]byte, 1024)\n\t_, err = conn.Read(response1)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %w\", i18n.GetText(\"netbios_smb_negotiate_read_failed\"), err)\n\t}\n\n\t// 发送Session Setup请求\n\tsmbSessionSetup := []byte{\n\t\t0x00, 0x00, 0x01, 0x0A, 0xFF, 0x53, 0x4D, 0x42, 0x73, 0x00, 0x00, 0x00, 0x00, 0x18, 0x07, 0xC8,\n\t\t0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFE,\n\t\t0x00, 0x00, 0x40, 0x00, 0x0C, 0xFF, 0x00, 0x0A, 0x01, 0x04, 0x41, 0x32, 0x00, 0x00, 0x00, 0x00,\n\t\t0x00, 0x00, 0x00, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD4, 0x00, 0x00, 0xA0, 0xCF, 0x00, 0x60,\n\t\t0x48, 0x06, 0x06, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x02, 0xA0, 0x3E, 0x30, 0x3C, 0xA0, 0x0E, 0x30,\n\t\t0x0C, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x02, 0x0A, 0xA2, 0x2A, 0x04,\n\t\t0x28, 0x4E, 0x54, 0x4C, 0x4D, 0x53, 0x53, 0x50, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x82, 0x08,\n\t\t0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/services/netbios.go#L199-L235","documentation":"This error occurs in queryNetBIOSSession when writing the SMB negotiate packet (smbNegotiate1) to a NetBIOS session service TCP connection on port 139 fails. The library wraps the underlying net.Conn.Write error with the i18n message 'netbios_smb_negotiate_send_failed'. It means the TCP connection was established (DialTCP succeeded) but broke before the first SMB packet could be delivered.","triggerScenarios":"Calling Scan -> queryNetBIOSSession against a host where TCP 139 accepts the connection but the write fails: connection reset by peer immediately after accept, connection closed by the remote host mid-write, or the deadline set via SetDeadline(ModuleTimeout) expiring during the write.","commonSituations":"Windows hosts with SMB disabled but NetBIOS port-filtering middleware that accepts and drops connections; firewalls/IPS that RST SMB traffic; host crashed or rebooted between dial and write; extremely short ModuleTimeout values causing i/o timeout; scanning hosts that only expose UDP 137 but have a half-open TCP 139 listener.","solutions":["Verify the target host actually speaks SMB on TCP 139 (nmap -p139 --script smb-os-discovery); if it doesn't, exclude it from scanning.","Increase config.ModuleTimeout() so the SetDeadline does not expire during the write.","Check for firewalls/IPS between scanner and host that reset SMB packets; whitelist the scanner IP.","Inspect the wrapped %w error to distinguish i/o timeout vs connection reset and handle each case specifically."],"exampleFix":"// before\nconn, err := session.DialTCP(ctx, \"tcp\", target, session.Config.ModuleTimeout())\n_, err = conn.Write(smbNegotiate1)\n\n// after\nconn, err := session.DialTCP(ctx, \"tcp\", target, 2*session.Config.ModuleTimeout())\nif err != nil { return nil, err }\nif n, werr := conn.Write(smbNegotiate1); werr != nil {\n    var nerr net.Error\n    if errors.As(werr, &nerr) && nerr.Timeout() {\n        return nil, fmt.Errorf(\"smb negotiate timed out after %v: %w\", session.Config.ModuleTimeout(), werr)\n    }\n    return nil, fmt.Errorf(\"%s: %w\", i18n.GetText(\"netbios_smb_negotiate_send_failed\"), werr)\n}","handlingStrategy":"try-catch","validationCode":"// pre-flight: check TCP 139 reachability and a sane timeout before scanning\nif config.ModuleTimeout() < 2*time.Second {\n    return fmt.Errorf(\"module timeout %v too short for SMB negotiate\", config.ModuleTimeout())\n}\nconn, err := net.DialTimeout(\"tcp\", host+\":139\", config.ModuleTimeout())\nif err != nil {\n    return fmt.Errorf(\"host %s not reachable on TCP 139: %w\", host, err)\n}\n_ = conn.Close()","typeGuard":"func isNetError(err error) (net.Error, bool) {\n    var nerr net.Error\n    if errors.As(err, &nerr) {\n        return nerr, true\n    }\n    return nil, false\n}","tryCatchPattern":"info, err := plugin.Scan(ctx, host, session)\nif err != nil {\n    var nerr net.Error\n    if errors.As(err, &nerr) && nerr.Timeout() {\n        log.Printf(\"skip %s: negotiate send timeout\", host)\n        return nil // treat as no NetBIOS service\n    }\n    if errors.Is(err, syscall.ECONNRESET) || errors.Is(err, syscall.EPIPE) {\n        log.Printf(\"skip %s: connection reset during negotiate\", host)\n        return nil\n    }\n    return err\n}","preventionTips":["Set ModuleTimeout generously (>=5s) for cross-WAN scans.","Pre-check TCP 139 reachability before running the full session flow.","Exclude known non-SMB hosts (printers, IoT) from NetBIOS scanning.","Always inspect the wrapped error with errors.Is/errors.As instead of treating all failures alike."],"tags":["network","netbios","smb","tcp","scan"],"backgroundTag":"broken-pipe","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"}