From b86f39d2ccdebbccd99cbd489e49f2f95656c7bb Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Tue, 20 Jan 2026 13:29:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(credential):=20=E4=BF=AE=E5=A4=8D=E5=87=AD?= =?UTF-8?q?=E6=8D=AE=E6=B5=8B=E8=AF=95=E7=BB=93=E6=9E=9C=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题原因: 1. 未知错误类型不重试,导致服务端限流时跳过正确密码 2. SSH 错误分类不够准确,某些临时错误未被识别 修复内容: 1. 未知错误改为可重试(可能是临时问题) 2. 增加 SSH 特有的网络错误识别(handshake failed, disconnect 等) --- plugins/services/credential_tester.go | 9 +++------ plugins/services/ssh.go | 12 +++++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/plugins/services/credential_tester.go b/plugins/services/credential_tester.go index 9a1f210..b557420 100644 --- a/plugins/services/credential_tester.go +++ b/plugins/services/credential_tester.go @@ -255,10 +255,10 @@ func testCredentialWithRetry( // 根据错误类型决定是否重试 switch result.ErrorType { case ErrorTypeAuth: - // 认证错误,不重试 + // 认证错误(密码错误),不重试 return nil - case ErrorTypeNetwork: - // 网络错误,可以重试 + case ErrorTypeNetwork, ErrorTypeUnknown: + // 网络错误或未知错误,可以重试(可能是服务端限流等临时问题) if attempt < testConfig.MaxRetries-1 { select { case <-ctx.Done(): @@ -267,9 +267,6 @@ func testCredentialWithRetry( // 继续重试 } } - default: - // 未知错误,不重试 - return nil } } return nil diff --git a/plugins/services/ssh.go b/plugins/services/ssh.go index d6a54c9..2a843b3 100644 --- a/plugins/services/ssh.go +++ b/plugins/services/ssh.go @@ -160,12 +160,22 @@ func classifySSHErrorType(err error) ErrorType { return ErrorTypeUnknown } + // SSH 特有的认证错误(密码错误) sshAuthErrors := append(CommonAuthErrors, "unable to authenticate", "no supported methods remain", ) - return ClassifyError(err, sshAuthErrors, CommonNetworkErrors) + // SSH 特有的网络/临时错误(需要重试) + sshNetworkErrors := append(CommonNetworkErrors, + "handshake failed", // 握手失败,可能是服务端限流 + "ssh: disconnect", // SSH 主动断开 + "connection closed", // 连接被关闭 + "max startups", // SSH MaxStartups 限制 + "too many authentication", // 认证次数过多 + ) + + return ClassifyError(err, sshAuthErrors, sshNetworkErrors) } // scanWithKey 使用SSH私钥扫描