mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-24 12:11:52 +08:00
fix(credential): 修复凭据测试结果不一致的问题
问题原因: 1. 未知错误类型不重试,导致服务端限流时跳过正确密码 2. SSH 错误分类不够准确,某些临时错误未被识别 修复内容: 1. 未知错误改为可重试(可能是临时问题) 2. 增加 SSH 特有的网络错误识别(handshake failed, disconnect 等)
This commit is contained in:
@@ -255,10 +255,10 @@ func testCredentialWithRetry(
|
|||||||
// 根据错误类型决定是否重试
|
// 根据错误类型决定是否重试
|
||||||
switch result.ErrorType {
|
switch result.ErrorType {
|
||||||
case ErrorTypeAuth:
|
case ErrorTypeAuth:
|
||||||
// 认证错误,不重试
|
// 认证错误(密码错误),不重试
|
||||||
return nil
|
return nil
|
||||||
case ErrorTypeNetwork:
|
case ErrorTypeNetwork, ErrorTypeUnknown:
|
||||||
// 网络错误,可以重试
|
// 网络错误或未知错误,可以重试(可能是服务端限流等临时问题)
|
||||||
if attempt < testConfig.MaxRetries-1 {
|
if attempt < testConfig.MaxRetries-1 {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@@ -267,9 +267,6 @@ func testCredentialWithRetry(
|
|||||||
// 继续重试
|
// 继续重试
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
// 未知错误,不重试
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+11
-1
@@ -160,12 +160,22 @@ func classifySSHErrorType(err error) ErrorType {
|
|||||||
return ErrorTypeUnknown
|
return ErrorTypeUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SSH 特有的认证错误(密码错误)
|
||||||
sshAuthErrors := append(CommonAuthErrors,
|
sshAuthErrors := append(CommonAuthErrors,
|
||||||
"unable to authenticate",
|
"unable to authenticate",
|
||||||
"no supported methods remain",
|
"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私钥扫描
|
// scanWithKey 使用SSH私钥扫描
|
||||||
|
|||||||
Reference in New Issue
Block a user